make .rhosts a bit more forgiving
[unix-history] / usr / src / lib / libc / net / gethostbyname.3
CommitLineData
b9a6fdfb
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.\"
92953539 5.\" @(#)gethostbyname.3 6.1 (Berkeley) %G%
b9a6fdfb 6.\"
92953539 7.TH GETHOSTENT 3N ""
b9a6fdfb
KM
8.UC 5
9.SH NAME
92953539 10gethostent, gethostbyaddr, gethostbyname, sethostent, endhostent, sethostfile \- get network host entry
b9a6fdfb
KM
11.SH SYNOPSIS
12.B "#include <netdb.h>
13.PP
14.B "struct hostent *gethostent()
15.PP
16.B "struct hostent *gethostbyname(name)
17.br
18.B "char *name;
19.PP
20.B "struct hostent *gethostbyaddr(addr, len, type)
21.br
22.B "char *addr; int len, type;
23.PP
24.B "sethostent(stayopen)
25.br
92953539 26.B "int stayopen;
b9a6fdfb
KM
27.PP
28.B "endhostent()
92953539
KM
29.PP
30.B "sethostfile(name)
31.br
32.B "char *name;
b9a6fdfb
KM
33.SH DESCRIPTION
34.IR Gethostent ,
35.IR gethostbyname ,
36and
37.I gethostbyaddr
38each return a pointer to an object with the
39following structure
40containing the broken-out
41fields of a line in the network host data base,
42.IR /etc/hosts .
43.RS
44.PP
45.nf
46struct hostent {
47 char *h_name; /* official name of host */
48 char **h_aliases; /* alias list */
49 int h_addrtype; /* address type */
50 int h_length; /* length of address */
51 char *h_addr; /* address */
52};
53.ft R
54.ad
55.fi
56.RE
57.PP
58The members of this structure are:
59.TP \w'h_addrtype'u+2n
60h_name
61Official name of the host.
62.TP \w'h_addrtype'u+2n
63h_aliases
64A zero terminated array of alternate names for the host.
65.TP \w'h_addrtype'u+2n
66h_addrtype
67The type of address being returned; currently always AF_INET.
68.TP \w'h_addrtype'u+2n
69h_length
70The length, in bytes, of the address.
71.TP \w'h_addrtype'u+2n
72h_addr
73A pointer to the network address for the host.
74Host addresses are returned
75in network byte order.
76.PP
77.I Gethostent
78reads the next line of the file, opening the file if necessary.
79.PP
80.I Sethostent
81opens and rewinds the file. If the
82.I stayopen
83flag is non-zero,
84the host data base will not be closed after each call to
85.I gethostent
86(either directly, or indirectly through one of the other
87\*(lqgethost\*(rq calls).
88.PP
89.I Endhostent
90closes the file.
91.PP
92953539
KM
92.I Sethostfile
93changes the default host table file to
94.I name
95thus allowing these routines to be used with alternate host tables.
96Note that it does
97.I not
98close the previous file.
99If this is desired,
100.I endhostent
101should be called prior to it.
102.PP
b9a6fdfb
KM
103.I Gethostbyname
104and
105.I gethostbyaddr
106sequentially search from the beginning
107of the file until a matching
108host name or
109host address is found,
110or until EOF is encountered.
111Host addresses are supplied in network order.
112.SH FILES
113/etc/hosts
114.SH "SEE ALSO"
115hosts(5)
116.SH DIAGNOSTICS
117Null pointer
118(0) returned on EOF or error.
119.SH BUGS
120All information
121is contained in a static area
122so it must be copied if it is
123to be saved. Only the Internet
124address format is currently understood.