IPv4mappedIPv6prefix is the byte prefix for IPv4-mapped IPv6.
IPv4mask is used to select only the lower 32 bits of uint128. IPv4 addresses may not have the the upper 96 bits of Addr set to 0. IPv4 addresses mapped to IPv6 have prefix bits that should not change.
IPv4max is used for overflows.
IPv4size 1 byte for family, 1 byte for mask, 4 for IP.
IPv6size 1 byte for family, 1 byte for mask, 16 for IP.
ParseINet parses postgres style INET types. See TestIPAddrParseINet for examples.
Addr is the representation of the IP address. The Uint128 takes 16-bytes for both IPv4 and IPv6.
Add wraps the Uint128 addition.
Compare wraps the Uint128 equivilance.
Equal wraps the Uint128 equivilance.
String wraps net.IP.String().
Sub wraps the Uint128 subtraction.
WriteIPv4Bytes writes the 4-byte IPv4 representation. If the IP is IPv6 then the first 12-bytes are truncated.
WriteIPv6Bytes gets the 16-byte IPv6 representation.
IPAddr stores an IP address's family, IP, and host mask. This was chosen over Go's "net" IP, as that struct doesn't work well for what we need to do.
- It discards information when parsing IPv4, forcing it to be IPv6, and then assuming IPv4-mapped IPv6 addresses are purely IPv4 (only for printing). This is solved by having a Family field. - ParseIP and ParseCIDR are very strict, whereas postgres' INET and CIDR have very relaxed constraints for parsing an IP. - Doing int64 operations is much more efficient than byte slice operations.
RandIPAddr generates a random IPAddr. This includes random mask size and IP family.
Add returns a new IPAddr that is incremented by an int64.
And returns a new IPAddr which is the bitwise AND of two IPAddrs. Only the lower 32 bits are changed for IPv4.
Broadcast returns a new IPAddr where the host mask of the IP address is a full mask, i.e. 0xFF bytes.
Compare two IPAddrs. IPv4-mapped IPv6 addresses are not equal to their IPv4 mapping. The order of order importance goes Family > Mask > IP-bytes.
Complement returns a new IPAddr which is the bitwise complement of the original IP. Only the lower 32 bits are changed for IPv4.
ContainedBy determines if one ipAddr is in the same subnet as another.
ContainedByOrEquals determines if one ipAddr is in the same subnet as another or the addresses and subnets are equal.
Contains determines if one ipAddr is in the same subnet as another.
ContainsOrContainedBy determines if one ipAddr is in the same subnet as another or vice versa.
ContainsOrEquals determines if one ipAddr is in the same subnet as another or the addresses and subnets are equal.
Equal checks if the family, mask, and IP are equal.
FromBuffer populates an IPAddr with data from a byte slice, returning the remaining buffer or an error.
Hostmask returns the host masked IP. This is defined as the IP address bits that are not masked.
Netmask returns the network masked IP. This is defined as the IP address bits that are masked.
Or returns a new IPAddr which is the bitwise OR of two IPAddrs. Only the lower 32 bits are changed for IPv4.
String will convert the IP to the appropriate family formatted string representation. In order to retain postgres compatibility we ensure IPv4-mapped IPv6 stays in IPv6 format, unlike net.Addr.String().
Sub returns a new IPAddr that is decremented by an int64.
SubIPAddr returns the difference between two IPAddrs.
ToBuffer appends the IPAddr encoding to a buffer and returns the final buffer.
IPFamily denotes which classification the IP belongs to.