xref: /freebsd/lib/libc/net/inet.3 (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
1.\" Copyright (c) 1983, 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)inet.3	8.1 (Berkeley) 6/4/93
33.\"
34.Dd June 4, 1993
35.Dt INET 3
36.Os BSD 4.2
37.Sh NAME
38.Nm inet_aton ,
39.Nm inet_addr ,
40.Nm inet_network ,
41.Nm inet_ntoa ,
42.Nm inet_makeaddr ,
43.Nm inet_lnaof ,
44.Nm inet_netof
45.Nd Internet address manipulation routines
46.Sh SYNOPSIS
47.Fd #include <sys/socket.h>
48.Fd #include <netinet/in.h>
49.Fd #include <arpa/inet.h>
50.Ft int
51.Fn inet_aton "char *cp" "struct in_addr *pin"
52.Ft unsigned long
53.Fn inet_addr "char *cp"
54.Ft unsigned long
55.Fn inet_network "char *cp"
56.Ft char *
57.Fn inet_ntoa "struct in_addr in"
58.Ft struct in_addr
59.Fn inet_makeaddr "int net" "int lna"
60.Ft unsigned long
61.Fn inet_lnaof "struct in_addr in"
62.Ft unsigned long
63.Fn inet_netof "struct in_addr in"
64.Sh DESCRIPTION
65The routines
66.Fn inet_aton ,
67.Fn inet_addr
68and
69.Fn inet_network
70interpret character strings representing
71numbers expressed in the Internet standard
72.Ql \&.
73notation.
74The
75.Fn inet_aton
76routine interprets the specified character string as an Internet address,
77placing the address into the structure provided.
78It returns 1 if the string was successfully interpreted,
79or 0 if the string is invalid.
80The
81.Fn inet_addr
82and
83.Fn inet_network
84functions return numbers suitable for use
85as Internet addresses and Internet network
86numbers, respectively.
87The routine
88.Fn inet_ntoa
89takes an Internet address and returns an
90.Tn ASCII
91string representing the address in
92.Ql \&.
93notation.  The routine
94.Fn inet_makeaddr
95takes an Internet network number and a local
96network address and constructs an Internet address
97from it.  The routines
98.Fn inet_netof
99and
100.Fn inet_lnaof
101break apart Internet host addresses, returning
102the network number and local network address part,
103respectively.
104.Pp
105All Internet addresses are returned in network
106order (bytes ordered from left to right).
107All network numbers and local address parts are
108returned as machine format integer values.
109.Sh INTERNET ADDRESSES
110Values specified using the
111.Ql \&.
112notation take one
113of the following forms:
114.Bd -literal -offset indent
115a.b.c.d
116a.b.c
117a.b
118a
119.Ed
120.Pp
121When four parts are specified, each is interpreted
122as a byte of data and assigned, from left to right,
123to the four bytes of an Internet address.  Note
124that when an Internet address is viewed as a 32-bit
125integer quantity on the
126.Tn VAX
127the bytes referred to
128above appear as
129.Dq Li d.c.b.a .
130That is,
131.Tn VAX
132bytes are
133ordered from right to left.
134.Pp
135When a three part address is specified, the last
136part is interpreted as a 16-bit quantity and placed
137in the right-most two bytes of the network address.
138This makes the three part address format convenient
139for specifying Class B network addresses as
140.Dq Li 128.net.host .
141.Pp
142When a two part address is supplied, the last part
143is interpreted as a 24-bit quantity and placed in
144the right most three bytes of the network address.
145This makes the two part address format convenient
146for specifying Class A network addresses as
147.Dq Li net.host .
148.Pp
149When only one part is given, the value is stored
150directly in the network address without any byte
151rearrangement.
152.Pp
153All numbers supplied as
154.Dq parts
155in a
156.Ql  \&.
157notation
158may be decimal, octal, or hexadecimal, as specified
159in the C language (i.e., a leading 0x or 0X implies
160hexadecimal; otherwise, a leading 0 implies octal;
161otherwise, the number is interpreted as decimal).
162.Sh DIAGNOSTICS
163The constant
164.Dv INADDR_NONE
165is returned by
166.Fn inet_addr
167and
168.Fn inet_network
169for malformed requests.
170.Sh SEE ALSO
171.Xr gethostbyname 3 ,
172.Xr getnetent 3 ,
173.Xr hosts 5 ,
174.Xr networks 5 ,
175.Sh HISTORY
176These
177functions appeared in
178.Bx 4.2 .
179.Sh BUGS
180The value
181.Dv INADDR_NONE
182(0xffffffff) is a valid broadcast address, but
183.Fn inet_addr
184cannot return that value without indicating failure.
185The newer
186.Fn inet_aton
187function does not share this problem.
188The problem of host byte ordering versus network byte ordering is
189confusing.
190The string returned by
191.Fn inet_ntoa
192resides in a static memory area.
193.Pp
194Inet_addr should return a
195.Fa struct in_addr .
196