linux下多网卡机器中,如何通过指定网卡来接受数据?

酷咪哥
全栈领域新星创作者
2017-06-21 08:29:29
多播(组播)指定网口发送数据:
bind输出网口或者使用IP_MULTICAST_IF均可以实现
多播(组播)指定网口接收数据:
使用IP_ADD_MEMBERSHIP加入组播组时,将 imr_interface 地址指定为希望接收网卡的地址,按照这个理解,应该可以按需要接收数据才对啊?但实际确无法接收到,必须配置route表,有知道原理的么?
...全文
869 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jklinux 2017-06-22
  • 打赏
  • 举报
回复
引用 5 楼 weixin_35804181 的回复:
[quote=引用 4 楼 jklinux 的回复:] [quote=引用 3 楼 weixin_35804181 的回复:] [quote=引用 1 楼 jklinux 的回复:] IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据[/quote] 最后一招了, 试下设置socket选项(man 7 socket): SO_BINDTODEVICE Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maxi‐ mum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket.[/quote] 这个试过了不行,现在是IGMP确定是从ETH1发出去的,输入网口也接收了,但在进行路由(内核函数ip_rcv_finish)时被丢弃了[/quote] 在bind绑定端口号时指定网卡的ip地址也没用吗?
酷咪哥 2017-06-22
  • 打赏
  • 举报
回复
引用 4 楼 jklinux 的回复:
[quote=引用 3 楼 weixin_35804181 的回复:] [quote=引用 1 楼 jklinux 的回复:] IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据[/quote] 最后一招了, 试下设置socket选项(man 7 socket): SO_BINDTODEVICE Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maxi‐ mum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket.[/quote] 这个试过了不行,现在是IGMP确定是从ETH1发出去的,输入网口也接收了,但在进行路由(内核函数ip_rcv_finish)时被丢弃了
jklinux 2017-06-22
  • 打赏
  • 举报
回复
引用 3 楼 weixin_35804181 的回复:
[quote=引用 1 楼 jklinux 的回复:] IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据[/quote] 最后一招了, 试下设置socket选项(man 7 socket): SO_BINDTODEVICE Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maxi‐ mum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket.
酷咪哥 2017-06-22
  • 打赏
  • 举报
回复
引用 1 楼 jklinux 的回复:
IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据
酷咪哥 2017-06-22
  • 打赏
  • 举报
回复
引用 1 楼 jklinux 的回复:
IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
感谢您的回答,这个信息在哪儿查阅到的?另外网卡索引应该如何获取呢?SIOCGIFINDEX?
jklinux 2017-06-22
  • 打赏
  • 举报
回复
IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
酷咪哥 2017-06-22
  • 打赏
  • 举报
回复
引用 8 楼 jklinux 的回复:
[quote=引用 7 楼 weixin_35804181 的回复:] [quote=引用 6 楼 jklinux 的回复:] [quote=引用 5 楼 weixin_35804181 的回复:] [quote=引用 4 楼 jklinux 的回复:] [quote=引用 3 楼 weixin_35804181 的回复:] [quote=引用 1 楼 jklinux 的回复:] IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据[/quote] 最后一招了, 试下设置socket选项(man 7 socket): SO_BINDTODEVICE Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maxi‐ mum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket.[/quote] 这个试过了不行,现在是IGMP确定是从ETH1发出去的,输入网口也接收了,但在进行路由(内核函数ip_rcv_finish)时被丢弃了[/quote] 在bind绑定端口号时指定网卡的ip地址也没用吗?[/quote] 没用,eth1确定已经加入组播,并且IGMP包也是从eth1发出去的,但是就是没有办法接收 eth0 1 224.0.0.251 eth0 1 224.0.0.1 eth1 1 224.2.2.2 eth1 1 224.0.0.251 eth1 1 224.0.0.1 eth2 1 224.0.0.251 eth2 1 224.0.0.1 丢包监控: 3995 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 2 drops at __netif_receive_skb_core+2c9 (0xffffffff81730369) 4063 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 200 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 1 drops at sk_stream_kill_queues+57 (0xffffffff81723c87) 1 drops at tcp_v4_rcv+80 (0xffffffff817943b0) [/quote] 确定也与防火墙无关吗? 我也来写代码测试下好了[/quote] 有可能与路由有关系,我正在看内核源码,分析!
jklinux 2017-06-22
  • 打赏
  • 举报
回复
引用 7 楼 weixin_35804181 的回复:
[quote=引用 6 楼 jklinux 的回复:] [quote=引用 5 楼 weixin_35804181 的回复:] [quote=引用 4 楼 jklinux 的回复:] [quote=引用 3 楼 weixin_35804181 的回复:] [quote=引用 1 楼 jklinux 的回复:] IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据[/quote] 最后一招了, 试下设置socket选项(man 7 socket): SO_BINDTODEVICE Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maxi‐ mum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket.[/quote] 这个试过了不行,现在是IGMP确定是从ETH1发出去的,输入网口也接收了,但在进行路由(内核函数ip_rcv_finish)时被丢弃了[/quote] 在bind绑定端口号时指定网卡的ip地址也没用吗?[/quote] 没用,eth1确定已经加入组播,并且IGMP包也是从eth1发出去的,但是就是没有办法接收 eth0 1 224.0.0.251 eth0 1 224.0.0.1 eth1 1 224.2.2.2 eth1 1 224.0.0.251 eth1 1 224.0.0.1 eth2 1 224.0.0.251 eth2 1 224.0.0.1 丢包监控: 3995 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 2 drops at __netif_receive_skb_core+2c9 (0xffffffff81730369) 4063 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 200 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 1 drops at sk_stream_kill_queues+57 (0xffffffff81723c87) 1 drops at tcp_v4_rcv+80 (0xffffffff817943b0) [/quote] 确定也与防火墙无关吗? 我也来写代码测试下好了
酷咪哥 2017-06-22
  • 打赏
  • 举报
回复
引用 6 楼 jklinux 的回复:
[quote=引用 5 楼 weixin_35804181 的回复:] [quote=引用 4 楼 jklinux 的回复:] [quote=引用 3 楼 weixin_35804181 的回复:] [quote=引用 1 楼 jklinux 的回复:] IP_ADD_MEMBERSHIP (since Linux 1.2) Join a multicast group. Argument is an ip_mreqn structure. struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast group address */ struct in_addr imr_address; /* IP address of local interface */ int imr_ifindex; /* interface index */ }; 在linux应是用imr_ifindex指定网卡的序号
static int udp_multicastgroup_join(URLContext *s) { struct ip_mreqn mreq; memset(&mreq, 0, sizeof(struct ip_mreqn) ); mreq.imr_multiaddr.s_addr = inet_addr(s->url_info.hostname); mreq.imr_address.s_addr= ( NULL==s->urlctt_opt.udp_opt.localhostip_in) ? INADDR_ANY : inet_addr(s->urlctt_opt.udp_opt.localhostip_in); struct ifreq ifr; strcpy(ifr.ifr_name, "eth1"); ioctl(s->fd, SIOCGIFINDEX, &ifr); mreq.imr_ifindex=ifr.ifr_ifindex; ms_debug("interface index(eth1) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth0) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "eth2"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(eth2) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "lo"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(lo) :%d",ifr.ifr_ifindex); strcpy(ifr.ifr_name, "wlan0"); ioctl(s->fd, SIOCGIFINDEX, &ifr); ms_debug("interface index(wlan0) :%d",ifr.ifr_ifindex); if( NULL!=s->urlctt_opt.udp_opt.localhostip_in){ ms_debug("imr_address:%s",s->urlctt_opt.udp_opt.localhostip_in); } ms_debug("interface index(eth1) :%d",mreq.imr_ifindex); if (setsockopt(s->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { ms_errret(-1, "setsockopt(IP_ADD_MEMBERSHIP) %s (%d,%s)", s->urlctt_opt.udp_opt.localhostip_in,errno,strerror(errno) ); } return 0; } 依然不行呢?eth1抓包有数据[/quote] 最后一招了, 试下设置socket选项(man 7 socket): SO_BINDTODEVICE Bind this socket to a particular device like “eth0”, as specified in the passed interface name. If the name is an empty string or the option length is zero, the socket device binding is removed. The passed option is a variable-length null-terminated interface name string with the maxi‐ mum size of IFNAMSIZ. If a socket is bound to an interface, only packets received from that particular interface are processed by the socket.[/quote] 这个试过了不行,现在是IGMP确定是从ETH1发出去的,输入网口也接收了,但在进行路由(内核函数ip_rcv_finish)时被丢弃了[/quote] 在bind绑定端口号时指定网卡的ip地址也没用吗?[/quote] 没用,eth1确定已经加入组播,并且IGMP包也是从eth1发出去的,但是就是没有办法接收 eth0 1 224.0.0.251 eth0 1 224.0.0.1 eth1 1 224.2.2.2 eth1 1 224.0.0.251 eth1 1 224.0.0.1 eth2 1 224.0.0.251 eth2 1 224.0.0.1 丢包监控: 3995 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 2 drops at __netif_receive_skb_core+2c9 (0xffffffff81730369) 4063 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 200 drops at ip_rcv_finish+19b (0xffffffff8176e29b) 1 drops at sk_stream_kill_queues+57 (0xffffffff81723c87) 1 drops at tcp_v4_rcv+80 (0xffffffff817943b0)

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧