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):
A third form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is
x:x:x:x:x:x:d.d.d.d
, where thex
characters are the hexadecimal values of the six high-order 16-bit pieces of the address, and thed
characters are the decimal values of the four low-order 8-bit pieces of the address (standard IPv4 representation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With