BSD 4_2 development
[unix-history] / usr / man / man3 / gethostent.3n
CommitLineData
931a9d50
C
1.TH GETHOSTENT 3N "9 February 1983"
2.UC 4
3.SH NAME
4gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent \- get network host entry
5.SH SYNOPSIS
6.B "#include <netdb.h>
7.PP
8.B "struct hostent *gethostent()
9.PP
10.B "struct hostent *gethostbyname(name)
11.br
12.B "char *name;
13.PP
14.B "struct hostent *gethostbyaddr(addr, len, type)
15.br
16.B "char *addr; int len, type;
17.PP
18.B "sethostent(stayopen)
19.br
20.B "int stayopen
21.PP
22.B "endhostent()
23.SH DESCRIPTION
24.IR Gethostent ,
25.IR gethostbyname ,
26and
27.I gethostbyaddr
28each return a pointer to an object with the
29following structure
30containing the broken-out
31fields of a line in the network host data base,
32.IR /etc/hosts .
33.RS
34.PP
35.nf
36struct hostent {
37 char *h_name; /* official name of host */
38 char **h_aliases; /* alias list */
39 int h_addrtype; /* address type */
40 int h_length; /* length of address */
41 char *h_addr; /* address */
42};
43.ft R
44.ad
45.fi
46.RE
47.PP
48The members of this structure are:
49.TP \w'h_addrtype'u+2n
50h_name
51Official name of the host.
52.TP \w'h_addrtype'u+2n
53h_aliases
54A zero terminated array of alternate names for the host.
55.TP \w'h_addrtype'u+2n
56h_addrtype
57The type of address being returned; currently always AF_INET.
58.TP \w'h_addrtype'u+2n
59h_length
60The length, in bytes, of the address.
61.TP \w'h_addrtype'u+2n
62h_addr
63A pointer to the network address for the host.
64Host addresses are returned
65in network byte order.
66.PP
67.I Gethostent
68reads the next line of the file, opening the file if necessary.
69.PP
70.I Sethostent
71opens and rewinds the file. If the
72.I stayopen
73flag is non-zero,
74the host data base will not be closed after each call to
75.I gethostent
76(either directly, or indirectly through one of the other
77\*(lqgethost\*(rq calls).
78.PP
79.I Endhostent
80closes the file.
81.PP
82.I Gethostbyname
83and
84.I gethostbyaddr
85sequentially search from the beginning
86of the file until a matching
87host name or
88host address is found,
89or until EOF is encountered.
90Host addresses are supplied in network order.
91.SH FILES
92/etc/hosts
93.SH "SEE ALSO"
94hosts(5)
95.SH DIAGNOSTICS
96Null pointer
97(0) returned on EOF or error.
98.SH BUGS
99All information
100is contained in a static area
101so it must be copied if it is
102to be saved. Only the Internet
103address format is currently understood.