Converts an address in its standard text presentation form into its numeric binary form, in network byte order. Format #include <inet.h> int inet_pton ( int af, const char *src, void *dst );
1 – Arguments
af Specifies the address family. Valid values are AF_INET for an IPv4 address and AF_INET6 for an IPv6 address. src Points to the address text string to be converted. dst Points to a buffer that is to contain the numeric address.
2 – Description
This function converts a text string to a numeric value in network byte order. o If the af parameter is AF_INET, the function accepts a string in the standard IPv4 dotted-decimal format: ddd.ddd.ddd.ddd In this format, ddd is a one- to three-digit decimal number between 0 and 255. o If the af parameter is AF_INET6, the function accepts a string in the following format: x:x:x:x:x:x:x:x In this format, x is the hexadecimal value of a 16-bit piece of the address. IPv6 addresses can contain long strings of zero (0) bits. To make it easier to write these addresses, you can use double- colon characters (::) one time in an address to represent 1 or more 16-bit groups of zeros. o For mixed IPv4 and IPv6 environments, the following format is also accepted: x:x:x:x:x:x:ddd.ddd.ddd.ddd In this format, x is the hexadecimal value of a 16-bit piece of the address, and ddd is a one- to three-digit decimal value between 0 and 255 that represents the IPv4 address. The calling application is responsible for ensuring that the buffer referred to by the dst parameter is large enough to hold the numeric address. AF_INET addresses require 4 bytes and AF_ INET6 addresses require 16 bytes.
3 – Return Values
1 Indicates success. 0 Indicates that the input string is neither a valid IPv4 dotted-decimal string nor a valid IPv6 address string. -1 Indicates a failure. errno is set to the following value.
4 – Errors
EAFNOSUPPORT The address family specified in the af parameter is unknown.