Convert an Internet network number to CIDR format
#include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> char * inet_net_ntop( int af, const void * src, int bits, char * dst, size_t size );
- The address family. Currently, only AF_INET is supported.
- A pointer to the Internet network number that you want to convert. The format of the address is interpreted according to af.
- The number of bits that specify the network number (src).
- a pointer to the buffer where the function can store the converted address.
- The size of the buffer that dst points to, in bytes.
Use the -l socket option to qcc to link against this library.
The inet_net_ntop() function converts an Internet network number from network format (usually a struct in_addr or some other binary form, in network byte order) to CIDR (Classless Internet Domain Routing) presentation format that's suitable for external display purposes.
With CIDR, a single IP address can be used to designate many unique IP addresses. A CIDR IP address looks like a normal IP address, except that it ends with a slash (/) followed by a number, called the IP prefix. For example:
The IP prefix specifies how many addresses are covered by the CIDR address, with lower numbers covering more addresses.
Network Numbers (IPv4 Internet addresses)
You can specify Internet addresses in the "dotted quad" notation, or Internet network numbers, using one of the following forms:
- a.b.c.d/bits or a.b.c.d
- When you specify a four-part address, each part is interpreted as a byte of data and is assigned, from left to right, to the four bytes of an Internet network number (or Internet address). When an Internet network number is viewed as a 32-bit integer quantity on a system that uses little-endian byte order (i.e. right to left), such as the Intel 486 and Pentium processors, the bytes referred to above appear as " d.c.b.a ".
- When you specify a three-part address, the last part is interpreted as a 16-bit quantity and is placed in the rightmost two bytes of the Internet network number (or network address). This makes the three-part address format convenient for specifying Class B network addresses as net.net.host.
- When you specify a two-part address, the last part is interpreted as a 24-bit quantity and is placed in the rightmost three bytes of the Internet network number (or network address). This makes the two-part number format convenient for specifying Class A network numbers as net.host.
- When you specify a one-part address, the value is stored directly in the Internet network number (network address) without any byte rearrangement.
All numbers supplied as "parts" in a dot notation may be decimal, octal, or hexadecimal, as specified in the C language. That is, a number is interpreted as decimal unless it has a leading 0 (octal), or a leading 0x or 0X (hex).
A pointer to the destination string (dst), or NULL if a system error occurs ( errno is set).
- Invalid argument af.
Last modified: 2014-06-24