]> git.saurik.com Git - apple/libc.git/blame - net/FreeBSD/inet_net.3
Libc-1158.50.2.tar.gz
[apple/libc.git] / net / FreeBSD / inet_net.3
CommitLineData
5b2abdfb
A
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.
5b2abdfb
A
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.\"
b5d655f7 33.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.4 2007/01/09 00:28:02 imp Exp $
5b2abdfb 34.\"
b5d655f7 35.Dd February 26, 2006
5b2abdfb
A
36.Dt INET_NET 3
37.Os
38.Sh NAME
39.Nm inet_net_ntop ,
40.Nm inet_net_pton
41.Nd Internet network number manipulation routines
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
5b2abdfb
A
45.In arpa/inet.h
46.Ft char *
47.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size"
48.Ft int
49.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size"
50.Sh DESCRIPTION
51The
52.Fn inet_net_ntop
53function converts an Internet network number from network format (usually a
54.Vt "struct in_addr"
55or some other binary form, in network byte order) to CIDR presentation format
56(suitable for external display purposes).
9385eb3d 57The
5b2abdfb 58.Fa bits
9385eb3d 59argument
5b2abdfb
A
60is the number of bits in
61.Fa src
62that are the network number.
63It returns
64.Dv NULL
65if a system error occurs (in which case,
66.Va errno
67will have been set), or it returns a pointer to the destination string.
68.Pp
69The
70.Fn inet_net_pton
71function converts a presentation format Internet network number (that is,
72printable form as held in a character string) to network format (usually a
73.Vt "struct in_addr"
74or some other internal binary representation, in network byte order).
75It returns the number of bits (either computed based on the class, or
76specified with /CIDR), or \-1 if a failure occurred
77(in which case
78.Va errno
79will have been set.
80It will be set to
81.Er ENOENT
82if the Internet network number was not valid).
83.Pp
b5d655f7 84The currently supported values for
5b2abdfb 85.Fa af
b5d655f7
A
86are
87.Dv AF_INET
88and
89.Dv AF_INET6 .
9385eb3d 90The
5b2abdfb 91.Fa size
9385eb3d 92argument
5b2abdfb
A
93is the size of the result buffer
94.Fa dst .
95.Pp
96.Sh NETWORK NUMBERS (IP VERSION 4)
97Internet network numbers may be specified in one of the following forms:
98.Bd -literal -offset indent
99a.b.c.d/bits
100a.b.c.d
101a.b.c
102a.b
103a
104.Ed
105.Pp
106When four parts are specified, each is interpreted
107as a byte of data and assigned, from left to right,
108to the four bytes of an Internet network number.
109Note
110that when an Internet network number is viewed as a 32-bit
111integer quantity on a system that uses little-endian
112byte order (such as the
113.Tn Intel 386 , 486 ,
114and
115.Tn Pentium
116processors) the bytes referred to above appear as
117.Dq Li d.c.b.a .
118That is, little-endian bytes are ordered from right to left.
119.Pp
120When a three part number is specified, the last
121part is interpreted as a 16-bit quantity and placed
122in the rightmost two bytes of the Internet network number.
123This makes the three part number format convenient
124for specifying Class B network numbers as
125.Dq Li 128.net.host .
126.Pp
127When a two part number is supplied, the last part
128is interpreted as a 24-bit quantity and placed in
129the rightmost three bytes of the Internet network number.
130This makes the two part number format convenient
131for specifying Class A network numbers as
132.Dq Li net.host .
133.Pp
134When only one part is given, the value is stored
135directly in the Internet network number without any byte
136rearrangement.
137.Pp
138All numbers supplied as
139.Dq parts
140in a
141.Ql \&.
142notation
143may be decimal, octal, or hexadecimal, as specified
144in the C language (i.e., a leading 0x or 0X implies
145hexadecimal; otherwise, a leading 0 implies octal;
146otherwise, the number is interpreted as decimal).
b5d655f7
A
147.\"
148.\" .Sh NETWORK NUMBERS (IP VERSION 6)
149.\" XXX - document this!
150.\"
ad3c9f2a
A
151.Sh LEGACY SYNOPSIS
152.Fd #include <sys/types.h>
153.Fd #include <sys/socket.h>
154.Fd #include <netinet/in.h>
155.Fd #include <arpa/inet.h>
156.Pp
157These include files were necessary for all functions.
5b2abdfb
A
158.Sh SEE ALSO
159.Xr byteorder 3 ,
160.Xr inet 3 ,
161.Xr networks 5
162.Sh HISTORY
163The
164.Fn inet_net_ntop
165and
166.Fn inet_net_pton
167functions appeared in BIND 4.9.4.