no retries or perror if EADDRNOTAVAIL, so can fail gracefully if no net
[unix-history] / usr / src / lib / libc / net / inet.3
CommitLineData
fd221ed5
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
0dc23afe 5.\" @(#)inet.3 6.1 (Berkeley) %G%
fd221ed5 6.\"
0dc23afe 7.TH INET 3N ""
fd221ed5
KM
8.UC 5
9.SH NAME
10inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof, inet_netof \- Internet address manipulation routines
11.SH SYNOPSIS
12.nf
13.B "#include <sys/socket.h>
14.B "#include <netinet/in.h>
15.B "#include <arpa/inet.h>
16.PP
0dc23afe 17.B "unsigned long inet_addr(cp)
fd221ed5
KM
18.B "char *cp;
19.PP
20.B "int inet_network(cp)
21.B "char *cp;
22.PP
23.B "char *inet_ntoa(in)
0dc23afe 24.B "struct in_addr in;
fd221ed5
KM
25.PP
26.B "struct in_addr inet_makeaddr(net, lna)
27.B "int net, lna;
28.PP
29.B "int inet_lnaof(in)
30.B "struct in_addr in;
31.PP
32.B "int inet_netof(in)
33.B "struct in_addr in;
34.fi
35.SH DESCRIPTION
36The routines
37.I inet_addr
38and
39.I inet_network
40each interpret character strings representing
41numbers expressed in the Internet standard \*(lq.\*(rq
42notation, returning numbers suitable for use
43as Internet addresses and Internet network
44numbers, respectively. The routine
45.I inet_ntoa
46takes an Internet address and returns an ASCII
47string representing the address in \*(lq.\*(rq
48notation. The routine
49.I inet_makeaddr
50takes an Internet network number and a local
51network address and constructs an Internet address
52from it. The routines
53.I inet_netof
54and
55.I inet_lnaof
56break apart Internet host addresses, returning
57the network number and local network address part,
58respectively.
59.PP
60All Internet address are returned in network
61order (bytes ordered from left to right).
62All network numbers and local address parts are
63returned as machine format integer values.
64.SH "INTERNET ADDRESSES"
65Values specified using the \*(lq.\*(rq notation take one
66of the following forms:
67.RS
68.nf
69a.b.c.d
70a.b.c
71a.b
72a
73.RE
74.fi
75When four parts are specified, each is interpreted
76as a byte of data and assigned, from left to right,
77to the four bytes of an Internet address. Note
78that when an Internet address is viewed as a 32-bit
79integer quantity on the VAX the bytes referred to
80above appear as \*(lqd.c.b.a\*(rq. That is, VAX bytes are
81ordered from right to left.
82.PP
83When a three part address is specified, the last
84part is interpreted as a 16-bit quantity and placed
85in the right most two bytes of the network address.
86This makes the three part address format convenient
87for specifying Class B network addresses as
88\*(lq128.net.host\*(rq.
89.PP
90When a two part address is supplied, the last part
91is interpreted as a 24-bit quantity and placed in
92the right most three bytes of the network address.
93This makes the two part address format convenient
94for specifying Class A network addresses as
95\*(lqnet.host\*(rq.
96.PP
97When only one part is given, the value is stored
98directly in the network address without any byte
99rearrangement.
100.PP
101All numbers supplied as \*(lqparts\*(rq in a \*(lq.\*(rq notation
102may be decimal, octal, or hexadecimal, as specified
103in the C language (i.e. a leading 0x or 0X implies
104hexadecimal; otherwise, a leading 0 implies octal;
105otherwise, the number is interpreted as decimal).
106.SH "SEE ALSO"
107gethostent(3N), getnetent(3N), hosts(5), networks(5),
108.SH DIAGNOSTICS
109The value \-1 is returned by
110.I inet_addr
111and
112.I inet_network
113for malformed requests.
114.SH BUGS
115The problem of host byte ordering versus network byte ordering is
116confusing. A simple way to specify Class C network addresses in a manner
117similar to that for Class B and Class A is needed.
118The string returned by
119.I inet_ntoa
120resides in a static memory area.
0dc23afe
KM
121.br
122Inet_addr should return a struct in_addr.