xref: /netbsd-src/external/bsd/libbind/dist/doc/getnetent.3 (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1*5bbd2a12Schristos.\"	$NetBSD: getnetent.3,v 1.1.1.2 2012/09/09 16:07:43 christos Exp $
2b5677b36Schristos.\"
3b5677b36Schristos.\" Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
4b5677b36Schristos.\"
5b5677b36Schristos.\" Permission to use, copy, modify, and/or distribute this software for any
6b5677b36Schristos.\" purpose with or without fee is hereby granted, provided that the above
7b5677b36Schristos.\" copyright notice and this permission notice appear in all copies.
8b5677b36Schristos.\"
9b5677b36Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10b5677b36Schristos.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11b5677b36Schristos.\" AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12b5677b36Schristos.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13b5677b36Schristos.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14b5677b36Schristos.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15b5677b36Schristos.\" PERFORMANCE OF THIS SOFTWARE.
16b5677b36Schristos.\"
17b5677b36Schristos.\" Id: getnetent.3,v 1.3 2009/01/22 23:49:23 tbox Exp
18b5677b36Schristos.\"
19b5677b36Schristos.Dd May 20, 1996
20b5677b36Schristos.Dt GETNETENT @LIB_NETWORK_EXT_U@
21b5677b36Schristos.Os BSD 4
22b5677b36Schristos.Sh NAME
23b5677b36Schristos.Nm getnetent ,
24b5677b36Schristos.Nm getnetbyaddr ,
25b5677b36Schristos.Nm getnetbyname ,
26b5677b36Schristos.Nm setnetent ,
27b5677b36Schristos.Nm endnetent
28b5677b36Schristos.Nd get networks entry
29b5677b36Schristos.Sh SYNOPSIS
30b5677b36Schristos.Fd #include <netdb.h>
31b5677b36Schristos.Ft struct netent *
32b5677b36Schristos.Fn getnetent
33b5677b36Schristos.Ft struct netent *
34b5677b36Schristos.Fn getnetbyname "char name"
35b5677b36Schristos.Ft struct netent *
36b5677b36Schristos.Fn getnetbyaddr "unsigned long net" "int type"
37b5677b36Schristos.Ft void
38b5677b36Schristos.Fn setnetent "int stayopen"
39b5677b36Schristos.Ft void
40b5677b36Schristos.Fn endnetent
41b5677b36Schristos.Sh DESCRIPTION
42b5677b36SchristosThe
43b5677b36Schristos.Fn getnetent ,
44b5677b36Schristos.Fn getnetbyname ,
45b5677b36Schristosand
46b5677b36Schristos.Fn getnetbyaddr
47b5677b36Schristossubroutines
48b5677b36Schristoseach return a pointer to an object with the following structure
49b5677b36Schristoscontaining the broken-out fields of a line in the
50b5677b36Schristos.Pa networks
51b5677b36Schristosdatabase.
52b5677b36Schristos.Bd -literal -offset indent
53b5677b36Schristosstruct	netent {
54b5677b36Schristos	char	*n_name;	/* official name of net */
55b5677b36Schristos	char	**n_aliases;	/* alias list */
56b5677b36Schristos	int	n_addrtype;	/* net number type */
57b5677b36Schristos	long	n_net;		/* net number */
58b5677b36Schristos};
59b5677b36Schristos.Ed
60b5677b36Schristos.Pp
61b5677b36SchristosThe members of this structure are:
62b5677b36Schristos.Bl -tag -width "n_addrtype"
63b5677b36Schristos.It n_name
64b5677b36SchristosThe official name of the network.
65b5677b36Schristos.It n_aliases
66b5677b36SchristosA zero-terminated list of alternate names for the network.
67b5677b36Schristos.It n_addrtype
68b5677b36SchristosThe type of the network number returned:
69b5677b36Schristos.Dv AF_INET .
70b5677b36Schristos.It n_net
71b5677b36SchristosThe network number.  Network numbers are returned in machine byte
72b5677b36Schristosorder.
73b5677b36Schristos.El
74b5677b36Schristos.Pp
75b5677b36SchristosIf the
76b5677b36Schristos.Fa stayopen
77b5677b36Schristosflag on a
78b5677b36Schristos.Fn setnetent
79b5677b36Schristossubroutine is NULL, the
80b5677b36Schristos.Pa networks
81b5677b36Schristosdatabase is opened.  Otherwise, the
82b5677b36Schristos.Fn setnetent
83b5677b36Schristoshas the effect of rewinding the
84b5677b36Schristos.Pa networks
85b5677b36Schristosdatabase.
86b5677b36SchristosThe
87b5677b36Schristos.Fn endnetent
88b5677b36Schristossubroutine may be called to
89b5677b36Schristosclose the
90b5677b36Schristos.Pa networks
91b5677b36Schristosdatabase when processing is complete.
92b5677b36Schristos.Pp
93b5677b36SchristosThe
94b5677b36Schristos.Fn getnetent
95b5677b36Schristossubroutine simply reads the next
96b5677b36Schristosline while
97b5677b36Schristos.Fn getnetbyname
98b5677b36Schristosand
99b5677b36Schristos.Fn getnetbyaddr
100b5677b36Schristossearch until a matching
101b5677b36Schristos.Fa name
102b5677b36Schristosor
103b5677b36Schristos.Fa net
104b5677b36Schristosnumber is found
105b5677b36Schristos(or until
106b5677b36Schristos.Dv EOF
107b5677b36Schristosis encountered).  The
108b5677b36Schristos.Fa type must be
109b5677b36Schristos.Dv AF_INET .
110b5677b36SchristosThe
111b5677b36Schristos.Fn getnetent
112b5677b36Schristossubroutine keeps a pointer in the database, allowing
113b5677b36Schristossuccessive calls to be used to search the entire file.
114b5677b36Schristos.Pp
115b5677b36SchristosBefore a
116b5677b36Schristos.Ic while
117b5677b36Schristosloop using
118b5677b36Schristos.Fn getnetent ,
119b5677b36Schristosa call to
120b5677b36Schristos.Fn setnetent
121b5677b36Schristosmust be made
122b5677b36Schristosin order to perform initialization; a call to
123b5677b36Schristos.Fn endnetent
124b5677b36Schristosmust be used after the loop.  Both
125b5677b36Schristos.Fn getnetbyname
126b5677b36Schristosand
127b5677b36Schristos.Fn getnetbyaddr
128b5677b36Schristosmake calls to
129b5677b36Schristos.Fn setnetent
130b5677b36Schristosand
131b5677b36Schristos.Fn endnetent .
132b5677b36Schristos.Sh FILES
133b5677b36Schristos.Pa /etc/networks
134b5677b36Schristos.Sh DIAGNOSTICS
135b5677b36SchristosNull pointer (0) returned on
136b5677b36Schristos.Dv EOF
137b5677b36Schristosor error.
138b5677b36Schristos.Sh SEE ALSO
139b5677b36Schristos.Xr networks @FORMAT_EXT@ ,
140b5677b36SchristosRFC 1101.
141b5677b36Schristos.Sh HISTORY
142b5677b36SchristosThe
143b5677b36Schristos.Fn "getnetent" ,
144b5677b36Schristos.Fn "getnetbyaddr" ,
145b5677b36Schristos.Fn "getnetbyname" ,
146b5677b36Schristos.Fn "setnetent" ,
147b5677b36Schristosand
148b5677b36Schristos.Fn "endnetent"
149b5677b36Schristosfunctions appeared in
150b5677b36Schristos.Bx 4.2 .
151b5677b36Schristos.Sh BUGS
152b5677b36SchristosThe data space used by these functions is static; if future use requires the
153b5677b36Schristosdata, it should be copied before any subsequent calls to these functions
154b5677b36Schristosoverwrite it.  Only Internet network numbers are currently understood.
155b5677b36SchristosExpecting network numbers to fit in no more than 32 bits is probably naive.
156