Skip to content Skip to sidebar Skip to footer

Why Doesn't A %en0 Suffix Work To Connect A Link-local Ipv6 Tcp Socket In Python?

A week or so ago someone on StackOverflow asked why their Python code for connecting to an IPv6 link-local address wasn't working, and I replied that since it was a link-local addr

Solution 1:

This is the correct way to do an ipv6 connection:

>>>addrinfo = getaddrinfo('fe80::225:ff:fecd:5aa0%en0', 2001, AF_INET6, SOCK_STREAM)>>>addrinfo
[(30, 1, 6, '', ('fe80::225:ff:fecd:5aa0%en0', 2001, 0, 4))]
>>>(family, socktype, proto, canonname, sockaddr) = addrinfo[0]>>>s = socket(family, socktype, proto)>>>s.connect(sockaddr)

getaddrinfo() will return the correct numerical scope and flow information for you.

Post a Comment for "Why Doesn't A %en0 Suffix Work To Connect A Link-local Ipv6 Tcp Socket In Python?"