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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       inet_ntop, inet_pton — convert IPv4 and IPv6 addresses  between  binary
14       and text form
15

SYNOPSIS

17       #include <arpa/inet.h>
18
19       const char *inet_ntop(int af, const void *restrict src,
20           char *restrict dst, socklen_t size);
21       int inet_pton(int af, const char *restrict src, void *restrict dst);
22

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

98       None.
99

APPLICATION USAGE

101       None.
102

RATIONALE

104       None.
105

FUTURE DIRECTIONS

107       None.
108

SEE ALSO

110       The Base Definitions volume of POSIX.1‐2008, <arpa_inet.h>
111
113       Portions  of  this text are reprinted and reproduced in electronic form
114       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
115       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
116       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
117       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
118       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
119       event of any discrepancy between this version and the original IEEE and
120       The Open Group Standard, the original IEEE and The Open Group  Standard
121       is  the  referee document. The original Standard can be obtained online
122       at http://www.unix.org/online.html .
123
124       Any typographical or formatting errors that appear  in  this  page  are
125       most likely to have been introduced during the conversion of the source
126       files to man page format. To report such errors,  see  https://www.ker
127       nel.org/doc/man-pages/reporting_bugs.html .
128
129
130
131IEEE/The Open Group                  2013                        INET_NTOP(3P)
Impressum