INET
NAMESYNOPSIS
DESCRIPTION
CONFORMING TO
NOTES
EXAMPLE
SEE ALSO
COLOPHON
NAME
inet_aton, inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof, inet_netof − Internet address manipulation routines
SYNOPSIS
#include
<sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int inet_aton(const char *cp, struct in_addr *inp);
in_addr_t inet_addr(const char *cp);
in_addr_t inet_network(const char *cp);
char *inet_ntoa(struct in_addr in);
struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
in_addr_t inet_lnaof(struct in_addr in);
in_addr_t inet_netof(struct in_addr in);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
inet_aton(), inet_ntoa(): _BSD_SOURCE || _SVID_SOURCE
DESCRIPTION
inet_aton() converts the Internet host address cp from the IPv4 numbers-and-dots notation into binary form (in network byte order) and stores it in the structure that inp points to. inet_aton() returns nonzero if the address is valid, zero if not. The address supplied in cp can have one of the following forms:
a.b.c.d |
Each of the four numeric parts specifies a byte of the address; the bytes are assigned in left-to-right order to produce the binary address. | ||
a.b.c |
Parts a and b specify the first two bytes of the binary address. Part c is interpreted as a 16-bit value that defines the rightmost two bytes of the binary address. This notation is suitable for specifying (outmoded) Class B network addresses. | ||
a.b |
Part a specifies the first byte of the binary address. Part b is interpreted as a 24-bit value that defines the rightmost three bytes of the binary address. This notation is suitable for specifying (outmoded) Class A network addresses. | ||
a |
The value a is interpreted as a 32-bit value that is stored directly into the binary address without any byte rearrangement. |
In all of the above forms, components of the dotted address can be specified in decimal, octal (with a leading 0), or hexadecimal, with a leading 0X). Addresses in any of these forms are collectively termed IPV4 numbers-and-dots notation. The form that uses exactly four decimal numbers is referred to as IPv4 dotted-decimal notation (or sometimes: IPv4 dotted-quad notation).
inet_aton() returns 1 if the supplied string was successfully interpreted, or 0 if the string is invalid (errno is not set on error).
The inet_addr() function converts the Internet host address cp from IPv4 numbers-and-dots notation into binary data in network byte order. If the input is invalid, INADDR_NONE (usually −1) is returned. Use of this function is problematic because −1 is a valid address (255.255.255.255). Avoid its use in favor of inet_aton(), inet_pton(3), or getaddrinfo(3), which provide a cleaner way to indicate error return.
The inet_network() function converts cp, a string in IPv4 numbers-and-dots notation, into a number in host byte order suitable for use as an Internet network address. On success, the converted address is returned. If the input is invalid, −1 is returned.
The inet_ntoa() function converts the Internet host address in, given in network byte order, to a string in IPv4 dotted-decimal notation. The string is returned in a statically allocated buffer, which subsequent calls will overwrite.
The inet_lnaof() function returns the local network address part of the Internet address in. The returned value is in host byte order.
The inet_netof() function returns the network number part of the Internet address in. The returned value is in host byte order.
The inet_makeaddr() function is the converse of inet_netof() and inet_lnaof(). It returns an Internet host address in network byte order, created by combining the network number net with the local address host, both in host byte order.
The structure in_addr as used in inet_ntoa(), inet_makeaddr(), inet_lnaof() and inet_netof() is defined in <netinet/in.h> as:
typedef uint32_t in_addr_t;
struct in_addr
{
in_addr_t s_addr;
};
CONFORMING TO
4.3BSD. inet_addr() and inet_ntoa() are specified in POSIX.1-2001. inet_aton() is not specified in POSIX.1-2001, but is available on most systems.
NOTES
On the i386 the host byte order is Least Significant Byte first (little endian), whereas the network byte order, as used on the Internet, is Most Significant Byte first (big endian).
inet_lnaof(), inet_netof(), and inet_makeaddr() are legacy functions that assume they are dealing with classful network addresses. Classful networking divides IPv4 network addresses into host and network components at byte boundaries, as follows:
Class A |
This address type is indicated by the value 0 in the most significant bit of the (network byte ordered) address. The network address is contained in the most significant byte, and the host address occupies the remaining three bytes. | ||
Class B |
This address type is indicated by the binary value 10 in the most significant two bits of the address. The network address is contained in the two most significant bytes, and the host address occupies the remaining two bytes. | ||
Class C |
This address type is indicated by the binary value 110 in the most significant three bits of the address. The network address is contained in the three most significant bytes, and the host address occupies the remaining byte. |
Classful network addresses are now obsolete, having been superseded by Classless Inter-Domain Routing (CIDR), which divides addresses into network and host components at arbitrary bit (rather than byte) boundaries.
EXAMPLE
An example of the use of inet_aton() and inet_ntoa() is shown below. Here are some example runs:
$ ./a.out
226.000.000.037 # Last byte is in octal
226.0.0.31
$ ./a.out 0x7f.1 # First byte is in hex
127.0.0.1
Program
source
#define _BSD_SOURCE
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
struct in_addr addr;
if (argc != 2)
{
fprintf(stderr, "%s
<dotted−address>\n", argv[0]);
exit(EXIT_FAILURE);
}
if
(inet_aton(argv[1], &addr) == 0) {
fprintf(stderr, "Invalid address\n");
exit(EXIT_FAILURE);
}
printf("%s\n",
inet_ntoa(addr));
exit(EXIT_SUCCESS);
}
SEE ALSO
byteorder(3), getaddrinfo(3), gethostbyname(3), getnameinfo(3), getnetent(3), inet_net_pton(3), inet_ntop(3), inet_pton(3), hosts(5), networks(5)
COLOPHON
This page is part of release 3.69 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man−pages/.
More Linux Commands
manpages/glPixelStorei.3gl.html
glPixelStorei(3gl) - set pixel storage modes (Man Page).....
glPixelStore sets pixel storage modes that affect the operation of subsequent glDrawPixels and glReadPixels as well as the unpacking of polygon stipple patterns
manpages/bib1-attr.7.html
bib1-attr(7) - Bib-1 Attribute Set - Linux manual page......
This reference entry lists the Bib-1 attribute set types and values. TYPES The Bib-1 attribute defines six attribute types: Use (1), Relation (2), Position (3),
manpages/Tcl_UniCharToUpper.3.html
Tcl_UniCharToUpper(3) - routines for manipulating the case o
The first three routines convert the case of individual Unicode characters: If ch represents a lower-case character, Tcl_UniCharToUpper returns the correspondin
manpages/elfedit.1.html
elfedit(1) - Update the ELF header of ELF files. (Man Page)
elfedit updates the ELF header of ELF files which have the matching ELF machine and file types. The options control how and which fields in the ELF header shoul
manpages/Mail::DKIM::Canonicalization::DkimCommon.3pm.html
Mail::DKIM::Canonicalization::DkimCommon(3pm) - common canon
This class implements functionality that is common to all the currently-defined DKIM canonicalization methods, but not necessarily common with future canonicali
manpages/XtParent.3.html
XtParent(3) - obtain widget's parent widget id (Man Page)...
XtParent returns the widgets parent widget ID. SEE ALSO X Toolkit Intrinsics - C Language Interface Xlib - C Language X Interface XtParent.3 (Library - Linux ma
manpages/pacat.1.html
pacat(1) - Play back or record raw or encoded audio streams
pacat is a simple tool for playing back or capturing raw or encoded audio files on a PulseAudio sound server. OPTIONS -h | --help Show help. --version Show vers
manpages/acl_to_text.3.html
acl_to_text(3) - convert an ACL to text - Linux manual page
The acl_to_text() function translates the ACL pointed to by the argument acl into a NULL terminated character string. If the pointer len_p is not NULL, then the
manpages/gnutls_x509_trust_list_add_cas.3.html
gnutls_x509_trust_list_add_cas(3) - API function (Man Page)
This function will add the given certificate authorities to the trusted list. The list of CAs must not be deinitialized during this structures lifetime. RETURNS
manpages/gnutls_cipher_set_iv.3.html
gnutls_cipher_set_iv(3) - API function - Linux manual page
This function will set the IV to be used for the next encryption block. SINCE 3.0.0 REPORTING BUGS Report bugs to <bug-gnutls@gnu.org>. GnuTLS home page: http:/
manpages/intrflush_sp.3ncurses.html
intrflush_sp(3ncurses) - curses screen-pointer extension....
This implementation can be configured to provide a set of functions which improve the ability to manage multiple screens. This feature can be added to any of th
manpages/Tcl_GetErrno.3.html
Tcl_GetErrno(3) - manipulate errno to store and retrieve err
Tcl_SetErrno and Tcl_GetErrno provide portable access to the errno variable, which is used to record a POSIX error code after system calls and other operations
