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
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
29       address must be in network byte order. The dst  argument  points  to  a
30       buffer  where  the  function stores the resulting text string; it shall
31       not be NULL. The size argument specifies the size of this buffer, which
32       shall  be large enough to hold the text string (INET_ADDRSTRLEN charac‐
33       ters for 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
47              ddd.ddd.ddd.ddd
48
49       where  "ddd"  is  a one to three digit decimal number between 0 and 255
50       (see inet_addr()). The inet_pton() function does not accept other  for‐
51       mats  (such  as  the octal numbers, hexadecimal numbers, and fewer than
52       four numbers that inet_addr() accepts).
53
54       If the af argument of inet_pton() is AF_INET6, the src string shall  be
55       in one of the following standard IPv6 text forms:
56
57        1. The  preferred  form  is "x:x:x:x:x:x:x:x", where the 'x' s are the
58           hexadecimal values of the eight 16-bit pieces of the address. Lead‐
59           ing  zeros  in individual fields can be omitted, but there shall be
60           at least one numeral in every field.
61
62        2. A string of contiguous zero fields in the  preferred  form  can  be
63           shown  as  "::"  .  The  "::"  can  only appear once in an address.
64           Unspecified addresses ( "0:0:0:0:0:0:0:0" ) may be represented sim‐
65           ply as "::" .
66
67        3. A  third form that is sometimes more convenient when dealing with a
68           mixed environment of IPv4 and IPv6 nodes is  "x:x:x:x:x:x:d.d.d.d",
69           where  the  'x'  s are the hexadecimal values of the six high-order
70           16-bit pieces of the address, and the 'd' s are the decimal  values
71           of  the  four  low-order 8-bit pieces of the address (standard IPv4
72           representation).
73
74       Note:  A more extensive description of the standard representations  of
75              IPv6 addresses can be found in RFC 2373.
76
77

RETURN VALUE

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

ERRORS

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

EXAMPLES

102       None.
103

APPLICATION USAGE

105       None.
106

RATIONALE

108       None.
109

FUTURE DIRECTIONS

111       None.
112

SEE ALSO

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