1INET_NTOP(P)               POSIX Programmer's Manual              INET_NTOP(P)
2
3
4

NAME

6       inet_ntop,  inet_pton  - convert IPv4 and IPv6 addresses between binary
7       and text form
8

SYNOPSIS

10       #include <arpa/inet.h>
11
12       const char *inet_ntop(int af, const void *restrict src,
13              char *restrict dst, socklen_t size);
14       int inet_pton(int af, const char *restrict src, void *restrict dst);
15
16

DESCRIPTION

18       The inet_ntop() function shall convert a numeric address  into  a  text
19       string  suitable  for  presentation.  The af argument shall specify the
20       family of the address. This can be AF_INET  or AF_INET6.  The src argu‐
21       ment  points  to a buffer holding an IPv4 address if the af argument is
22       AF_INET,  or an IPv6 address if  the  af  argument  is  AF_INET6;   the
23       address  must  be  in  network byte order. The dst argument points to a
24       buffer where the function stores the resulting text  string;  it  shall
25       not be NULL. The size argument specifies the size of this buffer, which
26       shall be large enough to hold the text string (INET_ADDRSTRLEN  charac‐
27       ters for IPv4,    INET6_ADDRSTRLEN characters for IPv6).
28
29       The  inet_pton() function shall convert an address in its standard text
30       presentation form into its numeric binary form.  The af argument  shall
31       specify  the family of the address. The AF_INET    and AF_INET6 address
32       families shall be supported. The src  argument  points  to  the  string
33       being  passed  in.  The  dst argument points to a buffer into which the
34       function stores the numeric address; this shall be large enough to hold
35       the numeric address (32 bits for AF_INET,  128 bits for AF_INET6).
36
37       If  the  af argument of inet_pton() is AF_INET, the src string shall be
38       in the standard IPv4 dotted-decimal form:
39
40
41              ddd.ddd.ddd.ddd
42
43       where "ddd" is a one to three digit decimal number between  0  and  255
44       (see inet_addr() ). The inet_pton() function does not accept other for‐
45       mats (such as the octal numbers, hexadecimal numbers,  and  fewer  than
46       four numbers that inet_addr() accepts).
47
48       If  the af argument of inet_pton() is AF_INET6, the src string shall be
49       in one of the following standard IPv6 text forms:
50
51        1. The preferred form is "x:x:x:x:x:x:x:x" , where the 'x' s  are  the
52           hexadecimal values of the eight 16-bit pieces of the address. Lead‐
53           ing zeros in individual fields can be omitted, but there  shall  be
54           at least one numeral in every field.
55
56        2. A  string  of  contiguous  zero fields in the preferred form can be
57           shown as "::" . The "::"  can  only  appear  once  in  an  address.
58           Unspecified addresses ( "0:0:0:0:0:0:0:0" ) may be represented sim‐
59           ply as "::" .
60
61        3. A third form that is sometimes more convenient when dealing with  a
62           mixed environment of IPv4 and IPv6 nodes is "x:x:x:x:x:x:d.d.d.d" ,
63           where the 'x' s are the hexadecimal values of  the  six  high-order
64           16-bit  pieces of the address, and the 'd' s are the decimal values
65           of the four low-order 8-bit pieces of the  address  (standard  IPv4
66           representation).
67
68       Note:  A  more extensive description of the standard representations of
69              IPv6 addresses can be found in RFC 2373.
70
71

RETURN VALUE

73       The inet_ntop() function shall return a pointer to the buffer  contain‐
74       ing the text string if the conversion succeeds, and NULL otherwise, and
75       set errno to indicate the error.
76
77       The inet_pton() function shall return 1  if  the  conversion  succeeds,
78       with  the  address  pointed  to  by dst in network byte order. It shall
79       return 0 if the input is not a valid IPv4 dotted-decimal string    or a
80       valid  IPv6  address string,  or -1 with errno set to [EAFNOSUPPORT] if
81       the af argument is unknown.
82

ERRORS

84       The inet_ntop() and inet_pton() functions shall fail if:
85
86       EAFNOSUPPORT
87
88              The af argument is invalid.
89
90       ENOSPC The size of the inet_ntop() result buffer is inadequate.
91
92
93       The following sections are informative.
94

EXAMPLES

96       None.
97

APPLICATION USAGE

99       None.
100

RATIONALE

102       None.
103

FUTURE DIRECTIONS

105       None.
106

SEE ALSO

108       The Base Definitions volume of IEEE Std 1003.1-2001, <arpa/inet.h>
109
111       Portions of this text are reprinted and reproduced in  electronic  form
112       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
113       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
114       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
115       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
116       event of any discrepancy between this version and the original IEEE and
117       The Open Group Standard, the original IEEE and The Open Group  Standard
118       is  the  referee document. The original Standard can be obtained online
119       at http://www.opengroup.org/unix/online.html .
120
121
122
123IEEE/The Open Group                  2003                         INET_NTOP(P)
Impressum