inet_pton
inet_pton converts an IPv4 or IPv6 Internet network address in its standard text presentation form into its numeric binary form in network byte order. This is the ANSI version of the Windows function InetPton.
Syntax
INT WSAAPI inet_pton( INT Family, PCSTR pszAddrString, PVOID pAddrBuf );
Parameters
Family
The address family: AF_INET or AF_INET6.
pszAddrString
A pointer to the NULL-terminated string that contains the text representation of the IP address.
If Family is AF_INET, the pszAddrString parameter must point to a text representation of an IPv4 address in standard dotted-decimal notation.
If Family is AF_INET6, the pszAddrString parameter must point to a text representation of an IPv6 address in standard notation.
pAddrBuf
A pointer to a buffer to store the numeric binary representation of the IP address.
If Family is AF_INET, this buffer should be large enough to hold an IN_ADDR structure.
If Family is AF_INET6, this buffer should be large enough to hold an IN6_ADDR structure.
Return Value
1 is returned if the function succeeds. The buffer pointed to by the pAddrBuf parameter contains the binary numeric IP address in network byte order.
0 is returned if the pAddrBuf parameter does not point to a valid IPv4 dotted-decimal or IPv6 address string presentation.
-1 is returned on other errors. A specific error code can be retrieved by calling WSAGetLastError.
Possible error codes returned by WSAGetLastError are:
Error Code | Meaning |
---|---|
WSAEAFNOSUPPORT |
The address family is not supported. |
WSAEFAULT |
An invalid parameter was passed to the function. |
Requirements
Minimum Supported Version | RTX64 2014 with Service Pack 1 |
Header | Winsock2.h, WS2Tcpip.h |
Library | RtTcpip.lib |