1

This might sound stupid. Pardon my limited knowledge in these stuff.

Is it possible to listen to multiple multicast groups, or more precisely, a range of addresses, for e.g. 224.128.*.* ? Usually these are denoted with CIDR network mask as /16 for example.

Presently I am binding my socket to a particular address as : sock.bind((ip, port)). But I would need to work with a range of addresses.

I am pretty much sure it is not possible. Just want to confirm.

Thanks

gaganbm
  • 2,663
  • 3
  • 24
  • 36

1 Answers1

0

It is somewhat possible. E.g.:

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', 2345))

for i in xrange(255):
    print i
    mreq = struct.pack("=4sl", socket.inet_aton("224.1.2.%d" % i),
                       socket.INADDR_ANY)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

Unfortunately, the kernel limits how many groups one socket can be joined to at one time: it is 20. It is not tunable, either (as far as I know).

EDIT: it is in fact tunable on Linux, via /proc/sys/net/ipv4/igmp_max_memberships.

ldx
  • 3,984
  • 23
  • 28
  • thanks for the example. I came across this [question](http://stackoverflow.com/questions/9243292/subscribing-to-multiple-multicast-groups-on-one-socket-linux-c) where they say that I can join as many groups as I can. Can you explain a bit on the limiting '20' number of groups that you are saying. Any reference will be helpful. – gaganbm May 02 '13 at 10:56
  • It appears I was wrong: /proc/sys/net/ipv4/igmp_max_memberships enables you to tune this on Linux. By default it is still 20. – ldx May 03 '13 at 12:28
  • Thanks. Got some information about the parameter. Will put it in edit. – gaganbm May 03 '13 at 12:52