]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/inet.3
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man3 / inet.3
CommitLineData
fea681da 1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3d54a910
MK
2.\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3.\" <mtk.manpages@gmail.com>
fea681da 4.\"
4b72fb64 5.\" %%%LICENSE_START(verbatim)
fea681da
MK
6.\" Permission is granted to make and distribute verbatim copies of this
7.\" manual provided the copyright notice and this permission notice are
8.\" preserved on all copies.
9.\"
10.\" Permission is granted to copy and distribute modified versions of this
11.\" manual under the conditions for verbatim copying, provided that the
12.\" entire resulting derived work is distributed under the terms of a
13.\" permission notice identical to this one.
c13182ef 14.\"
fea681da
MK
15.\" Since the Linux kernel and libraries are constantly changing, this
16.\" manual page may be incorrect or out-of-date. The author(s) assume no
17.\" responsibility for errors or omissions, or for damages resulting from
18.\" the use of the information contained herein. The author(s) may not
19.\" have taken the same level of care in the production of this manual,
20.\" which is licensed free of charge, as they might when working
21.\" professionally.
c13182ef 22.\"
fea681da
MK
23.\" Formatted or processed versions of this manual, if unaccompanied by
24.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 25.\" %%%LICENSE_END
fea681da
MK
26.\"
27.\" References consulted:
28.\" Linux libc source code
29.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
30.\" 386BSD man pages
31.\" libc.info (from glibc distribution)
32.\" Modified Sat Jul 24 19:12:00 1993 by Rik Faith <faith@cs.unc.edu>
33.\" Modified Sun Sep 3 20:29:36 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
34.\" Changed network into host byte order (for inet_network),
35.\" Andreas Jaeger <aj@arthur.rhein-neckar.de>, 980130.
054f5228
MK
36.\" 2008-06-19, mtk
37.\" Describe the various address forms supported by inet_aton().
38.\" Clarify discussion of inet_lnaof(), inet_netof(), and inet_makeaddr().
39.\" Add discussion of Classful Addressing, noting that it is obsolete.
40.\" Added an EXAMPLE program.
fea681da 41.\"
7d90b3d3 42.TH INET 3 2013-02-10 "GNU" "Linux Programmer's Manual"
fea681da 43.SH NAME
c13182ef 44inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof,
fea681da
MK
45inet_netof \- Internet address manipulation routines
46.SH SYNOPSIS
47.nf
48.B #include <sys/socket.h>
49.B #include <netinet/in.h>
50.B #include <arpa/inet.h>
51.sp
52.BI "int inet_aton(const char *" cp ", struct in_addr *" inp );
53.sp
54.BI "in_addr_t inet_addr(const char *" cp );
55.sp
56.BI "in_addr_t inet_network(const char *" cp );
57.sp
58.BI "char *inet_ntoa(struct in_addr " in );
59.sp
60.BI "struct in_addr inet_makeaddr(int " net ", int " host );
61.sp
62.BI "in_addr_t inet_lnaof(struct in_addr " in );
63.sp
64.BI "in_addr_t inet_netof(struct in_addr " in );
65.fi
cc4615cc
MK
66.sp
67.in -4n
68Feature Test Macro Requirements for glibc (see
69.BR feature_test_macros (7)):
70.in
71.sp
72.BR inet_aton (),
73.BR inet_ntoa ():
74_BSD_SOURCE || _SVID_SOURCE
fea681da 75.SH DESCRIPTION
60a90ecd
MK
76.BR inet_aton ()
77converts the Internet host address \fIcp\fP from the
054f5228
MK
78IPv4 numbers-and-dots notation into binary form (in network byte order)
79and stores it in the structure that \fIinp\fP points to.
60a90ecd 80.BR inet_aton ()
c7094399 81returns nonzero if the address is valid, zero if not.
054f5228
MK
82The address supplied in
83.I cp
84can have one of the following forms:
85.TP 10
86.I a.b.c.d
57e5ca03 87Each of the four numeric parts specifies a byte of the address;
054f5228
MK
88the bytes are assigned in left-to-right order to produce the binary address.
89.TP
90.I a.b.c
91Parts
92.I a
93and
94.I b
95specify the first two bytes of the binary address.
96Part
97.I c
98is interpreted as a 16-bit value that defines the rightmost two bytes
99of the binary address.
100This notation is suitable for specifying (outmoded) Class B
101network addresses.
102.TP
103.I a.b
104Part
105.I a
106specifies the first byte of the binary address.
107Part
108.I b
109is interpreted as a 24-bit value that defines the rightmost three bytes
110of the binary address.
111This notation is suitable for specifying (outmoded) Class C
112network addresses.
113.TP
114.I a
115The value
116.I a
117is interpreted as a 32-bit value that is stored directly
118into the binary address without any byte rearrangement.
119.PP
120In all of the above forms,
121components of the dotted address can be specified in decimal,
122octal (with a leading
123.IR 0 ),
124or hexadecimal, with a leading
125.IR 0X ).
126Addresses in any of these forms are collectively termed
127.IR "IPV4 numbers-and-dots notation" .
128The form that uses exactly four decimal numbers is referred to as
129.IR "IPv4 dotted-decimal notation"
130(or sometimes:
131.IR "IPv4 dotted-quad notation" ).
fea681da 132.PP
60a90ecd
MK
133The
134.BR inet_addr ()
135function converts the Internet host address
054f5228 136\fIcp\fP from IPv4 numbers-and-dots notation into binary data in network
c13182ef 137byte order.
2f0af33b
MK
138If the input is invalid,
139.B INADDR_NONE
140(usually \-1) is returned.
054f5228
MK
141Use of this function is problematic because \-1 is a valid address
142(255.255.255.255).
143Avoid its use in favor of
60a90ecd 144.BR inet_aton (),
054f5228
MK
145.BR inet_pton (3),
146or
147.BR getaddrinfo (3)
148which provide a cleaner way to indicate error return.
fea681da 149.PP
60a90ecd
MK
150The
151.BR inet_network ()
054f5228
MK
152function converts
153.IR cp ,
154a string in IPv4 numbers-and-dots notation,
155into a number in host byte order suitable for use as an
156Internet network address.
157On success, the converted address is returned.
7cc028fb 158If the input is invalid, \-1 is returned.
fea681da 159.PP
60a90ecd
MK
160The
161.BR inet_ntoa ()
162function converts the Internet host address
054f5228
MK
163\fIin\fP, given in network byte order, to a string in IPv4
164dotted-decimal notation.
c13182ef 165The string is returned in a statically
fea681da
MK
166allocated buffer, which subsequent calls will overwrite.
167.PP
60a90ecd 168The
60a90ecd 169.BR inet_lnaof ()
054f5228 170function returns the local network address part
c13182ef 171of the Internet address \fIin\fP.
054f5228 172The returned value is in host byte order.
fea681da 173.PP
60a90ecd
MK
174The
175.BR inet_netof ()
176function returns the network number part of
054f5228
MK
177the Internet address \fIin\fP.
178The returned value is in host byte order.
179.PP
180The
181.BR inet_makeaddr ()
182function is the converse of
61792fc6 183.BR inet_netof ()
054f5228
MK
184and
185.BR inet_lnaof ().
186It returns an Internet host address in network byte order,
187created by combining the network number \fInet\fP
188with the local address \fIhost\fP, both in
189host byte order.
fea681da 190.PP
60a90ecd
MK
191The structure \fIin_addr\fP as used in
192.BR inet_ntoa (),
193.BR inet_makeaddr (),
3c775eb7 194.BR inet_lnaof ()
60a90ecd
MK
195and
196.BR inet_netof ()
a9a13a50
MK
197is defined in
198.I <netinet/in.h>
199as:
fea681da 200.sp
bd191423 201.in +4n
fea681da 202.nf
9f8162f9
MK
203typedef uint32_t in_addr_t;
204
fea681da 205struct in_addr {
9f8162f9
MK
206 in_addr_t s_addr;
207};
fea681da 208.fi
bd191423 209.in
47297adb 210.SH CONFORMING TO
2b2581ee 2114.3BSD.
054f5228 212.BR inet_addr ()
2b2581ee
MK
213and
214.BR inet_ntoa ()
215are specified in POSIX.1-2001.
054f5228 216.BR inet_aton ()