Updated: April 19, 2023 |
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 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:
172.200.0.0/16
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:
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 Intel Pentium processors, the bytes referred to above appear as d.c.b.a.
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 occurred (errno is set).
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |