Python IPv6 Address Representation

I converted IPv6 addresses to a text representation and noticed behavior that I could not explain:

In[38]: socket.inet_ntop(socket.AF_INET6, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x7f\x00\x00\x01')
Out[38]: '::ffff:127.0.0.1'
In[39]: socket.inet_ntop(socket.AF_INET6, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\x7f\x00\x00\x00')
Out[39]: '::ff:ffff:7f00:0'

I am surprised to see it ::ffff:127.0.0.1, I expect it to be ::ffff:7f00:0. Is this standard or at least generic? What IPv6 addresses are represented in this way? The Wikipedia article does not mention this at all. I'm confused.

+4
source share
1 answer

The POSIXinet_ntop page for indicates this format as one of the parameters (slightly rephrased):

, IPv4 IPv6, - x:x:x:x:x:x:d.d.d.d, x - 16- , d - 8- ( IPv4).

+5

All Articles