Add nsswitch support.
[dragonfly.git] / lib / libc / net / getnetent.3
1 .\" Copyright (c) 1983, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)getnetent.3 8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/net/getnetent.3,v 1.11.2.4 2001/12/14 18:33:55 ru Exp $
34 .\" $DragonFly: src/lib/libc/net/getnetent.3,v 1.2 2003/06/17 04:26:44 dillon Exp $
35 .\"
36 .Dd June 4, 1993
37 .Dt GETNETENT 3
38 .Os
39 .Sh NAME
40 .Nm getnetent ,
41 .Nm getnetbyaddr ,
42 .Nm getnetbyname ,
43 .Nm setnetent ,
44 .Nm endnetent
45 .Nd get network entry
46 .Sh LIBRARY
47 .Lb libc
48 .Sh SYNOPSIS
49 .In netdb.h
50 .Ft struct netent *
51 .Fn getnetent void
52 .Ft struct netent *
53 .Fn getnetbyname "const char *name"
54 .Ft struct netent *
55 .Fn getnetbyaddr "unsigned long net" "int type"
56 .Ft void
57 .Fn setnetent "int stayopen"
58 .Ft void
59 .Fn endnetent void
60 .Sh DESCRIPTION
61 The
62 .Fn getnetent ,
63 .Fn getnetbyname ,
64 and
65 .Fn getnetbyaddr
66 functions
67 each return a pointer to an object with the
68 following structure describing an internet network.
69 This structure contains either the information obtained
70 from the nameserver,
71 .Xr named 8 ,
72 broken-out fields of a line in the network data base
73 .Pa /etc/networks ,
74 or entries supplied by the
75 .Xr yp 4
76 system.  The order of the lookups is controlled by the
77 `networks' entry in
78 .Xr nsswitch.conf 5 .
79 .Pp
80 .Bd -literal -offset indent
81 struct  netent {
82         char            *n_name;        /* official name of net */
83         char            **n_aliases;    /* alias list */
84         int             n_addrtype;     /* net number type */
85         unsigned long   n_net;          /* net number */
86 };
87 .Ed
88 .Pp
89 The members of this structure are:
90 .Bl -tag -width n_addrtype
91 .It Fa n_name
92 The official name of the network.
93 .It Fa n_aliases
94 A zero terminated list of alternate names for the network.
95 .It Fa n_addrtype
96 The type of the network number returned; currently only AF_INET.
97 .It Fa n_net
98 The network number.  Network numbers are returned in machine byte
99 order.
100 .El
101 .Pp
102 The
103 .Fn getnetent
104 function
105 reads the next line of the file, opening the file if necessary.
106 .Pp
107 The
108 .Fn setnetent
109 function
110 opens and rewinds the file.  If the
111 .Fa stayopen
112 flag is non-zero,
113 the net data base will not be closed after each call to
114 .Fn getnetbyname
115 or
116 .Fn getnetbyaddr .
117 .Pp
118 The
119 .Fn endnetent
120 function
121 closes the file.
122 .Pp
123 The
124 .Fn getnetbyname
125 function
126 and
127 .Fn getnetbyaddr
128 sequentially search from the beginning
129 of the file until a matching
130 net name or
131 net address and type is found,
132 or until
133 .Dv EOF
134 is encountered.
135 The
136 .Fa type
137 must be
138 .Dv AF_INET .
139 Network numbers are supplied in host order.
140 .Sh FILES
141 .Bl -tag -width /etc/nsswitch.conf -compact
142 .It Pa /etc/networks
143 .It Pa /etc/nsswitch.conf
144 .It Pa /etc/resolv.conf
145 .El
146 .Sh DIAGNOSTICS
147 Null pointer
148 (0) returned on
149 .Dv EOF
150 or error.
151 .Sh SEE ALSO
152 .Xr networks 5
153 .Pp
154 .%T RFC 1101
155 .Sh HISTORY
156 The
157 .Fn getnetent ,
158 .Fn getnetbyaddr ,
159 .Fn getnetbyname ,
160 .Fn setnetent ,
161 and
162 .Fn endnetent
163 functions appeared in
164 .Bx 4.2 .
165 .Sh BUGS
166 The data space used by
167 these functions is static; if future use requires the data, it should be
168 copied before any subsequent calls to these functions overwrite it.
169 Only Internet network
170 numbers are currently understood.
171 Expecting network numbers to fit
172 in no more than 32 bits is probably
173 naive.