Manual Pages for Linux CentOS command on man inet_network
MyWebUniversity

Manual Pages for Linux CentOS command on man inet_network

INET(3) Linux Programmer's Manual INET(3)

NAME inetaton, inetaddr, inetnetwork, inetntoa, inetmakeaddr,

inetlnaof, inetnetof - Internet address manipulation routines SYNOPSIS

#include

#include

#include int inetaton(const char *cp, struct inaddr *inp); inaddrt inetaddr(const char *cp); inaddrt inetnetwork(const char *cp); char *inetntoa(struct inaddr in); struct inaddr inetmakeaddr(int net, int host); inaddrt inetlnaof(struct inaddr in); inaddrt inetnetof(struct inaddr in); Feature Test Macro Requirements for glibc (see featuretestmacros(7)): inetaton(), inetntoa(): BSDSOURCE || SVIDSOURCE DESCRIPTION inetaton() converts the Internet host address cp from the IPv4 num‐

bers-and-dots notation into binary form (in network byte order) and stores it in the structure that inp points to. inetaton() 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 net‐ work 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 C network addresses.

a The value a is interpreted as a 32-bit value that is stored directly into the binary address without any byte rearrange‐ ment. 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 deci‐

mal numbers is referred to as IPv4 dotted-decimal notation (or some‐

times: IPv4 dotted-quad notation). The inetaddr() 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, INADDRNONE (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 inetaton(), inetpton(3), or getaddrinfo(3) which provide a cleaner way to indicate error return.

The inetnetwork() 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 inetntoa() 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 subse‐ quent calls will overwrite. The inetlnaof() function returns the local network address part of the Internet address in. The returned value is in host byte order. The inetnetof() function returns the network number part of the Inter‐ net address in. The returned value is in host byte order. The inetmakeaddr() function is the converse of inetnetof() and inetlnaof(). 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 inaddr as used in inetntoa(), inetmakeaddr(), inetlnaof() and inetnetof() is defined in as: typedef uint32t inaddrt; struct inaddr { inaddrt saddr; }; ATTRIBUTES For an explanation of the terms used in this section, see attributes(7). ┌───────────────────────────────┬───────────────┬────────────────┐ │Interface │ Attribute │ Value │ ├───────────────────────────────┼───────────────┼────────────────┤

│inetaton(), inetaddr(), │ Thread safety │ MT-Safe locale │ │inetnetwork(), inetntoa() │ │ │ ├───────────────────────────────┼───────────────┼────────────────┤

│inetmakeaddr(), inetlnaof(), │ Thread safety │ MT-Safe │ │inetnetof() │ │ │ └───────────────────────────────┴───────────────┴────────────────┘ CONFORMING TO

4.3BSD. inetaddr() and inetntoa() are specified in POSIX.1-2001.

inetaton() 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). inetlnaof(), inetnetof(), and inetmakeaddr() are legacy functions that assume they are dealing with classful network addresses. Classful networking divides IPv4 network addresses into host and network compo‐ nents 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) bound‐ aries. EXAMPLE An example of the use of inetaton() and inetntoa() 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 BSDSOURCE

#include

#include

#include int main(int argc, char *argv[]) { struct inaddr addr; if (argc != 2) {

fprintf(stderr, "%s \n", argv[0]); exit(EXITFAILURE); } if (inetaton(argv[1], &addr) == 0) { fprintf(stderr, "Invalid address\n"); exit(EXITFAILURE); }

printf("%s\n", inetntoa(addr)); exit(EXITSUCCESS); } SEE ALSO byteorder(3), getaddrinfo(3), gethostbyname(3), getnameinfo(3), getne‐ tent(3), inetntop(3), inetpton(3), hosts(5), networks(5) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

GNU 2013-02-10 INET(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™