微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法通过非默认NIC发送多播

在Windows 7虚拟机上,我尝试使用第二个(非认的)两个networking接口将UDP数据包发送到多播地址。 我可以使用/ INTF选项(不允许指定端口)使用mcast来实现此目的,但我的C#代码不起作用:

void run(string ipaddrstr,int port,string nicaddrstr) { int index = -1; // Create a socket for the UDP broadcast Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp); IPAddress ipaddr = IPAddress.Parse(ipaddrstr); IPAddress nicAddr = IPAddress.Parse(nicaddrstr); int i = 0; foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { foreach (UnicastIPAddressinformation ip in ni.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == System.Net.sockets.AddressFamily.InterNetwork) { if (ip.Address.Equals(nicAddr)) { index = i; break; } } } if (index != -1) { break; } i++; } if (index == -1) { Console.Error.WriteLine("Couldn't find NIC with IP address '" + nicaddrstr + "'"); return; } socket.SetSocketoption(SocketoptionLevel.IP,SocketoptionName.AddMembership,new MulticastOption(ipaddr,nicAddr)); int multicastInterfaceIndex = (int)IPAddress.HostToNetworkOrder(index); socket.SetSocketoption(SocketoptionLevel.IP,SocketoptionName.MulticastInterface,multicastInterfaceIndex); } socket.SetSocketoption(SocketoptionLevel.IP,SocketoptionName.MulticastTimetoLive,1); IPEndPoint endpoint = new IPEndPoint(ipaddr,port); socket.Connect(endpoint); // At this point,data can be send to the socket }

当我将nicaddrstr指定为认的networking接口IP地址时,数据按照预期在该接口上stream动。 但是,如果我将nicaddrstr指定为第二个(非认)networking接口IP地址,则不会有任何数据stream(由Wiresharkvalidation),即使在任何函数调用中都没有发生错误。 有人能告诉我mcast正在做什么,允许非认网卡接受UDP数据?

我尝试过路由表中的路由设置的各种组合,但内容似乎不影响此代码的行为。

在具有多个接口的服务器上接收多播(linux)

为什么在同一个端口但是从不同的组合的多播消息?

Linux桥认启用组播查询

在Linux上用C发送RAW Socket

我如何在Linux的Win7虚拟机上使用组播?

ping 224.0.0.1没有回复

2个Weblogic集群在同一个networking中

多播Ping(Windows)

刷新多播组成员资格

Windows服务器2008r2多播&igmp问题

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐