.TH inet_addr() "" "" "Sockets Function (libsocket)"
.PC "Transform an IP address from text to binary"
.B "#include <netinet/in.h>"
.B "#include <arpa/inet.h>"
.B "#include <sys/types.h>"
\fBulong inet_addr(\fIip_address\^\fB)\fR
\fBchar *\fIip_address\^\fB;\fR
.PP
The function
.B inet_addr()
translates an Internet-protocol (IP) address from text into binary format.
.I ip_address
gives the address where the string that holds the IP address
resides in memory.
.PP
If all goes well,
.B inet_addr()
returns the binary address that it built from
.IR ip_address .
If, however,
.I ip_address
points to a malformed Internet address,
.B inet_addr()
returns \-1.
.PP
An IP address consists of four bytes.
The four bytes normally are written as four numbers
that are separated by periods;
for example, ``199.3.32.100''.
.II "IP dot notation"
.II "dot notation"
This way of rendering an IP address is called
.IR "dot notation" .
Each byte can as a written as a decimal, octal, or hexadecimal number.
By default, a numbers is written in decimal;
a leading ``0x'' or ``0X'' indicates hexadecimal,
and a leading `0' indicates octal.
.PP
When
.B inet_addr()
translates an IP address from text into binary, it simply transforms the
four numbers as written into four bytes,
which it writes into the four bytes of an unsigned long (32-bit) integer,
from left to right, without regard to the machine's byte ordering.
This means, among other things, that you cannot perform arithmetic on the
address that
.B inet_addr()
returns \(em not even to increment or decrement it.
.PP
The IP address to which
.I ip_address
points can have any of the following four forms:
.DS
	\fIfirst.second.third.fourth\fR
	\fIfirst.second.third\fR
	\fIfirst.second\fR
	\fIfirst\fR
.DE
.PP
When the string to which
.I ip_address
points specifies all four parts of the Internet address,
.B inet_addr()
writes all four, from left to right, into the long integer that it returns.
.PP
When
.I ip_address
points to a three-part address,
.B inet_addr()
interprets the last (third) part as a 16-bit value, which it writes into
into the rightmost two bytes of the network address.
When
.I ip_address
points to a two-part address,
.B inet_addr()
interprets the second part as a 24-bit, which it writes into 
the rightmost three bytes of the network address.
.PP
When
.I ip_address
points to a one-part address,
.B inet_addr()
simply transforms it into an integer without shuffling any bytes.
.SH "See Also"
.Xr "inet_network()," inet_netw
.Xr "libsocket" libsocket
.SH Notes
Because \*(CO does not yet support networking,
.B inet_addr()
is a dummy function that always returns zero.
