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