inet_lnaof, inet_netof
Purpose
Manipulation subroutines for Internet addresses.
Library
Sockets Library (libsock.a)
Syntax
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
struct in_addr inet_addr (cp) struct in_addr inet_makeaddr (net, lna)
char *cp; int net, lna;
int inet_network (cp) int inet_lnaof (in)
char *cp; struct in_addr in;
char *inet_ntoa (in) int inet_netof (in)
struct in_addr in; struct in_addr in;
Description
The inet_addr and inet_network subroutines each interpret
character strings representing numbers expressed in the
Internet standard dot (.) notation, returning numbers
suitable for use as Internet addresses and Internet
network numbers. The cp parameter represents a string of
characters in the Internet address form.
The inet_ntoa subroutine takes an Internet address and
returns an ASCII string representing the address in dot
notation. The in parameter contains the Internet address
to be converted to ASCII.
The inet_makeaddr takes an Internet network number and a
local network address and constructs an Internet address
from it. The net parameter contains an Internet network
number, while the lna parameter contains a local network
address.
The inet_netof and inet_lnaof subroutines break apart
Internet addresses, returning the network number and
local network address part. The in parameter represents
the Internet address to separate.
All Internet addresses are returned in network order,
with the first byte being the high-order byte. All
network numbers and local addresses are returned as
integer values in machine format.
The values specified using the dot notation take one of
the following forms:
"a.b.c.d"
"a.b.c"
"a.b"
"a"
When four parts are specified, each is interpreted as a
byte of data and assigned to the four bytes of an
Internet address, ordered from high-order to low-order.
When a three-part address is specified, the last part is
interpreted as a 16-bit quantity and placed in the right
two bytes of the network address. This makes the three-
part address format convenient for specifying Class B
network addresses as 128.net.host.
When a two-part address is supplied, the last part is
interpreted as a 24-bit quantity and placed in the right
three bytes of the network address. This makes the two-
part address format convenient for specifying Class A
network addresses as net.host.
When only one part is given, the value is stored directly
in the network address without any byte rearrangement.
All numbers supplied for each part of a dot notation may
be decimal, octal, or hexadecimal, as specified in C lan-
guage. A leading "0x" or "0X" implies hexadecimal, a
leading "0" implies octal, and anything else is inter-
preted as decimal.
Return Value
The inet_addr and inet_network subroutines return numbers
suitable for use as Internet addresses and Internet
network numbers, respectively, on success. If the
inet_addr or inet_network subroutine fails, a value of -1
is returned.
Related Information
In this book: " gethostbyaddr, gethostbyname,
sethostent, endhostent .*5a, gethostent," and "getnetent,
getnetbyaddr, getnetbyname, setnetent, endnetent."
The discussion of /etc/hosts and /etc/networks in Inter-
face Program for use with TCP/IP.