1inet_ntop(3) Library Functions Manual inet_ntop(3)
2
3
4
6 inet_ntop - convert IPv4 and IPv6 addresses from binary to text form
7
9 Standard C library (libc, -lc)
10
12 #include <arpa/inet.h>
13
14 const char *inet_ntop(int af, const void *restrict src,
15 char dst[restrict .size], socklen_t size);
16
18 This function converts the network address structure src in the af ad‐
19 dress family into a character string. The resulting string is copied
20 to the buffer pointed to by dst, which must be a non-null pointer. The
21 caller specifies the number of bytes available in this buffer in the
22 argument size.
23
24 inet_ntop() extends the inet_ntoa(3) function to support multiple ad‐
25 dress families, inet_ntoa(3) is now considered to be deprecated in fa‐
26 vor of inet_ntop(). The following address families are currently sup‐
27 ported:
28
29 AF_INET
30 src points to a struct in_addr (in network byte order) which is
31 converted to an IPv4 network address in the dotted-decimal for‐
32 mat, "ddd.ddd.ddd.ddd". The buffer dst must be at least
33 INET_ADDRSTRLEN bytes long.
34
35 AF_INET6
36 src points to a struct in6_addr (in network byte order) which is
37 converted to a representation of this address in the most appro‐
38 priate IPv6 network address format for this address. The buffer
39 dst must be at least INET6_ADDRSTRLEN bytes long.
40
42 On success, inet_ntop() returns a non-null pointer to dst. NULL is re‐
43 turned if there was an error, with errno set to indicate the error.
44
46 EAFNOSUPPORT
47 af was not a valid address family.
48
49 ENOSPC The converted address string would exceed the size given by
50 size.
51
53 For an explanation of the terms used in this section, see at‐
54 tributes(7).
55
56 ┌─────────────────────────────────────┬───────────────┬────────────────┐
57 │Interface │ Attribute │ Value │
58 ├─────────────────────────────────────┼───────────────┼────────────────┤
59 │inet_ntop() │ Thread safety │ MT-Safe locale │
60 └─────────────────────────────────────┴───────────────┴────────────────┘
61
63 POSIX.1-2008.
64
66 POSIX.1-2001.
67
68 Note that RFC 2553 defines a prototype where the last argument size is
69 of type size_t. Many systems follow RFC 2553. glibc 2.0 and 2.1 have
70 size_t, but 2.2 and later have socklen_t.
71
73 AF_INET6 converts IPv4-mapped IPv6 addresses into an IPv6 format.
74
76 See inet_pton(3).
77
79 getnameinfo(3), inet(3), inet_pton(3)
80
81
82
83Linux man-pages 6.04 2023-03-30 inet_ntop(3)