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

前端 未结 4 1428
没有蜡笔的小新
没有蜡笔的小新 2020-12-28 09:11

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

4条回答
  •  孤独总比滥情好
    2020-12-28 09:31

    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));
    

提交回复
热议问题