I was converting IPv6 addresses to the textual representation and noticed a behavior 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 ::ffff:127.0.0.1
, I'd expect it to be ::ffff:7f00:0
. Is it standard or at least common? Which IPv6 addresses are represented this way? The Wikipedia article doesn't mention it at all. I am confused.
The POSIX page for
inet_ntop
specifies that format as one of the options (slightly paraphrased):