Send UDP packet to link-local IPv6 address?

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Wed Oct 29 17:50:30 CET 2014


Grant Edwards <invalid at invalid.invalid> writes:

[...]
> With link-local addresses you also need to specify which interface to
> use. The normal way of doing this on Linux with command-line utilities
> is append %<ifname> to the address/hostname (e.g. ping6 ff02::1%net1).
>
> That doesn't work:
>
> s.sendto(data, ("ff02::1%net1",port))
> s.sendto(data, ("fe80::2c0:4eff:fe40:5f%net1",port))
>
> The "%net1" appears to be ignored, and the packet will go out _some_
> interface, but I can't figure out how it decides which one (it's not
> always the same one).

The only way I've found is to use socket.getaddrinfo(), which does
accept "%net1" after the IPv6 address, and returns scope_id (actually a
complete sockaddr). I can't access my files now, by I think

    socket.getaddrinfo("fe80::2c0:4eff:fe40:5f%net1",port,...)

should work for you (family, socktype etc should be passed also to avoid
searching the results of getaddrinfo()).

Hope this helps,

-- Alain.



More information about the Python-list mailing list