UDP Multicast HELP!
Martin v. Loewis
martin at v.loewis.de
Wed Jul 24 18:34:11 EDT 2002
"Larry" <ld @ nospam.com> writes:
> s1.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, '234.5.6.7')
The problem here is that IP_ADD_MEMBERSHIP requires a struct ip_mreq,
which is typically defined as
struct ip_mreq
{
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
};
So this is an 8-byte value. For imr_interface, you usually specify
INADDR_ANY, which is '\0\0\0\0', so you really need to use
group = socket.inet_aton('234.5.6.7') + '\0\0\0\0'
s1.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, group)
[Strictly speaking, you should use struct.pack to build the struct,
but the code above is just as portable, I assume]
HTH,
Martin
More information about the Python-list
mailing list