diff options
Diffstat (limited to 'src/lib/libc/net/inet_net.3')
-rw-r--r-- | src/lib/libc/net/inet_net.3 | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/src/lib/libc/net/inet_net.3 b/src/lib/libc/net/inet_net.3 new file mode 100644 index 0000000000..a763bb12a5 --- /dev/null +++ b/src/lib/libc/net/inet_net.3 | |||
@@ -0,0 +1,183 @@ | |||
1 | .\" $OpenBSD: inet_net.3,v 1.12 2005/12/30 20:45:59 claudio Exp $ | ||
2 | .\" $NetBSD: inet_net.3,v 1.1 1997/06/18 02:25:27 lukem Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1997 The NetBSD Foundation, Inc. | ||
5 | .\" All rights reserved. | ||
6 | .\" | ||
7 | .\" This code is derived from software contributed to The NetBSD Foundation | ||
8 | .\" by Luke Mewburn. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" 3. All advertising materials mentioning features or use of this software | ||
19 | .\" must display the following acknowledgement: | ||
20 | .\" This product includes software developed by the NetBSD | ||
21 | .\" Foundation, Inc. and its contributors. | ||
22 | .\" 4. Neither the name of The NetBSD Foundation nor the names of its | ||
23 | .\" contributors may be used to endorse or promote products derived | ||
24 | .\" from this software without specific prior written permission. | ||
25 | .\" | ||
26 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
27 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
28 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
29 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE | ||
30 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
31 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
32 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
33 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
34 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
35 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
36 | .\" POSSIBILITY OF SUCH DAMAGE. | ||
37 | .\" | ||
38 | .Dd June 18, 1997 | ||
39 | .Dt INET_NET 3 | ||
40 | .Os | ||
41 | .Sh NAME | ||
42 | .Nm inet_net_ntop , | ||
43 | .Nm inet_net_pton | ||
44 | .Nd Internet network number manipulation routines | ||
45 | .Sh SYNOPSIS | ||
46 | .Fd #include <sys/types.h> | ||
47 | .Fd #include <sys/socket.h> | ||
48 | .Fd #include <netinet/in.h> | ||
49 | .Fd #include <arpa/inet.h> | ||
50 | .Ft char * | ||
51 | .Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" | ||
52 | .Ft int | ||
53 | .Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" | ||
54 | .Sh DESCRIPTION | ||
55 | The | ||
56 | .Fn inet_net_ntop | ||
57 | function converts an Internet network number from network format (usually a | ||
58 | .Li struct in_addr | ||
59 | or some other binary form, in network byte order) to CIDR presentation format | ||
60 | (suitable for external display purposes). | ||
61 | .Fa bits | ||
62 | is the number of bits in | ||
63 | .Fa src | ||
64 | that are the network number. | ||
65 | It returns | ||
66 | .Dv NULL | ||
67 | if a system error occurs (in which case, | ||
68 | .Va errno | ||
69 | will have been set), or it returns a pointer to the destination string. | ||
70 | .Pp | ||
71 | The | ||
72 | .Fn inet_net_pton | ||
73 | function converts a presentation format Internet network number (that is, | ||
74 | printable form as held in a character string) to network format (usually a | ||
75 | .Li struct in_addr | ||
76 | or some other internal binary representation, in network byte order). | ||
77 | It returns the number of bits (either computed based on the class, or | ||
78 | specified with /CIDR), or \-1 if a failure occurred | ||
79 | (in which case | ||
80 | .Va errno | ||
81 | will have been set. | ||
82 | It will be set to | ||
83 | .Er ENOENT | ||
84 | if the Internet network number was not valid). | ||
85 | .Pp | ||
86 | Caution: | ||
87 | The | ||
88 | .Fa dst | ||
89 | field should be zeroed before calling | ||
90 | .Fn inet_net_pton | ||
91 | as the function will only fill the number of bytes necessary to | ||
92 | encode the network number in network byte order. | ||
93 | .Pp | ||
94 | The only value for | ||
95 | .Fa af | ||
96 | currently supported is | ||
97 | .Dv AF_INET . | ||
98 | .Fa size | ||
99 | is the size of the result buffer | ||
100 | .Fa dst . | ||
101 | .Sh NETWORK NUMBERS (IP VERSION 4) | ||
102 | The external representation of Internet network numbers may be specified in | ||
103 | one of the following forms: | ||
104 | .Bd -literal -offset indent | ||
105 | a | ||
106 | a.b | ||
107 | a.b.c | ||
108 | a.b.c.d | ||
109 | .Ed | ||
110 | .Pp | ||
111 | Any of the above four forms may have | ||
112 | .Dq Li /bits | ||
113 | appended where | ||
114 | .Dq Li bits | ||
115 | is in the range | ||
116 | .Li 0-32 | ||
117 | and is used to explicitly specify the number of bits in the network address. | ||
118 | When | ||
119 | .Dq Li /bits | ||
120 | is not specified the number of bits in the network address is calculated | ||
121 | as the larger of the number of bits in the class to which the address | ||
122 | belongs and the number of bits provided rounded up modulo 8. | ||
123 | Examples: | ||
124 | .Pp | ||
125 | .Bl -tag -width 10.1.2.3/24 -offset indent -compact | ||
126 | .It Li 10 | ||
127 | an 8-bit network number (class A), value | ||
128 | .Li 10.0.0.0 . | ||
129 | .It Li 192 | ||
130 | a 24-bit network number (class C), value | ||
131 | .Li 192.0.0.0 . | ||
132 | .It Li 10.10 | ||
133 | a 16-bit network number, value | ||
134 | .Li 10.10.0.0 . | ||
135 | .It Li 10.1.2 | ||
136 | a 24-bit network number, value | ||
137 | .Li 10.1.2.0 . | ||
138 | .It Li 10.1.2.3 | ||
139 | a 32-bit network number, value | ||
140 | .Li 10.1.2.3 . | ||
141 | .It Li 10.1.2.3/24 | ||
142 | a 24-bit network number (explicit), value | ||
143 | .Li 10.1.2.3 . | ||
144 | .El | ||
145 | .Pp | ||
146 | Note that when the number of bits is specified using | ||
147 | .Dq Li /bits | ||
148 | notation, the value of the address still includes all bits supplied | ||
149 | in the external representation, even those bits which are the host | ||
150 | part of an Internet address. | ||
151 | Also, unlike | ||
152 | .Xr inet_pton 3 | ||
153 | where the external representation is assumed to be a host address, the | ||
154 | external representation for | ||
155 | .Fn inet_net_pton | ||
156 | is assumed to be a network address. | ||
157 | Thus | ||
158 | .Dq Li 10.1 | ||
159 | is assumed to be | ||
160 | .Dq Li 10.1.0.0 | ||
161 | not | ||
162 | .Dq Li 10.0.0.1 | ||
163 | .Pp | ||
164 | All numbers supplied as | ||
165 | .Dq parts | ||
166 | in a | ||
167 | .Ql \&. | ||
168 | notation | ||
169 | may be decimal, octal, or hexadecimal, as specified | ||
170 | in the C language (i.e., a leading 0x or 0X implies | ||
171 | hexadecimal; otherwise, a leading 0 implies octal; | ||
172 | otherwise, the number is interpreted as decimal). | ||
173 | .Sh SEE ALSO | ||
174 | .Xr byteorder 3 , | ||
175 | .Xr inet 3 , | ||
176 | .Xr inet_pton 3 , | ||
177 | .Xr networks 5 | ||
178 | .Sh HISTORY | ||
179 | The | ||
180 | .Nm inet_net_ntop | ||
181 | and | ||
182 | .Nm inet_net_pton | ||
183 | functions first appeared in BIND 4.9.4. | ||