HP-UX IPv6 Porting Guide (February 2007)
Converting Binary and Text Addresses
Converting a Text Address to Binary
Chapter 1044
The inet_aton() or inet_addr() functions convert dotted-decimal string (such as 10.9.8.7)
to 32-bit binary in network byte order.
inet_ntoa() converts 32-bit network byte order binary into dotted-decimal string (such as
10.9.8.7).
Two new IPv6 functions convert both IPv4 and IPv6 addresses.
Converting a Text Address to Binary
Syntax
void inet_pton(int addr_family, const char *strptr, void *addrptr)
The inet_pton() function call converts the IP address pointed to by
strptr
, from
presentation (string) format to numeric (binary) format, in the buffer pointed to by
addrptr
.
Converting a Binary Address to Text
Syntax
inet_ntop(int family, const void *addrptr, char *strptr, site_t len)
The inet_ntop() function call converts an IP address from numeric format to string format.
The
len
parameter specifies the calling function’s buffer size to prevent overflow. Two
definitions specify this buffer size for either IPv4 or IPv6 addresses in the <netinet/in.h>
header file.
#defineINET_ADDRSTRLEN16 /* for IPv4 dotted-decimal */
#defineINET6_ADDRSTRLEN46 /* for IPv6 hex string */