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