tm_cidrhost
Function
tm_cidrhost
calculates a full host IP address for a given host number within a given IP network address prefix.
tm_cidrhost(prefix, hostnum)
prefix
must be given in CIDR notation, as defined in RFC 4632 section 3.1.
hostnum
is a whole number that can be represented as a binary integer with no more than the number of digits remaining in the address after the given prefix. For more details on how this function interprets CIDR prefixes and populates host numbers, see the worked example for tm_cidrsubnet
.
Conventionally host number zero is used to represent the address of the network itself and the host number that would fill all the host bits with binary 1 represents the network's broadcast address. These numbers should generally not be used to identify individual hosts except in unusual situations, such as point-to-point links.
This function accepts both IPv6 and IPv4 prefixes, and the result always uses the same addressing scheme as the given prefix.
INFO
As a historical accident, this function interprets IPv4 address octets that have leading zeros as decimal numbers, which is contrary to some other systems which interpret them as octal. We have preserved this behavior for backward compatibility, but recommend against relying on this behavior.
Examples
tm_cidrhost("10.12.112.0/20", 16)
10.12.112.16
tm_cidrhost("10.12.112.0/20", 268)
10.12.113.12
tm_cidrhost("fd00:fd12:3456:7890:00a2::/72", 34)
fd00:fd12:3456:7890::22
Related Functions
tm_cidrsubnet
calculates a subnet address under a given network address prefix.tm_cidrsubnets
calculates a sequence of consecutive IP address ranges within a particular CIDR prefix.tm_cidrnetmask
converts an IPv4 address prefix given in CIDR notation into a subnet mask address.tm_cidrcontains
determines whether a given IP address or an address prefix given in CIDR notation is within a given IP network address prefix.