有没有办法在同一盒上测试多播IP? [英] Is there a way to test multicast IP on same box?

查看:58
本文介绍了有没有办法在同一盒上测试多播IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想测试一组多播IP程序(发送者/接收者)而不必设置网络,是否可以在同一盒子上完成?如果是这样,需要进行哪些设置或以其他方式进行操作?

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?

推荐答案

您可能已经知道了这一点(因为该问题已有2年的历史了),但是要在单个主机上进行多播,您只需要做两件事:(1)确保您的接收多播套接字设置了SO_REUSEADDR(以便多个进程可以绑定相同的多播地址),以及(2)确保您的发送多播套接字设置了IP_MULTICAST_LOOP(这样,数据包将被循环回")到同一系统上的接收方).如果您的应用程序使用单个套接字同时发送和接收多播,则应在其上同时设置两个套接字选项.

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

这篇关于有没有办法在同一盒上测试多播IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆