Receiving multicast data from different groups on the same socket in linux

c, linux, multicast, sockets

Solution

No, you can't bind a socket to 2 ports, you need a socket per port.

Problem

Say I want to receive data from 239.1.2.3:20000 and also from 239.4.5.6:20001 in a linux C program. Can I do so with just one socket? I can of course join multiple groups on the socket using the IP_ADD_MEMBERSHIP `setsockopt` option, but, since the ports are different, I am not sure if it is possible to somehow "bind to both ports"

Original source