开发者

Is there a way to test multicast IP on same box?

开发者 https://www.devze.com 2022-12-11 00:06 出处:网络
If I want to test a set of multicast IP programs (sender/receiver) without having to set up the networking, can this be done on the s开发者_Python百科ame box?If so, what needs to be setup or done diff

If I want to test a set of multicast IP programs (sender/receiver) without having to set up the networking, can this be done on the s开发者_Python百科ame box? If so, what needs to be setup or done differently?


You may have figured this out already (since the question is now 2 years old) but to do multicast on a single host, you only have to do two things: (1) make sure that your receiving multicast sockets have SO_REUSEADDR set (so that multiple processes can bind the same multicast address) and (2) make sure your sending multicast sockets have IP_MULTICAST_LOOP set (so that packets will be "looped back" to receivers on the same system). If your application uses a single socket for both sending and receiving multicasts, you would set both socket options on it.

int recv_s = socket(AF_INET, SOCK_DGRAM, 0);
int send_s = socket(AF_INET, SOCK_DGRAM, 0);
u_int yes = 1;
setsockopt(recv_s, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
setsockopt(send_s, IPPROTO_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes));


This may not be what you're looking for, but when I was writing code that used a bunch of broadcast and socket connections and such, I just made two virtual machines in VMWare, booted them off the live CDs, and uploaded my code. If your code runs in Windows, just make two installs of Windows. VMWare places the machines on the same subnet, so communication between them works just fine, broadcast and all. (and I assume multicast, though I didn't have direct experience with that.)


Some amount of network setup is necessary. If you do not want to create a physical network you can add multiple IP addresses to a single network card. If your machine has more than one network card you can even create a network with just two cards and a hub. Also if your machine has a wireless interface and a wired interface then connecting your machine to your wireless hub via both the wireless and wired interfaces will also get you a network.

Hope one of these ideas helps. Pat O


I would say the easiest thing to do would be to setup multiple IPs on your NIC. Just make sure you listen on specifict address and not on all.

HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消