inet6.3n (2010 09)

i
inet6(3N) inet6(3N)
NAME
inet_pton(), inet_ntop() - Internet address manipulation routines for IP Version 4 and later
SYNOPSIS
#include <sys/socket.h>
#include <arpa/inet.h>
int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src,
char *dst, size_t size);
DESCRIPTION
The functions inet_pton() and inet_ntop() are new with IP Version 6 (IPv6) and work with both
IP Version 4 (IPv4) and IPv6 addresses. The letters "p" and "n" stand for
presentation and numeric.
The presentation format for an address is often an ASCII string and the numeric format is the binary
value that goes into a socket address structure.
The ASCII string is either the IPv4 address in dot notation or an IPv6 address in colon notation. An
example of an ASCII string is
15.10.43.255 or
1080::2538:400:25:800:200C:417A
.
The binary value is the hex representation of the IPv4/IPv6 address. This binary value resides in the
in_addr structure for IPv4 address and in the in6_addr structure for IPv6 address. (Refer to the
inet (3N) manpage for more details.)
The functions
inet_pton() and inet_ntop() are opposite of each other. The function
inet_pton() converts an ASCII address string to binary address, and the function inet_ntop()
converts a binary address into ASCII address string. Also, these are equivalent to inet_addr() and
inet_ntoa(), respectively.
The inet_pton() Function
The
inet_pton() function converts an address in its standard text presentation form into its numeric
binary form.
The af argument specifies the family of the address. Currently, the
AF_INET and AF_INET6 address
families are supported.
The src argument points to the IPv6/IPv4 address string being passed in.
The
dst argument points to a buffer in which the function stores the numeric address. The address is
returned in network byte order.
inet_pton() returns 1 if the conversion succeeds, 0 if the input is not a valid IPv4 dotted-decimal
string or a valid IPv6 address string, or -1 with errno set to [EAFNOSUPPORT] if the af argument is
unknown.
The calling application must ensure that the buffer referred to by dst is large enough to hold the numeric
address (e.g., 4 bytes for
AF_INET or 16 bytes for AF_INET6).
If the af argument is
AF_INET, the function accepts a string in the standard IPv4 dotted-decimal form:
ddd.ddd.ddd.ddd
where ddd is a one to three digit decimal number between 0 and 255. Note that many implementations of
the existing
inet_addr() and inet_aton() functions accept nonstandard input: octal numbers,
hexadecimal numbers, and fewer than four numbers. inet_pton() does not accept these formats.
If the af argument is
AF_INET6, then the function accepts a string in one of the standard IPv6 text
forms. (Refer to the IPv6 address notation below for more details).
The inet_ntop() Function
The
inet_ntop() function converts a numeric address into a text string suitable for presentation.
The af argument specifies the family of the address. This can be
AF_INET or AF_INET6.
The src argument points to a buffer holding an IPv4 address if the af argument is
AF_INET,oranIPv6
address if the af argument is AF_INET6.
The dst argument points to a buffer where the function will store the resulting text string.
The size argument specifies the size of this buffer. The application must specify a non-NULL dst argu-
ment. For IPv6 addresses, the buffer must be at least 46-octets. For IPv4 addresses, the buffer must be at
least 16-octets. In order to allow applications to easily declare buffers of the proper size to store IPv4 and
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)