免费注册 查看新帖 |

Chinaunix

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

请教两块网卡的RAW_SOCKET问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-25 18:03 |只看该作者 |倒序浏览
有两块网卡(ip:eth0:192.168.0.8;eth1:192.168.0.9)
建立socket:int iSockFd = socket(AF_PACKET,SOCK_PACKET,htons(ETH_P_ALL));
怎么让iSockFd只收到192.168.0.8上的包。
我将socket 绑定到eth0上,部分源码如下:
struct sockaddr_ll my_addr;
struct ifreq ifr;
strncpy(ifr.ifr_name,"eth0",4)
ioctl(iSockFd,SIOCGIFINDEX,&ifr);
my_addr.sll_family=AF_PACKET;
my_addr.sll_protocol=htons(ETH_P_ALL);
my_addr.sll_ifindex=ifr.ifr_ifindex
我用bind(iSockFd,(struct sockaddr*)&my_addr,sizeof(struct sockaddr_ll));
但是到eth1:192.168.0.9的包还能收到,求解决方法!

论坛徽章:
0
2 [报告]
发表于 2005-07-25 19:29 |只看该作者

请教两块网卡的RAW_SOCKET问题!

the bind system call do not show any clue that the iSockFd can and will have any relationship will address 192.168.0.9

论坛徽章:
0
3 [报告]
发表于 2005-07-25 20:51 |只看该作者

请教两块网卡的RAW_SOCKET问题!

sorry ,I saw man packet and found I was wrong
  man pakcet said that
        By  default  all  packets  of the specified protocol type

      are passed to a packet socket. To only get packets  from  a         spe‐cific interface use bind(2) specifying an address in a struct
       sockaddr_ll to bind the packet socket to an  interface.    Only  the  sll_protocol and the sll_ifindex address fields are used
       for purposes of binding.


so your code is OK.is there are other sections you mot pay attention to ?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP