免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1814 | 回复: 0
打印 上一主题 下一主题

[函数] 请教:sk_buff和ethhdr结构体中怎么获得源mac地址?并将类型转换? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-12-29 19:14 |只看该作者 |倒序浏览
请教各位大神,写的这段代码功能没有实现,求指教!
static size_t _format_mac_addr(char *buf, int buflen,const unsigned char *addr, int len)//mac地址转换函数,转为 aa:aa:aa:aa:aa:aa 这类
{
int i;
char *cp = buf;
for (i = 0; i < len; i++) {
cp += scnprintf(cp, buflen - (cp - buf), "%02x", addr[i]);
if (i == len - 1)
break;
cp += scnprintf(cp, buflen - (cp - buf), ":");
}
return cp - buf;
}

unsigned int hook_func(unsigned int hooknum,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))//获取源mac地址并和本机mac地址对比
{
char buffer[20];
u8 haddr[20];
struct ethhdr *eth;
eth=(struct ethhdr *)skb_mac_header(skb);
memcpy(haddr,eth->h_source,6);
_format_mac_addr(buffer, 18, haddr, 6);
if(strcmp(buffer,"b8:88:e3:72:31:44")==0)   
    return NF_ACCEPT;
else
    return NF_DROP;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP