Receiving multiple multicast feeds on the same port - C, Linux

前端 未结 8 1105
予麋鹿
予麋鹿 2020-11-29 04:59

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

相关标签:
8条回答
  • 2020-11-29 05:39

    The Multicast address will be the receiver's address not sender's address in the packet. Look at the receiver's IP address.

    0 讨论(0)
  • 2020-11-29 05:41

    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 :

    IP_MULTICAST_ALL (since Linux 2.6.31)
    This option can be used to modify the delivery policy of multicast messages to sockets bound to the wildcard INADDR_ANY address. The argument is a boolean integer (defaults to 1). If set to 1, the socket will receive messages from all the groups that have been joined globally on the whole system. Otherwise, it will deliver messages only from the groups that have been explicitly joined (for example via the IP_ADD_MEMBERSHIP option) on this particular socket.

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

    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.

    0 讨论(0)
提交回复
热议问题