Re: sending and receiving ipv6 multicasts

2009-04-14 Thread Martin v. Löwis
> I get the following error: "socket.error: [Errno 22] Invalid
> argument". So it complains about the multicast address.

The fragment

py> import socket
py> s = socket.inet_pton(socket.AF_INET6, "ff02::1")
py> sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
py> sock.bind(('', 9090))
py> sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP,
socket.inet_pton(socket.AF_INET6, "ff02::1")+'\0'*4)

works fine for me.

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: sending and receiving ipv6 multicasts

2009-04-14 Thread Kai Timmer
On 13 Apr., 19:51, "Martin v. Löwis"  wrote:
> On the receiving side, you also need to set the IPV6_JOIN_GROUP
> socket option - else your kernel doesn't know you are interested in
> packets for that address. You need to bind to the multicast port,
> and optionally to the multicast address.

If I do the following
s , ifn = createSocket("eth0")
maddr = ("ff02::1", 10101)

maddr = socket.getaddrinfo(maddr[0], maddr[1], socket.AF_INET6,
socket.SOCK_DGRAM)[0][-1]
group = socket.inet_pton(socket.AF_INET6, maddr[0]) + ifn #ifn is the
interface index
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, group)
s.bind(maddr)

def createSocket(if=""):
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)

sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if hasattr(socket, "SO_REUSEPORT"):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP,
1)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS,
224)

ifn = if_nametoindex(if)
ifn = struct.pack("I", ifn)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF,
ifn)

return sock, ifn

I get the following error: "socket.error: [Errno 22] Invalid
argument". So it complains about the multicast address.
--
http://mail.python.org/mailman/listinfo/python-list


Re: sending and receiving ipv6 multicasts

2009-04-13 Thread Martin v. Löwis
Kai Timmer wrote:
> I am trying to send and receive packages via an ipv6 multicast. But I
> can't get it working. What I thought was, that on the listener site, I
> just need to bind my socket to the interfaces ipv6 local link address
> and on the sender site, to the multicast address (in my case ff02::).
> That doesn't work :)

On the receiving side, you also need to set the IPV6_JOIN_GROUP
socket option - else your kernel doesn't know you are interested in
packets for that address. You need to bind to the multicast port,
and optionally to the multicast address.

On the sending side, you just use sendto, passing the multicast
address as the recipient.

HTH,
Martin
--
http://mail.python.org/mailman/listinfo/python-list