.\" @(#)inet 40.6 89/12/26 SMI; from UCB 4.2
.\" Copyright 1989 AT&T
.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved.
.nr X
.if \nX=0 .ds x} inet 3N "User Environment Utilities" "\&"
.if \nX=1 .ds x} inet 3N "User Environment Utilities"
.if \nX=2 .ds x} inet 3N "" "\&"
.if \nX=3 .ds x} inet "" "" "\&"
.TH \*(x}
.SH NAME
\f4inet\fP: \f4inet_addr\fP, \f4inet_network\fP, \f4inet_makeaddr\fP, \f4inet_lnaof\fP, \f4inet_netof\fP, \f4inet_ntoa\fP \- Internet address manipulation
.SH SYNOPSIS
.ft 4
.nf
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
.P
.ft 4
unsigned long
inet_addr(cp)
char *cp;
.P
.ft 4
inet_network(cp)
char *cp;
.P
.ft 4
struct in_addr
inet_makeaddr(net, lna)
int net, lna;
.P
.ft 4
inet_lnaof(in)
struct in_addr in;
.P
.ft 4
inet_netof(in)
struct in_addr in;
.P
.ft 4
char *
inet_ntoa(in)
struct in_addr in;
.ft R
.fi
.SH DESCRIPTION
.P
The routines
\f4inet_addr(\|)\fR
and
\f4inet_network(\|)\fR
each interpret character strings representing numbers expressed in the
Internet standard
`\f4.\fR'
notation, returning numbers suitable for
use as Internet addresses and Internet network numbers, respectively.
The routine
\f4inet_makeaddr(\|)\fR
takes an Internet network number and a local network address and
constructs an Internet address from it.
The routines
\f4inet_netof(\|)\fR
and
\f4inet_lnaof(\|)\fR
break apart Internet host addresses, returning the network number and
local network address part, respectively.
.P
The routine
\f4inet_ntoa(\|)\fR
returns a pointer to a string in the base 256 notation \*(lqd.d.d.d\*(rq
described below.
.P
All Internet addresses are returned in network order (bytes ordered from
left to right).
All network numbers and local address parts are
returned as machine format integer values.
.SH "INTERNET ADDRESSES"
.P
Values specified using the
`\f4.\fR'
notation take one of the following forms:
.IP
.nf
.ft 4
a.b.c.d
a.b.c
a.b
a
.ft R
.fi
.P
When four parts are specified, each is interpreted as a byte of data
and assigned, from left to right, to the four bytes of an Internet
address.
.P
When a three part address is specified, the last part is interpreted as
a 16-bit quantity and placed in the right most two bytes of the network
address.
This makes the three part address format convenient for
specifying Class B network addresses as \*(lq128.net.host\*(rq.
.P
When a two part address is supplied, the last part is interpreted as a
24-bit quantity and placed in the right most three bytes of the network
address.
This makes the two part address format convenient for
specifying Class A network addresses as \*(lqnet.host\*(rq.
.P
When only one part is given, the value is stored directly in the
network address without any byte rearrangement.
.P
All numbers supplied as \*(lqparts\*(rq in a
`\f4.\fR'
notation may
be decimal, octal, or hexadecimal, as specified in the C language (that
is, a leading 0x or
\s-10X\s0
implies hexadecimal; otherwise, a leading 0
implies octal; otherwise, the number is interpreted as decimal).
.SH "SEE ALSO"
\f4gethostent\fR(3N),
\f4getnetent\fR(3N),
\f4hosts\fR(4),
\f4networks\fR(4)
.SH DIAGNOSTICS
.P
The value \-1 is returned by
\f4inet_addr(\|)\fR
and
\f4inet_network(\|)\fR
for malformed requests.
.SH BUGS
.P
The problem of host byte ordering versus network byte ordering is
confusing.
A simple way to specify Class C network addresses in a manner
similar to that for Class B and Class A is needed.
.P
The return value from
\f4inet_ntoa(\|)\fR
points to static information which is overwritten in each call.
