如何在特定界面(Windows)下添加多播组
我可以使用cmd中的命令“netsh interface ip show joins”来显示每个接口下的多播组。但我真的不知道如何将组添加到 接口,如将IP地址239.39.188.188添加到“接口8:VirtualBox纯主机网络”。最简单的方法将不胜感激如何在特定界面(Windows)下添加多播组,windows,udp,multicast,Windows,Udp,Multicast,我可以使用cmd中的命令“netsh interface ip show joins”来显示每个接口下的多播组。但我真的不知道如何将组添加到 接口,如将IP地址239.39.188.188添加到“接口8:VirtualBox纯主机网络”。最简单的方法将不胜感激 Interface 3: Ethernet Scope References Last Address ---------- ---------- ---- --------------------- 0
Interface 3: Ethernet
Scope References Last Address
---------- ---------- ---- ---------------------
0 0 Yes 224.0.0.1
Interface 1: Loopback Interface
Scope References Last Address
---------- ---------- ---- ---------------------
0 2 Yes 239.255.255.250
Interface 8: VirtualBox Host-Only Network
Scope References Last Address
---------- ---------- ---- ---------------------
0 0 Yes 224.0.0.1
0 1 Yes 224.0.0.251
239.39.188.188 // this is what I want to add
顺便说一句,我尝试了一些方法,比如打开UDP套接字和设置IP_添加_成员身份()。此外,我还尝试在linux上使用命令“ipmaddr[add | del]MULTIADDR-dev-STRING”。
之后,我观察到IP_添加_成员设置成功。但因此,在上表中,我无法在特定接口下添加组。
为了打开UDP套接字并设置IP_添加_成员身份部分,我在linux中编码如下
ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr(_outIP.c_str()); // _outIP is destination address(group address), interface is ethernet interface
mreq.imr_interface.s_addr = _interface.length() > 0 ? inet_addr(_interface.c_str()) : htonl(INADDR_ANY);
if (setsockopt(_udpSock,IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(struct ip_mreq)) == -1) {
cout << "Fail to add ip membership!!!!" << endl;
}
else {
cout << "Success to add ip membership!!!!" << endl;
s = sprintf(warnmsg, "Success to add ip membership!!!!");
_ofile->write(warnmsg, s);
}
ip_-mreq-mreq;
mreq.imr_multiaddr.s_addr=inet_addr(_outIP.c_str());//_outIP是目标地址(组地址),接口是以太网接口
mreq.imr\u interface.s\u addr=\u interface.length()>0?inet_addr(_interface.c_str()):htonl(INADDR_ANY);
if(setsockopt(_udpSock,IPPROTO,IP,IP添加,成员,&mreq,sizeof(struct IP_mreq))=-1){
cout您必须使加入组的套接字永远打开。换句话说,您的程序不能终止。请在末尾为(;;){sleep(1000000);}
添加
当您的程序终止时,套接字将自动关闭,您的操作系统(Windows或Linux,无所谓)将再次离开组
操作系统中发生的事情稍微复杂一些,因为多个程序可能会加入同一个多播组,因此操作系统会保留引用计数,只有当组不再被任何套接字引用时,计算机才会离开该组。“打开UDP套接字并设置IP_添加_成员身份”是操作方法。“所有程序都失败”不是问题脚本。下面是“无法在特定界面下添加组”。由于您尚未发布代码,因此脱离主题。我希望我现在没有脱离主题>。这是关于Windows(如问题所述)还是Linux(如描述所述)?