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

NAME

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

SYNOPSIS

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

DESCRIPTION

23       The  inet_ntop()  function  shall convert a numeric address into a text
24       string suitable for presentation. The af  argument  shall  specify  the
25       family  of the address. This can be AF_INET or AF_INET6.  The src argu‐
26       ment points to a buffer holding an IPv4 address if the af  argument  is
27       AF_INET, or an IPv6 address if the af argument is AF_INET6; the address
28       must be in network byte order. The dst  argument  points  to  a  buffer
29       where  the  function  stores the resulting text string; it shall not be
30       NULL. The size argument specifies the size of this buffer, which  shall
31       be large enough to hold the text string (INET_ADDRSTRLEN characters for
32       IPv4, INET6_ADDRSTRLEN characters for IPv6).
33
34       The inet_pton() function shall convert an address in its standard  text
35       presentation  form  into its numeric binary form. The af argument shall
36       specify the family of the address. The  AF_INET  and  AF_INET6  address
37       families  shall  be  supported.  The  src argument points to the string
38       being passed in. The dst argument points to a  buffer  into  which  the
39       function stores the numeric address; this shall be large enough to hold
40       the numeric address (32 bits for AF_INET, 128 bits for AF_INET6).
41
42       If the af argument of inet_pton() is AF_INET, the src string  shall  be
43       in the standard IPv4 dotted-decimal form:
44
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 one to four hexadecimal digits 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‐2017, <arpa_inet.h>
111
113       Portions  of  this text are reprinted and reproduced in electronic form
114       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
115       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
116       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
117       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
118       event of any discrepancy between this version and the original IEEE and
119       The  Open Group Standard, the original IEEE and The Open Group Standard
120       is the referee document. The original Standard can be  obtained  online
121       at http://www.opengroup.org/unix/online.html .
122
123       Any  typographical  or  formatting  errors that appear in this page are
124       most likely to have been introduced during the conversion of the source
125       files  to  man page format. To report such errors, see https://www.ker
126       nel.org/doc/man-pages/reporting_bugs.html .
127
128
129
130IEEE/The Open Group                  2017                        INET_NTOP(3P)
Impressum