在同一端口上接收多个多播提要

在同一端口上接收多个多播提要

本文介绍了在同一端口上接收多个多播提要-C,Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序正在从同一端口上的多个多播源接收数据.我能够接收数据.但是,我试图考虑每个组的统计信息(即接收到的msgs,接收到的字节),并且所有数据都变得混乱起来.有谁知道如何解决这个问题?如果我尝试查看发件人的地址,它不是多播地址,而是发送方机器的IP.

I have an application that is receiving data from multiple multicast sources on the same port. I am able to receive the data. However, I am trying to account for statistics of each group (i.e. msgs received, bytes received) and all the data is getting mixed up. Does anyone know how to solved this problem? If I try to look at the sender's address, it is not the multicast address, but rather the IP of the sending machine.

我正在使用以下套接字选项:

I am using the following socket options:

struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr("224.1.2.3");
mreq.imr_interface.s_addr = INADDR_ANY;
setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

还有:

setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &reuse, sizeof(reuse));

推荐答案

几年后,面对这种linux奇怪的行为,并使用了,我意识到 ip( 7)联机帮助页描述一种可能的解决方案:

After some years facing this linux strange behaviour, and using the bind workaround describe in previous answers, I realize that the ip(7) manpage describe a possible solution :

然后,您可以使用来激活过滤器以接收加入的群组的消息:

Then you can activate the filter to receive messages of joined groups using :

int mc_all = 0;
if ((setsockopt(sock, IPPROTO_IP, IP_MULTICAST_ALL, (void*) &mc_all, sizeof(mc_all))) < 0) {
    perror("setsockopt() failed");
}

Redhat Bug 231899 ,此讨论包含测试程序以重现该问题并加以解决.

This problem and the way to solve it enabling IP_MULTICAST_ALL is discussed in Redhat Bug 231899, this discussion contains test programs to reproduce the problem and to solve it.

这篇关于在同一端口上接收多个多播提要-C,Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!