1inet_ntop(3XNET) X/Open Networking Services Library Functions inet_ntop(3XNET)
2
3
4

NAME

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

SYNOPSIS

10       cc [ flag ... ] file ... -lxnet [ library ... ]
11       #include <arpa/inet.h>
12
13       const char *inet_ntop(int af, const void *restrict src,
14            char *restrict dst, socklen_t size);
15
16
17       int inet_pton(int af, const char *restrict src, dst);
18
19

DESCRIPTION

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

RETURN VALUES

79       The inet_ntop() function returns a pointer to the buffer containing the
80       text string if the conversion succeeds. Otherwise it returns NULL   and
81       sets errno to indicate the error.
82
83
84       The inet_pton() function returns 1 if the conversion succeeds, with the
85       address pointed to by dst in network byte order. It returns  0  if  the
86       input is not a valid IPv4 dotted-decimal string or a valid IPv6 address
87       string. It returns −1 and sets errno to EAFNOSUPPORT if the af argument
88       is unknown.
89

ERRORS

91       The inet_ntop() and inet_pton() functions will fail if:
92
93       EAFNOSUPPORT    The af argument is invalid.
94
95
96       ENOSPC          The  size  of  the  inet_ntop() result buffer is inade‐
97                       quate.
98
99

ATTRIBUTES

101       See attributes(5) for descriptions of the following attributes:
102
103
104
105
106       ┌─────────────────────────────┬─────────────────────────────┐
107       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
108       ├─────────────────────────────┼─────────────────────────────┤
109       │Interface Stability          │Standard                     │
110       ├─────────────────────────────┼─────────────────────────────┤
111       │MT-Level                     │MT-Safe                      │
112       └─────────────────────────────┴─────────────────────────────┘
113

SEE ALSO

115       inet_addr(3XNET), attributes(5)
116
117
118
119SunOS 5.11                        1 Nov 2003                  inet_ntop(3XNET)
Impressum