2004-11-03 13:51:07 +00:00
|
|
|
.\" Hey Emacs! This file is -*- nroff -*- source.
|
|
|
|
.\"
|
|
|
|
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.\" References consulted:
|
|
|
|
.\" Linux libc source code
|
|
|
|
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
|
|
|
|
.\" 386BSD man pages
|
|
|
|
.\" libc.info (from glibc distribution)
|
|
|
|
.\" Modified Sat Jul 24 19:12:00 1993 by Rik Faith <faith@cs.unc.edu>
|
|
|
|
.\" Modified Sun Sep 3 20:29:36 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
|
|
|
|
.\" Changed network into host byte order (for inet_network),
|
|
|
|
.\" Andreas Jaeger <aj@arthur.rhein-neckar.de>, 980130.
|
|
|
|
.\"
|
2007-05-18 09:55:10 +00:00
|
|
|
.TH INET 3 2001-07-25 "GNU" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
2007-04-12 22:42:49 +00:00
|
|
|
inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof,
|
2004-11-03 13:51:07 +00:00
|
|
|
inet_netof \- Internet address manipulation routines
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <sys/socket.h>
|
|
|
|
.B #include <netinet/in.h>
|
|
|
|
.B #include <arpa/inet.h>
|
|
|
|
.sp
|
|
|
|
.BI "int inet_aton(const char *" cp ", struct in_addr *" inp );
|
|
|
|
.sp
|
|
|
|
.BI "in_addr_t inet_addr(const char *" cp );
|
|
|
|
.sp
|
|
|
|
.BI "in_addr_t inet_network(const char *" cp );
|
|
|
|
.sp
|
|
|
|
.BI "char *inet_ntoa(struct in_addr " in );
|
|
|
|
.sp
|
|
|
|
.BI "struct in_addr inet_makeaddr(int " net ", int " host );
|
|
|
|
.sp
|
|
|
|
.BI "in_addr_t inet_lnaof(struct in_addr " in );
|
|
|
|
.sp
|
|
|
|
.BI "in_addr_t inet_netof(struct in_addr " in );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
2007-05-12 09:06:04 +00:00
|
|
|
.BR inet_aton ()
|
|
|
|
converts the Internet host address \fIcp\fP from the
|
2004-11-03 13:51:07 +00:00
|
|
|
standard numbers-and-dots notation into binary data and stores it in
|
2007-05-12 09:06:04 +00:00
|
|
|
the structure that \fIinp\fP points to.
|
|
|
|
.BR inet_aton ()
|
|
|
|
returns
|
2005-06-15 13:32:34 +00:00
|
|
|
non-zero if the address is valid, zero if not.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR inet_addr ()
|
|
|
|
function converts the Internet host address
|
2004-11-03 13:51:07 +00:00
|
|
|
\fIcp\fP from numbers-and-dots notation into binary data in network
|
2007-04-12 22:42:49 +00:00
|
|
|
byte order.
|
|
|
|
If the input is invalid, INADDR_NONE (usually \-1) is returned.
|
2007-05-12 09:06:04 +00:00
|
|
|
This is an \fIobsolete\fP interface to
|
|
|
|
.BR inet_aton (),
|
|
|
|
described
|
2004-11-03 13:51:07 +00:00
|
|
|
immediately above; it is obsolete because \-1 is a valid address
|
2007-05-12 09:06:04 +00:00
|
|
|
(255.255.255.255), and
|
|
|
|
.BR inet_aton ()
|
|
|
|
provides a cleaner way
|
2004-11-03 13:51:07 +00:00
|
|
|
to indicate error return.
|
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR inet_network ()
|
|
|
|
function extracts
|
2006-12-04 05:46:35 +00:00
|
|
|
a number in host byte order suitable for use as an Internet address
|
2007-04-12 22:42:49 +00:00
|
|
|
from \fIcp\fP, which is a string in numbers-and-dots notation.
|
2006-12-04 05:46:35 +00:00
|
|
|
If the input is invalid, \-1 is returned.
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR inet_ntoa ()
|
|
|
|
function converts the Internet host address
|
2004-11-03 13:51:07 +00:00
|
|
|
\fIin\fP given in network byte order to a string in standard
|
2007-04-12 22:42:49 +00:00
|
|
|
numbers-and-dots notation.
|
|
|
|
The string is returned in a statically
|
2004-11-03 13:51:07 +00:00
|
|
|
allocated buffer, which subsequent calls will overwrite.
|
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR inet_makeaddr ()
|
|
|
|
function makes an Internet host address
|
2004-11-03 13:51:07 +00:00
|
|
|
in network byte order by combining the network number \fInet\fP
|
|
|
|
with the local address \fIhost\fP in network \fInet\fP, both in
|
|
|
|
local host byte order.
|
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR inet_lnaof ()
|
|
|
|
function returns the local host address part
|
2007-04-12 22:42:49 +00:00
|
|
|
of the Internet address \fIin\fP.
|
|
|
|
The local host address is returned
|
2004-11-03 13:51:07 +00:00
|
|
|
in local host byte order.
|
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR inet_netof ()
|
|
|
|
function returns the network number part of
|
2007-04-12 22:42:49 +00:00
|
|
|
the Internet Address \fIin\fP.
|
|
|
|
The network number is returned in
|
2004-11-03 13:51:07 +00:00
|
|
|
local host byte order.
|
|
|
|
.PP
|
2007-05-12 09:06:04 +00:00
|
|
|
The structure \fIin_addr\fP as used in
|
|
|
|
.BR inet_ntoa (),
|
|
|
|
.BR inet_makeaddr (),
|
|
|
|
.BR inet_lnoaf ()
|
|
|
|
and
|
|
|
|
.BR inet_netof ()
|
2004-11-03 13:51:07 +00:00
|
|
|
is defined in \fInetinet/in.h\fP as:
|
|
|
|
.sp
|
|
|
|
.RS
|
|
|
|
.nf
|
|
|
|
struct in_addr {
|
2007-04-05 12:36:57 +00:00
|
|
|
unsigned long int s_addr;
|
2004-11-03 13:51:07 +00:00
|
|
|
}
|
|
|
|
.fi
|
|
|
|
.RE
|
|
|
|
.PP
|
|
|
|
Note that on the i80x86 the host byte order is Least Significant Byte
|
2005-09-15 17:14:45 +00:00
|
|
|
first (little endian), whereas the network byte order, as used on the
|
|
|
|
Internet, is Most Significant Byte first (big endian).
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH "CONFORMING TO"
|
|
|
|
4.3BSD.
|
|
|
|
.BR inet_addr (),
|
|
|
|
.BR inet_aton (),
|
|
|
|
and
|
|
|
|
.BR inet_ntoa ()
|
|
|
|
are specified in POSIX.1-2001.
|
2007-05-16 02:54:18 +00:00
|
|
|
.SH NOTES
|
2005-09-15 17:14:45 +00:00
|
|
|
When you using numbers-and-dots notation for addresses,
|
|
|
|
be aware that each number will be interpreted as octal
|
2007-04-12 22:42:49 +00:00
|
|
|
if preceded by a 0 and as hexadecimal if preceded by 0x.
|
2005-09-15 17:14:45 +00:00
|
|
|
For example, \fBinet_aton("226.000.000.037", &t)\fP will
|
2006-06-04 20:30:13 +00:00
|
|
|
interpret the address as \fI226.0.0.31\fP and not \fI226.0.0.37\fP.
|
2007-05-18 10:30:02 +00:00
|
|
|
.SS Glibc Notes
|
2007-04-12 22:42:49 +00:00
|
|
|
In order to expose the declaration of
|
2005-12-06 10:34:54 +00:00
|
|
|
.BR inet_aton (),
|
2007-04-12 22:42:49 +00:00
|
|
|
one of the feature test macros _BSD_SOURCE, _SVID_SOURCE, or
|
2006-01-23 06:43:04 +00:00
|
|
|
_GNU_SOURCE must be defined.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR gethostbyname (3),
|
|
|
|
.BR getnetent (3),
|
|
|
|
.BR inet_ntop (3),
|
|
|
|
.BR inet_pton (3),
|
|
|
|
.BR hosts (5),
|
|
|
|
.BR networks (5)
|