summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/inet_net.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/inet_net.3')
-rw-r--r--src/lib/libc/net/inet_net.3181
1 files changed, 181 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..c14fa52e38
--- /dev/null
+++ b/src/lib/libc/net/inet_net.3
@@ -0,0 +1,181 @@
1.\" $OpenBSD: inet_net.3,v 1.10 2003/05/01 19:17:37 jmc 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/socket.h>
47.Fd #include <netinet/in.h>
48.Fd #include <arpa/inet.h>
49.Ft char *
50.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size"
51.Ft int
52.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size"
53.Sh DESCRIPTION
54The
55.Fn inet_net_ntop
56function converts an Internet network number from network format (usually a
57.Li struct in_addr
58or some other binary form, in network byte order) to CIDR presentation format
59(suitable for external display purposes).
60.Fa bits
61is the number of bits in
62.Fa src
63that are the network number.
64It returns
65.Dv NULL
66if a system error occurs (in which case,
67.Va errno
68will have been set), or it returns a pointer to the destination string.
69.Pp
70The
71.Fn inet_net_pton
72function converts a presentation format Internet network number (that is,
73printable form as held in a character string) to network format (usually a
74.Li struct in_addr
75or some other internal binary representation, in network byte order).
76It returns the number of bits (either computed based on the class, or
77specified with /CIDR), or \-1 if a failure occurred
78(in which case
79.Va errno
80will have been set.
81It will be set to
82.Er ENOENT
83if the Internet network number was not valid).
84.Pp
85Caution:
86The
87.Fa dst
88field should be zeroed before calling
89.Fn inet_net_pton
90as the function will only fill the number of bytes necessary to
91encode the network number in network byte order.
92.Pp
93The only value for
94.Fa af
95currently supported is
96.Dv AF_INET .
97.Fa size
98is the size of the result buffer
99.Fa dst .
100.Sh NETWORK NUMBERS (IP VERSION 4)
101The external representation of Internet network numbers may be specified in
102one of the following forms:
103.Bd -literal -offset indent
104a
105a.b
106a.b.c
107a.b.c.d
108.Ed
109.Pp
110Any of the above four forms may have
111.Dq Li /bits
112appended where
113.Dq Li bits
114is in the range
115.Li 0-32
116and is used to explicitly specify the number of bits in the network address.
117When
118.Dq Li /bits
119is not specified the number of bits in the network address is calculated
120as the larger of the number of bits in the class to which the address
121belongs and the number of bits provided rounded up modulo 8.
122Examples:
123.Bl -tag -width 10.1.2.3/24
124.It Li 10
125an 8 bit network number (class A), value
126.Li 10.0.0.0 .
127.It Li 192
128a 24 bit network number (class C), value
129.Li 192.0.0.0 .
130.It Li 10.10
131a 16 bit network number, value
132.Li 10.10.0.0 .
133.It Li 10.1.2
134a 24 bit network number, value
135.Li 10.1.2.0 .
136.It Li 10.1.2.3
137a 32 bit network number, value
138.Li 10.1.2.3 .
139.It Li 10.1.2.3/24
140a 24 bit network number (explicit), value
141.Li 10.1.2.3 .
142.El
143.Pp
144Note that when the number of bits is specified using
145.Dq Li /bits
146notation, the value of the address still includes all bits suplied
147in the external representation, even those bits which are the host
148part of an internet address.
149Also, unlike
150.Xr inet_pton 3
151where the external representation is assumed to be an internet address, the
152external representation for
153.Fn inet_net_pton
154is assumed to be a network address.
155Thus
156.Dq Li 10.1
157is assumed to be
158.Dq Li 10.1.0.0
159not
160.Dq Li 10.0.0.1
161.Pp
162All numbers supplied as
163.Dq parts
164in a
165.Ql \&.
166notation
167may be decimal, octal, or hexadecimal, as specified
168in the C language (i.e., a leading 0x or 0X implies
169hexadecimal; otherwise, a leading 0 implies octal;
170otherwise, the number is interpreted as decimal).
171.Sh SEE ALSO
172.Xr byteorder 3 ,
173.Xr inet 3 ,
174.Xr inet_pton 3 ,
175.Xr networks 5
176.Sh HISTORY
177The
178.Nm inet_net_ntop
179and
180.Nm inet_net_pton
181functions first appeared in BIND 4.9.4.