0x00 问题描述
An IP is a single IP address, a slice of bytes. Functions in this package accept either 4-byte (IPv4) or 16-byte (IPv6) slices as input.
GO的net库接受以4字节或16字节切片组成的IPv4和IPv6地址
Note that in this documentation, referring to an IP address as an IPv4 address or an IPv6 address is a semantic property of the address, not just the length of the byte slice: a 16-byte slice can still be an IPv4 address.
已知IPv4单位最大255,占8-bit,也就是1-byte,一共占4位,公共就是4-byte。
而IPv6地址单位最大65535占2-byte,一共8位,总共占16-byte.
所以无论是IPv4还是IPv6,一个16-byte长度的切片足以存储上述IP地址。所以go语言net库的IP地址是一16-byte大小的切片储存的。
- 阅读剩余部分 -