inet_net_ntop, inet_net_pton - Internet network number manipulation routines
inet_net_ntop(int af, const void *src, int bits, char *dst,
inet_net_pton(int af, const char *src, void *dst, size_t
The inet_net_ntop() function converts an Internet network
network format (usually a struct in_addr or some other binary form, in
network byte order) to CIDR presentation format (suitable
display purposes). bits is the number of bits in src that
are the network
number. It returns NULL if a system error occurs (in
errno will have been set), or it returns a pointer to the
The inet_net_pton() function converts a presentation format
number (that is, printable form as held in a character
network format (usually a struct in_addr or some other internal binary
representation, in network byte order). It returns the number of bits
(either computed based on the class, or specified with
/CIDR), or -1 if a
failure occurred (in which case errno will have been set.
It will be set
to ENOENT if the Internet network number was not valid).
Caution: The dst field should be zeroed before calling
the function will only fill the number of bytes necessary to
network number in network byte order.
The only value for af currently supported is AF_INET. size
is the size
of the result buffer dst.
NETWORK NUMBERS (IP VERSION 4) [Toc] [Back]
The external representation of Internet network numbers may
in one of the following forms:
Any of the above four forms may have ``/bits'' appended
where ``bits'' is
in the range 0-32 and is used to explicitly specify the number of bits in
the network address. When ``/bits'' is not specified the
number of bits
in the network address is calculated as the larger of the
number of bits
in the class to which the address belongs and the number of
rounded up modulo 8. Examples:
10 an 8 bit network number (class A), value
192 a 24 bit network number (class C), value
10.10 a 16 bit network number, value 10.10.0.0.
10.1.2 a 24 bit network number, value 10.1.2.0.
10.1.2.3 a 32 bit network number, value 10.1.2.3.
10.1.2.3/24 a 24 bit network number (explicit), value
Note that when the number of bits is specified using
the value of the address still includes all bits suplied in
representation, even those bits which are the host part of
address. Also, unlike inet_pton(3) where the external representation is
assumed to be an internet address, the external representation for
inet_net_pton() is assumed to be a network address. Thus
``10.1'' is assumed
to be ``10.1.0.0'' not ``10.0.0.1''
All numbers supplied as ``parts'' in a `.' notation may be
or hexadecimal, as specified in the C language (i.e., a
or 0X implies hexadecimal; otherwise, a leading 0 implies
the number is interpreted as decimal).
byteorder(3), inet(3), inet_pton(3), networks(5)
The inet_net_ntop and inet_net_pton functions first appeared
OpenBSD 3.6 June 18, 1997
[ Back ]