下面这段python代码在macOS和linux时运行的结果是不同的
import socket
ip = socket.inet_pton(socket.AF_INET6, '1:2:3:0:5:6:7:8')
print socket.inet_ntop(socket.AF_INET6, ip)
macOS
1:2:3::5:6:7:8
linux
1:2:3:0:5:6:7:8
可以看到区别在于,中间的一个0有没有压缩
哪一个行为更合理呢?
https://tools.ietf.org/html/rfc4291#section-2.2
- Due to some methods of allocating certain styles of IPv6 addresses, it will be common for addresses to contain long strings of zero bits. In order to make writing addresses containing zero bits easier, a special syntax is available to compress the zeros. The use of "::" indicates one or more groups of 16 bits of zeros. The "::