diff options
author | guenther <> | 2014-04-19 11:18:01 +0000 |
---|---|---|
committer | guenther <> | 2014-04-19 11:18:01 +0000 |
commit | 442335bf77f2f6653794378cc53adb59bba1ed12 (patch) | |
tree | 2d4d6567e4224e5b538d0c518319524895f5a922 /src | |
parent | 390a6ad86d0c194f7195536ef4f2b8f55ead29a5 (diff) | |
download | openbsd-442335bf77f2f6653794378cc53adb59bba1ed12.tar.gz openbsd-442335bf77f2f6653794378cc53adb59bba1ed12.tar.bz2 openbsd-442335bf77f2f6653794378cc53adb59bba1ed12.zip |
Split inet(3) into three pages by decade: 1980s -> inet_lnaof(3),
1990s -> inet_addr(3), 2000s and beyond -> inet_ntop(3).
ok tedu@ (who also noted the timeline) deraadt@ jmc@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/net/Makefile.inc | 15 | ||||
-rw-r--r-- | src/lib/libc/net/inet_addr.3 | 197 | ||||
-rw-r--r-- | src/lib/libc/net/inet_lnaof.3 | 90 | ||||
-rw-r--r-- | src/lib/libc/net/inet_ntop.3 (renamed from src/lib/libc/net/inet.3) | 201 |
4 files changed, 320 insertions, 183 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index f4153bbfb4..a619fe4ed9 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.51 2014/04/07 17:57:56 schwarze Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.52 2014/04/19 11:18:01 guenther Exp $ |
2 | 2 | ||
3 | # net sources | 3 | # net sources |
4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net |
@@ -27,8 +27,9 @@ SRCS+= ip6opt.c rthdr.c vars6.c | |||
27 | 27 | ||
28 | MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ | 28 | MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ |
29 | getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ | 29 | getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ |
30 | getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \ | 30 | getrrsetbyname.3 getservent.3 if_indextoname.3 \ |
31 | inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \ | 31 | inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ |
32 | inet6_option_space.3 inet6_rthdr_space.3 \ | ||
32 | inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ | 33 | inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ |
33 | rcmd.3 rcmdsh.3 resolver.3 | 34 | rcmd.3 rcmdsh.3 resolver.3 |
34 | 35 | ||
@@ -61,10 +62,10 @@ MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ | |||
61 | getservent.3 endservent_r.3 | 62 | getservent.3 endservent_r.3 |
62 | MLINKS+= if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ | 63 | MLINKS+= if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ |
63 | if_indextoname.3 if_freenameindex.3 | 64 | if_indextoname.3 if_freenameindex.3 |
64 | MLINKS+=inet.3 inet_addr.3 inet.3 inet_aton.3 \ | 65 | MLINKS+=inet_addr.3 inet_aton.3 inet_addr.3 inet_network.3 \ |
65 | inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ | 66 | inet_addr.3 inet_ntoa.3 \ |
66 | inet.3 inet_network.3 inet.3 inet_ntoa.3 \ | 67 | MLINKS+=inet_lnaof.3 inet_makeaddr.3 inet_lnaof.3 inet_netof.3 |
67 | inet.3 inet_ntop.3 inet.3 inet_pton.3 | 68 | MLINKS+=inet_ntop.3 inet_pton.3 |
68 | MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 | 69 | MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 |
69 | MLINKS+=link_addr.3 link_ntoa.3 | 70 | MLINKS+=link_addr.3 link_ntoa.3 |
70 | MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ | 71 | MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ |
diff --git a/src/lib/libc/net/inet_addr.3 b/src/lib/libc/net/inet_addr.3 new file mode 100644 index 0000000000..abe9e5d8c9 --- /dev/null +++ b/src/lib/libc/net/inet_addr.3 | |||
@@ -0,0 +1,197 @@ | |||
1 | .\" $OpenBSD: inet_addr.3,v 1.1 2014/04/19 11:18:01 guenther Exp $ | ||
2 | .\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1983, 1990, 1991, 1993 | ||
5 | .\" The Regents of the University of California. All rights reserved. | ||
6 | .\" | ||
7 | .\" Redistribution and use in source and binary forms, with or without | ||
8 | .\" modification, are permitted provided that the following conditions | ||
9 | .\" are met: | ||
10 | .\" 1. Redistributions of source code must retain the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer. | ||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
13 | .\" notice, this list of conditions and the following disclaimer in the | ||
14 | .\" documentation and/or other materials provided with the distribution. | ||
15 | .\" 3. Neither the name of the University nor the names of its contributors | ||
16 | .\" may be used to endorse or promote products derived from this software | ||
17 | .\" without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | .\" SUCH DAMAGE. | ||
30 | .\" | ||
31 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 | ||
32 | .\" | ||
33 | .Dd $Mdocdate: April 19 2014 $ | ||
34 | .Dt INET_ADDR 3 | ||
35 | .Os | ||
36 | .Sh NAME | ||
37 | .Nm inet_aton , | ||
38 | .Nm inet_addr , | ||
39 | .Nm inet_network , | ||
40 | .Nm inet_ntoa | ||
41 | .Nd Internet Protocol version 4 (IPv4) address manipulation routines | ||
42 | .Sh SYNOPSIS | ||
43 | .In arpa/inet.h | ||
44 | .Ft int | ||
45 | .Fn inet_aton "const char *cp" "struct in_addr *addr" | ||
46 | .Ft in_addr_t | ||
47 | .Fn inet_addr "const char *cp" | ||
48 | .Ft in_addr_t | ||
49 | .Fn inet_network "const char *cp" | ||
50 | .Ft char * | ||
51 | .Fn inet_ntoa "struct in_addr in" | ||
52 | .Sh DESCRIPTION | ||
53 | The functions presented here only support IPv4 addresses. | ||
54 | In order to support IPv6 addresses as well, | ||
55 | .Xr inet_ntop 3 | ||
56 | and | ||
57 | .Xr inet_pton 3 | ||
58 | should be used rather than the functions presented here. | ||
59 | Scoped IPv6 addresses are supported via | ||
60 | .Xr getaddrinfo 3 | ||
61 | and | ||
62 | .Xr getnameinfo 3 . | ||
63 | .Pp | ||
64 | The routines | ||
65 | .Fn inet_aton , | ||
66 | .Fn inet_addr , | ||
67 | and | ||
68 | .Fn inet_network | ||
69 | interpret character strings representing | ||
70 | numbers expressed in the Internet standard | ||
71 | .Dq dot | ||
72 | notation. | ||
73 | .Pp | ||
74 | The | ||
75 | .Fn inet_aton | ||
76 | routine interprets the specified character string as an Internet address, | ||
77 | placing the address into the structure provided. | ||
78 | It returns 1 if the string was successfully interpreted, | ||
79 | or 0 if the string was invalid. | ||
80 | .Pp | ||
81 | The | ||
82 | .Fn inet_addr | ||
83 | and | ||
84 | .Fn inet_network | ||
85 | functions return numbers suitable for use | ||
86 | as Internet addresses and Internet network | ||
87 | numbers, respectively. | ||
88 | Both functions return the constant | ||
89 | .Dv INADDR_NONE | ||
90 | if the specified character string is malformed. | ||
91 | .Pp | ||
92 | The routine | ||
93 | .Fn inet_ntoa | ||
94 | takes an Internet address and returns an | ||
95 | ASCII string representing the address in dot notation. | ||
96 | .Pp | ||
97 | All Internet addresses are returned in network | ||
98 | order (bytes ordered from left to right). | ||
99 | All network numbers and local address parts are | ||
100 | returned as machine format integer values. | ||
101 | .Sh INTERNET ADDRESSES (IP VERSION 4) | ||
102 | Values specified using dot notation take one of the following forms: | ||
103 | .Bd -literal -offset indent | ||
104 | a.b.c.d | ||
105 | a.b.c | ||
106 | a.b | ||
107 | a | ||
108 | .Ed | ||
109 | .Pp | ||
110 | When four parts are specified, each is interpreted | ||
111 | as a byte of data and assigned, from left to right, | ||
112 | to the four bytes of an Internet address. | ||
113 | Note that when an Internet address is viewed as a 32-bit | ||
114 | integer quantity on a system that uses little-endian | ||
115 | byte order | ||
116 | (such as the Intel 386, 486 and Pentium processors) | ||
117 | the bytes referred to above appear as | ||
118 | .Dq Li d.c.b.a . | ||
119 | That is, little-endian bytes are ordered from right to left. | ||
120 | .Pp | ||
121 | When a three part address is specified, the last | ||
122 | part is interpreted as a 16-bit quantity and placed | ||
123 | in the rightmost two bytes of the network address. | ||
124 | This makes the three part address format convenient | ||
125 | for specifying Class B network addresses as | ||
126 | .Dq Li 128.net.host . | ||
127 | .Pp | ||
128 | When a two part address is supplied, the last part | ||
129 | is interpreted as a 24-bit quantity and placed in | ||
130 | the rightmost three bytes of the network address. | ||
131 | This makes the two part address format convenient | ||
132 | for specifying Class A network addresses as | ||
133 | .Dq Li net.host . | ||
134 | .Pp | ||
135 | When only one part is given, the value is stored | ||
136 | directly in the network address without any byte | ||
137 | rearrangement. | ||
138 | .Pp | ||
139 | All numbers supplied as | ||
140 | .Dq parts | ||
141 | in a dot notation | ||
142 | may be decimal, octal, or hexadecimal, as specified | ||
143 | in the C language (i.e., a leading 0x or 0X implies | ||
144 | hexadecimal; a leading 0 implies octal; | ||
145 | otherwise, the number is interpreted as decimal). | ||
146 | .Sh SEE ALSO | ||
147 | .Xr byteorder 3 , | ||
148 | .Xr gethostbyname 3 , | ||
149 | .Xr getnetent 3 , | ||
150 | .Xr inet_lnaof 3 , | ||
151 | .Xr inet_net 3 , | ||
152 | .Xr inet_ntop 3 , | ||
153 | .Xr hosts 5 , | ||
154 | .Xr networks 5 | ||
155 | .Sh STANDARDS | ||
156 | The | ||
157 | .Nm inet_addr | ||
158 | and | ||
159 | .Nm inet_aton | ||
160 | functions conform to | ||
161 | .St -p1003.1-2008 . | ||
162 | .Sh HISTORY | ||
163 | The | ||
164 | .Nm inet_addr | ||
165 | and | ||
166 | .Nm inet_network | ||
167 | functions appeared in | ||
168 | .Bx 4.2 . | ||
169 | The | ||
170 | .Nm inet_aton | ||
171 | and | ||
172 | .Nm inet_ntoa | ||
173 | functions appeared in | ||
174 | .Bx 4.3 . | ||
175 | .Sh BUGS | ||
176 | The value | ||
177 | .Dv INADDR_NONE | ||
178 | (0xffffffff) is a valid broadcast address, but | ||
179 | .Fn inet_addr | ||
180 | cannot return that value without indicating failure. | ||
181 | Also, | ||
182 | .Fn inet_addr | ||
183 | should have been designed to return a | ||
184 | .Li struct in_addr . | ||
185 | The newer | ||
186 | .Fn inet_aton | ||
187 | function does not share these problems, and almost all existing code | ||
188 | should be modified to use | ||
189 | .Fn inet_aton | ||
190 | instead. | ||
191 | .Pp | ||
192 | The problem of host byte ordering versus network byte ordering is | ||
193 | confusing. | ||
194 | .Pp | ||
195 | The string returned by | ||
196 | .Fn inet_ntoa | ||
197 | resides in a static memory area. | ||
diff --git a/src/lib/libc/net/inet_lnaof.3 b/src/lib/libc/net/inet_lnaof.3 new file mode 100644 index 0000000000..f3f03514af --- /dev/null +++ b/src/lib/libc/net/inet_lnaof.3 | |||
@@ -0,0 +1,90 @@ | |||
1 | .\" $OpenBSD: inet_lnaof.3,v 1.1 2014/04/19 11:18:01 guenther Exp $ | ||
2 | .\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1983, 1990, 1991, 1993 | ||
5 | .\" The Regents of the University of California. All rights reserved. | ||
6 | .\" | ||
7 | .\" Redistribution and use in source and binary forms, with or without | ||
8 | .\" modification, are permitted provided that the following conditions | ||
9 | .\" are met: | ||
10 | .\" 1. Redistributions of source code must retain the above copyright | ||
11 | .\" notice, this list of conditions and the following disclaimer. | ||
12 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
13 | .\" notice, this list of conditions and the following disclaimer in the | ||
14 | .\" documentation and/or other materials provided with the distribution. | ||
15 | .\" 3. Neither the name of the University nor the names of its contributors | ||
16 | .\" may be used to endorse or promote products derived from this software | ||
17 | .\" without specific prior written permission. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | .\" SUCH DAMAGE. | ||
30 | .\" | ||
31 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 | ||
32 | .\" | ||
33 | .Dd $Mdocdate: April 19 2014 $ | ||
34 | .Dt INET_LNAOF 3 | ||
35 | .Os | ||
36 | .Sh NAME | ||
37 | .Nm inet_makeaddr , | ||
38 | .Nm inet_netof , | ||
39 | .Nm inet_lnaof | ||
40 | .Nd routines for manipulating classful Internet Protocol version 4 (IPv4) addresses | ||
41 | .Sh SYNOPSIS | ||
42 | .In arpa/inet.h | ||
43 | .Ft struct in_addr | ||
44 | .Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" | ||
45 | .Ft in_addr_t | ||
46 | .Fn inet_netof "struct in_addr in" | ||
47 | .Ft in_addr_t | ||
48 | .Fn inet_lnaof "struct in_addr in" | ||
49 | .Sh DESCRIPTION | ||
50 | As originally designed, | ||
51 | IP version 4 split each address into a network part and local network | ||
52 | address part, encoding that split into the address itself. | ||
53 | It is frequency-encoded; | ||
54 | the most-significant bit is clear in Class A addresses, | ||
55 | in which the high-order 8 bits are the network number. | ||
56 | Class B addresses use the high-order 16 bits as the network field, | ||
57 | and Class C addresses have a 24-bit network part. | ||
58 | .Pp | ||
59 | The routine | ||
60 | .Fn inet_makeaddr | ||
61 | takes an Internet network number and a local | ||
62 | network address and constructs an Internet address | ||
63 | from it. | ||
64 | .Pp | ||
65 | The routines | ||
66 | .Fn inet_netof | ||
67 | and | ||
68 | .Fn inet_lnaof | ||
69 | break apart Internet host addresses, returning | ||
70 | the network number and local network address part, | ||
71 | respectively. | ||
72 | .Pp | ||
73 | All Internet addresses are returned in network | ||
74 | order (bytes ordered from left to right). | ||
75 | All network numbers and local address parts are | ||
76 | returned as machine format integer values. | ||
77 | .Sh SEE ALSO | ||
78 | .Xr getnetent 3 , | ||
79 | .Xr inet_addr 3 , | ||
80 | .Xr inet_net 3 , | ||
81 | .Xr hosts 5 , | ||
82 | .Xr networks 5 | ||
83 | .Sh HISTORY | ||
84 | The | ||
85 | .Nm inet_makeaddr , | ||
86 | .Nm inet_lnaof , | ||
87 | and | ||
88 | .Nm inet_netof | ||
89 | functions appeared in | ||
90 | .Bx 4.2 . | ||
diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet_ntop.3 index e56ca0a59a..a5bd5076fe 100644 --- a/src/lib/libc/net/inet.3 +++ b/src/lib/libc/net/inet_ntop.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: inet.3,v 1.26 2013/06/05 03:39:23 tedu Exp $ | 1 | .\" $OpenBSD: inet_ntop.3,v 1.1 2014/04/19 11:18:01 guenther Exp $ |
2 | .\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ | 2 | .\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ |
3 | .\" | 3 | .\" |
4 | .\" Copyright (c) 1983, 1990, 1991, 1993 | 4 | .\" Copyright (c) 1983, 1990, 1991, 1993 |
@@ -30,72 +30,20 @@ | |||
30 | .\" | 30 | .\" |
31 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 | 31 | .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 |
32 | .\" | 32 | .\" |
33 | .Dd $Mdocdate: June 5 2013 $ | 33 | .Dd $Mdocdate: April 19 2014 $ |
34 | .Dt INET 3 | 34 | .Dt INET_NTOP 3 |
35 | .Os | 35 | .Os |
36 | .Sh NAME | 36 | .Sh NAME |
37 | .Nm inet_aton , | ||
38 | .Nm inet_addr , | ||
39 | .Nm inet_network , | ||
40 | .Nm inet_pton , | ||
41 | .Nm inet_ntop , | 37 | .Nm inet_ntop , |
42 | .Nm inet_ntoa , | 38 | .Nm inet_pton |
43 | .Nm inet_makeaddr , | 39 | .Nd convert Internet addresses between presentation and network formats |
44 | .Nm inet_netof , | ||
45 | .Nm inet_lnaof | ||
46 | .Nd Internet address manipulation routines | ||
47 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
48 | .In sys/types.h | ||
49 | .In sys/socket.h | ||
50 | .In netinet/in.h | ||
51 | .In arpa/inet.h | 41 | .In arpa/inet.h |
52 | .Ft int | ||
53 | .Fn inet_aton "const char *cp" "struct in_addr *addr" | ||
54 | .Ft in_addr_t | ||
55 | .Fn inet_addr "const char *cp" | ||
56 | .Ft in_addr_t | ||
57 | .Fn inet_network "const char *cp" | ||
58 | .Ft int | ||
59 | .Fn inet_pton "int af" "const char *src" "void *dst" | ||
60 | .Ft const char * | 42 | .Ft const char * |
61 | .Fn inet_ntop "int af" "const void *src" "char *dst" "socklen_t size" | 43 | .Fn inet_ntop "int af" "const void * restrict src" "char * restrict dst" "socklen_t size" |
62 | .Ft char * | 44 | .Ft int |
63 | .Fn inet_ntoa "struct in_addr in" | 45 | .Fn inet_pton "int af" "const char * restrict src" "void * restrict dst" |
64 | .Ft struct in_addr | ||
65 | .Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" | ||
66 | .Ft in_addr_t | ||
67 | .Fn inet_netof "struct in_addr in" | ||
68 | .Ft in_addr_t | ||
69 | .Fn inet_lnaof "struct in_addr in" | ||
70 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
71 | The routines | ||
72 | .Fn inet_aton , | ||
73 | .Fn inet_addr , | ||
74 | and | ||
75 | .Fn inet_network | ||
76 | interpret character strings representing | ||
77 | numbers expressed in the Internet standard | ||
78 | .Dq dot | ||
79 | notation. | ||
80 | .Pp | ||
81 | The | ||
82 | .Fn inet_aton | ||
83 | routine interprets the specified character string as an Internet address, | ||
84 | placing the address into the structure provided. | ||
85 | It returns 1 if the string was successfully interpreted, | ||
86 | or 0 if the string was invalid. | ||
87 | .Pp | ||
88 | The | ||
89 | .Fn inet_addr | ||
90 | and | ||
91 | .Fn inet_network | ||
92 | functions return numbers suitable for use | ||
93 | as Internet addresses and Internet network | ||
94 | numbers, respectively. | ||
95 | Both functions return the constant | ||
96 | .Dv INADDR_NONE | ||
97 | if the specified character string is malformed. | ||
98 | .Pp | ||
99 | The | 47 | The |
100 | .Fn inet_pton | 48 | .Fn inet_pton |
101 | function converts a presentation format address (that is, printable form | 49 | function converts a presentation format address (that is, printable form |
@@ -114,10 +62,7 @@ and | |||
114 | .Pp | 62 | .Pp |
115 | The function | 63 | The function |
116 | .Fn inet_ntop | 64 | .Fn inet_ntop |
117 | converts an address from network format (usually a | 65 | converts an address from network format to presentation format. |
118 | .Li struct in_addr | ||
119 | or some other binary form, in network byte order) to presentation format | ||
120 | (suitable for external display purposes). | ||
121 | It returns | 66 | It returns |
122 | .Dv NULL | 67 | .Dv NULL |
123 | if a system | 68 | if a system |
@@ -125,74 +70,15 @@ error occurs (in which case, | |||
125 | .Va errno | 70 | .Va errno |
126 | will have been set), or it returns a pointer to the destination string. | 71 | will have been set), or it returns a pointer to the destination string. |
127 | .Pp | 72 | .Pp |
128 | The routine | ||
129 | .Fn inet_ntoa | ||
130 | takes an Internet address and returns an | ||
131 | ASCII string representing the address in dot notation. | ||
132 | .Pp | ||
133 | The routine | ||
134 | .Fn inet_makeaddr | ||
135 | takes an Internet network number and a local | ||
136 | network address and constructs an Internet address | ||
137 | from it. | ||
138 | .Pp | ||
139 | The routines | ||
140 | .Fn inet_netof | ||
141 | and | ||
142 | .Fn inet_lnaof | ||
143 | break apart Internet host addresses, returning | ||
144 | the network number and local network address part, | ||
145 | respectively. | ||
146 | .Pp | ||
147 | All Internet addresses are returned in network | 73 | All Internet addresses are returned in network |
148 | order (bytes ordered from left to right). | 74 | order (bytes ordered from left to right). |
149 | All network numbers and local address parts are | ||
150 | returned as machine format integer values. | ||
151 | .Sh INTERNET ADDRESSES (IP VERSION 4) | 75 | .Sh INTERNET ADDRESSES (IP VERSION 4) |
152 | Values specified using dot notation take one of the following forms: | 76 | Values must be specified using the standard dot notation: |
153 | .Bd -literal -offset indent | 77 | .Bd -literal -offset indent |
154 | a.b.c.d | 78 | a.b.c.d |
155 | a.b.c | ||
156 | a.b | ||
157 | a | ||
158 | .Ed | 79 | .Ed |
159 | .Pp | 80 | .Pp |
160 | When four parts are specified, each is interpreted | 81 | All four parts must be decimal numbers between 0 and 255, inclusive. |
161 | as a byte of data and assigned, from left to right, | ||
162 | to the four bytes of an Internet address. | ||
163 | Note that when an Internet address is viewed as a 32-bit | ||
164 | integer quantity on a system that uses little-endian | ||
165 | byte order | ||
166 | (such as the Intel 386, 486 and Pentium processors) | ||
167 | the bytes referred to above appear as | ||
168 | .Dq Li d.c.b.a . | ||
169 | That is, little-endian bytes are ordered from right to left. | ||
170 | .Pp | ||
171 | When a three part address is specified, the last | ||
172 | part is interpreted as a 16-bit quantity and placed | ||
173 | in the rightmost two bytes of the network address. | ||
174 | This makes the three part address format convenient | ||
175 | for specifying Class B network addresses as | ||
176 | .Dq Li 128.net.host . | ||
177 | .Pp | ||
178 | When a two part address is supplied, the last part | ||
179 | is interpreted as a 24-bit quantity and placed in | ||
180 | the rightmost three bytes of the network address. | ||
181 | This makes the two part address format convenient | ||
182 | for specifying Class A network addresses as | ||
183 | .Dq Li net.host . | ||
184 | .Pp | ||
185 | When only one part is given, the value is stored | ||
186 | directly in the network address without any byte | ||
187 | rearrangement. | ||
188 | .Pp | ||
189 | All numbers supplied as | ||
190 | .Dq parts | ||
191 | in a dot notation | ||
192 | may be decimal, octal, or hexadecimal, as specified | ||
193 | in the C language (i.e., a leading 0x or 0X implies | ||
194 | hexadecimal; a leading 0 implies octal; | ||
195 | otherwise, the number is interpreted as decimal). | ||
196 | .Sh INTERNET ADDRESSES (IP VERSION 6) | 82 | .Sh INTERNET ADDRESSES (IP VERSION 6) |
197 | In order to support scoped IPv6 addresses, | 83 | In order to support scoped IPv6 addresses, |
198 | .Xr getaddrinfo 3 | 84 | .Xr getaddrinfo 3 |
@@ -271,23 +157,30 @@ or in compressed form: | |||
271 | .Ed | 157 | .Ed |
272 | .El | 158 | .El |
273 | .Sh SEE ALSO | 159 | .Sh SEE ALSO |
274 | .Xr byteorder 3 , | ||
275 | .Xr gethostbyname 3 , | 160 | .Xr gethostbyname 3 , |
276 | .Xr getnetent 3 , | 161 | .Xr inet_addr 3 , |
277 | .Xr inet_net 3 , | 162 | .Xr inet_net 3 , |
278 | .Xr hosts 5 , | 163 | .Xr hosts 5 |
279 | .Xr networks 5 | ||
280 | .Sh STANDARDS | 164 | .Sh STANDARDS |
281 | The | 165 | The |
282 | .Nm inet_ntop | 166 | .Nm inet_ntop |
283 | and | 167 | and |
284 | .Nm inet_pton | 168 | .Nm inet_pton |
285 | functions conform to the IETF IPv6 BSD API and address formatting | 169 | functions conform to the IETF IPv6 BSD API and address formatting |
286 | specifications. | 170 | specifications, as well as |
171 | .St -p1003.1-2008 . | ||
172 | .Sh HISTORY | ||
173 | The | ||
174 | .Nm inet_pton | ||
175 | and | ||
176 | .Nm inet_ntop | ||
177 | functions appeared in BIND 4.9.4. | ||
178 | .Sh CAVEATS | ||
287 | Note that | 179 | Note that |
288 | .Nm inet_pton | 180 | .Nm inet_pton |
289 | does not accept 1-, 2-, or 3-part dotted addresses; all four parts | 181 | does not accept 1-, 2-, or 3-part dotted addresses; |
290 | must be specified. | 182 | all four parts must be specified and must be in decimal |
183 | (and not octal or hexadecimal). | ||
291 | This is a narrower input set than that accepted by | 184 | This is a narrower input set than that accepted by |
292 | .Nm inet_aton . | 185 | .Nm inet_aton . |
293 | .Pp | 186 | .Pp |
@@ -309,47 +202,3 @@ This is a narrower input set than that accepted by | |||
309 | .%R RFC 4291 | 202 | .%R RFC 4291 |
310 | .%T IP Version 6 Addressing Architecture | 203 | .%T IP Version 6 Addressing Architecture |
311 | .Re | 204 | .Re |
312 | .Sh HISTORY | ||
313 | The | ||
314 | .Nm inet_addr , | ||
315 | .Nm inet_network , | ||
316 | .Nm inet_makeaddr , | ||
317 | .Nm inet_lnaof , | ||
318 | and | ||
319 | .Nm inet_netof | ||
320 | functions appeared in | ||
321 | .Bx 4.2 . | ||
322 | The | ||
323 | .Nm inet_aton | ||
324 | and | ||
325 | .Nm inet_ntoa | ||
326 | functions appeared in | ||
327 | .Bx 4.3 . | ||
328 | The | ||
329 | .Nm inet_pton | ||
330 | and | ||
331 | .Nm inet_ntop | ||
332 | functions appeared in BIND 4.9.4. | ||
333 | .Sh BUGS | ||
334 | The value | ||
335 | .Dv INADDR_NONE | ||
336 | (0xffffffff) is a valid broadcast address, but | ||
337 | .Fn inet_addr | ||
338 | cannot return that value without indicating failure. | ||
339 | Also, | ||
340 | .Fn inet_addr | ||
341 | should have been designed to return a | ||
342 | .Li struct in_addr . | ||
343 | The newer | ||
344 | .Fn inet_aton | ||
345 | function does not share these problems, and almost all existing code | ||
346 | should be modified to use | ||
347 | .Fn inet_aton | ||
348 | instead. | ||
349 | .Pp | ||
350 | The problem of host byte ordering versus network byte ordering is | ||
351 | confusing. | ||
352 | .Pp | ||
353 | The string returned by | ||
354 | .Fn inet_ntoa | ||
355 | resides in a static memory area. | ||