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 same box? If so, what needs to be setup or done differently?
PROCEDURE. In order to verify if Multicast is working correctly in your network, you can use the following quick tcpdump/ping test. If the Multicast is working correctly then you should see packets arriving at the first node. Repeat this procedure in each node to verify that Multicast is OK in your network.
You can only ping, via multicast, hosts which are subscribed to the multicast group which you are pinging. You need to be careful about which multicast groups you use, and, in general, you should use multicast groups from the administratively scoped range of 239.0.
A router will determine if any of the hosts on a locally attached network are configured to receive multicast datagrams using IGMP( Internet Group Management Protocol). Routers will listen for IGMP messages and periodically send queries on the local subnet.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With