java多网卡组播_多网卡接收组播问题

linux环境处理方法:

如果是多网卡多网段,在接收组播时有时收不到UDP包,可以考虑修改/etc/sysctl.conf文件,把 net.ipv4.conf.all.rp_filter和net.ipv4.conf.default.rp_filter设为0即可

系统配置文件

1. /etc/sysctl.conf

把 net.ipv4.conf.all.rp_filter和net.ipv4.conf.default.rp_filter设为0即可

net.ipv4.conf.default.rp_filter = 0

net.ipv4.conf.all.rp_filter = 0

系统启动后,会自动加载这个配置文件,内核会使用这个变量

2. 命令行

显示一个内核变量 sysctl net.ipv4.conf.all.rp_filter

设置一个内核变量 sysctl -w net.ipv4.conf.all.rp_filter=0

设置完后,会更新内核(实时的内存)中的变量的值,但不会修改sysctl.conf的值

3. 使用/proc文件系统

查看 cat /proc/sys/net/ipv4/conf/all/rp_filter

设置 echo "0">/proc/sys/net/ipv4/conf/all/rp_filter

Windows处理方法

IP_MULTICAST_IF.

Usually, the system administrator specifies the default interface multicast datagrams should be sent from. The programmer can override this and choose a concrete outgoing interface for a given socket with this option.

struct in_addr interface_addr;

setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(interface_addr));

>From now on, all multicast traffic generated in this socket will be output from the interface chosen. To revert to the original behavior and let the kernel choose the outgoing interface based on the system administrator's configuration, it is enough to call setsockopt() with this same option and INADDR_ANY in the interface field.

In determining or selecting outgoing interfaces, the following ioctls might be useful: SIOCGIFADDR (to get an interface's address), SIOCGIFCONF (to get the list of all the interfaces) and SIOCGIFFLAGS (to get an interface's flags and, thus, determine whether the interface is multicast capable or not -the IFF_MULTICAST flag-).

If the host has more than one interface and the IP_MULTICAST_IF option is not set, multicast transmissions are sent from the default interface, although the remainding interfaces might be used for multicast forwarding if the host is acting as a multicast router.

虽然使用上面的参数以期望来绑定IP 甚至采用bind动作也没能成功, 唯一的方法还是调整组播的缺省路由。

下面几个命令非常有用:

查看当前各个网卡有那些在绑定的组播IP

netsh interface ip show joins

查看路由表

route print

添加路由

route add destinationmask subnetmask gateway metriccost metric if interface

示例:   route add 224.0.0.0 mask 240.0.0.0 192.168.50.186

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值