Sync lib/net with FreeBSD:
[dragonfly.git] / lib / libc / net / inet_net.3
1 .\"     $NetBSD: inet_net.3,v 1.4 1999/03/22 19:44:52 garbled Exp $
2 .\"
3 .\" Copyright (c) 1997 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Luke Mewburn.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
18 .\"    contributors may be used to endorse or promote products derived
19 .\"    from this software without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 .\" POSSIBILITY OF SUCH DAMAGE.
32 .\"
33 .\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.4 2007/01/09 00:28:02 imp Exp $
34 .\" $DragonFly: src/lib/libc/net/inet_net.3,v 1.3 2006/03/26 22:56:56 swildner Exp $
35 .\"
36 .Dd February 26, 2006
37 .Dt INET_NET 3
38 .Os
39 .Sh NAME
40 .Nm inet_net_ntop ,
41 .Nm inet_net_pton
42 .Nd Internet network number manipulation routines
43 .Sh LIBRARY
44 .Lb libc
45 .Sh SYNOPSIS
46 .In sys/types.h
47 .In sys/socket.h
48 .In netinet/in.h
49 .In 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 .Vt "struct in_addr"
59 or some other binary form, in network byte order) to CIDR presentation format
60 (suitable for external display purposes).
61 The
62 .Fa bits
63 argument
64 is the number of bits in
65 .Fa src
66 that are the network number.
67 It returns
68 .Dv NULL
69 if a system error occurs (in which case,
70 .Va errno
71 will have been set), or it returns a pointer to the destination string.
72 .Pp
73 The
74 .Fn inet_net_pton
75 function converts a presentation format Internet network number (that is,
76 printable form as held in a character string) to network format (usually a
77 .Vt "struct in_addr"
78 or some other internal binary representation, in network byte order).
79 It returns the number of bits (either computed based on the class, or
80 specified with /CIDR), or \-1 if a failure occurred
81 (in which case
82 .Va errno
83 will have been set.
84 It will be set to
85 .Er ENOENT
86 if the Internet network number was not valid).
87 .Pp
88 The currently supported values for
89 .Fa af
90 are
91 .Dv AF_INET
92 and
93 .Dv AF_INET6 .
94 The
95 .Fa size
96 argument
97 is the size of the result buffer
98 .Fa dst .
99 .Sh NETWORK NUMBERS (IP VERSION 4)
100 Internet network numbers may be specified in one of the following forms:
101 .Bd -literal -offset indent
102 a.b.c.d/bits
103 a.b.c.d
104 a.b.c
105 a.b
106 a
107 .Ed
108 .Pp
109 When four parts are specified, each is interpreted
110 as a byte of data and assigned, from left to right,
111 to the four bytes of an Internet network number.
112 Note
113 that when an Internet network number is viewed as a 32-bit
114 integer quantity on a system that uses little-endian
115 byte order (such as the
116 .Tn Intel 386 , 486 ,
117 and
118 .Tn Pentium
119 processors) the bytes referred to above appear as
120 .Dq Li d.c.b.a .
121 That is, little-endian bytes are ordered from right to left.
122 .Pp
123 When a three part number is specified, the last
124 part is interpreted as a 16-bit quantity and placed
125 in the rightmost two bytes of the Internet network number.
126 This makes the three part number format convenient
127 for specifying Class B network numbers as
128 .Dq Li 128.net.host .
129 .Pp
130 When a two part number is supplied, the last part
131 is interpreted as a 24-bit quantity and placed in
132 the rightmost three bytes of the Internet network number.
133 This makes the two part number format convenient
134 for specifying Class A network numbers as
135 .Dq Li net.host .
136 .Pp
137 When only one part is given, the value is stored
138 directly in the Internet network number without any byte
139 rearrangement.
140 .Pp
141 All numbers supplied as
142 .Dq parts
143 in a
144 .Ql \&.
145 notation
146 may be decimal, octal, or hexadecimal, as specified
147 in the C language (i.e., a leading 0x or 0X implies
148 hexadecimal; otherwise, a leading 0 implies octal;
149 otherwise, the number is interpreted as decimal).
150 .\"
151 .\" .Sh NETWORK NUMBERS (IP VERSION 6)
152 .\" XXX - document this!
153 .\"
154 .Sh SEE ALSO
155 .Xr byteorder 3 ,
156 .Xr inet 3 ,
157 .Xr networks 5
158 .Sh HISTORY
159 The
160 .Fn inet_net_ntop
161 and
162 .Fn inet_net_pton
163 functions appeared in BIND 4.9.4.