I noticed Go creates a 16 byte internal representation of a 4 byte IPv4 Address when using:
// IPv4 returns the IP address (in 16-byte form) of the
// IPv4 address a.b.c.d.
func IPv4(a, b, c, d byte) IP {
p := make(IP, IPv6len)
copy(p, v4InV6Prefix)
p[12] = a
p[13] = b
p[14] = c
p[15] = d
return p
}
https://golang.org/src/net/ip.go
Is there a reason that IPv4 is initially created with 16 bytes? I was doing some calculations for Broadcast and Networkaddress where I accessed the internal byte[] directly and got confused that I had to call To4()
to do something like
start := binary.BigEndian.Uint32([]byte(ip))
and actually get the IPv4 Address as uint32.