Yur*_*ula 15
就像尼古拉的补遗一样:KB318911的问题是一个肮脏的技巧,用户必须提供必要的适配器索引.在查看如何检索此适配器索引时,我想出了这样的配方:
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
IPInterfaceProperties ip_properties = adapter.GetIPProperties();
if (!adapter.GetIPProperties().MulticastAddresses.Any())
continue; // most of VPN adapters will be skipped
if (!adapter.SupportsMulticast)
continue; // multicast is meaningless for this type of connection
if (OperationalStatus.Up != adapter.OperationalStatus)
continue; // this adapter is off or not connected
IPv4InterfaceProperties p = adapter.GetIPProperties().GetIPv4Properties();
if (null == p)
continue; // IPv4 is not configured on this adapter
// now we have adapter index as p.Index, let put it to socket option
my_sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, (int)IPAddress.HostToNetworkOrder(p.Index));
}
Run Code Online (Sandbox Code Playgroud)
完整说明http://windowsasusual.blogspot.ru/2013/01/socket-option-multicast-interface.html
| 归档时间: |
|
| 查看次数: |
13555 次 |
| 最近记录: |