xref: /netbsd-src/lib/libc/net/getnetent.3 (revision ae1bfcddc410612bc8c58b807e1830becb69a24c)
1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
2.\" 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.\"     from: @(#)getnetent.3	6.6 (Berkeley) 4/19/91
33.\"	$Id: getnetent.3,v 1.2 1993/08/01 07:45:21 mycroft Exp $
34.\"
35.Dd April 19, 1991
36.Dt GETNETENT 3
37.Os BSD 4.2
38.Sh NAME
39.Nm getnetent ,
40.Nm getnetbyaddr ,
41.Nm getnetbyname ,
42.Nm setnetent ,
43.Nm endnetent
44.Nd get network entry
45.Sh SYNOPSIS
46.Fd #include <netdb.h>
47.Ft struct netent *
48.Fn getnetent
49.Ft struct netent *
50.Fn getnetbyname "char *name"
51.Ft struct netent *
52.Fn getnetbyaddr "long net" "int type"
53.Fn setnetent "int stayopen"
54.Fn endnetent
55.Sh DESCRIPTION
56The
57.Fn getnetent ,
58.Fn getnetbyname ,
59and
60.Fn getnetbyaddr
61functions
62each return a pointer to an object with the
63following structure
64containing the broken-out
65fields of a line in the network data base,
66.Pa /etc/networks .
67.Bd -literal -offset indent
68struct	netent {
69	char		*n_name;	/* official name of net */
70	char		**n_aliases;	/* alias list */
71	int		n_addrtype;	/* net number type */
72	unsigned long	n_net;		/* net number */
73};
74.Ed
75.Pp
76The members of this structure are:
77.Bl -tag -width n_addrtype
78.It Fa n_name
79The official name of the network.
80.It Fa n_aliases
81A zero terminated list of alternate names for the network.
82.It Fa n_addrtype
83The type of the network number returned; currently only AF_INET.
84.It Fa n_net
85The network number.  Network numbers are returned in machine byte
86order.
87.El
88.Pp
89The
90.Fn getnetent
91function
92reads the next line of the file, opening the file if necessary.
93.Pp
94The
95.Fn setnetent
96function
97opens and rewinds the file.  If the
98.Fa stayopen
99flag is non-zero,
100the net data base will not be closed after each call to
101.Fn getnetbyname
102or
103.Fn getnetbyaddr .
104.Pp
105The
106.Fn endnetent
107function
108closes the file.
109.Pp
110The
111.Fn getnetbyname
112function
113and
114.Fn getnetbyaddr
115sequentially search from the beginning
116of the file until a matching
117net name or
118net address and type is found,
119or until
120.Dv EOF
121is encountered.
122Network numbers are supplied in host order.
123.Sh FILES
124.Bl -tag -width /etc/networks -compact
125.It Pa /etc/networks
126.El
127.Sh DIAGNOSTICS
128Null pointer
129(0) returned on
130.Dv EOF
131or error.
132.Sh SEE ALSO
133.Xr networks 5
134.Sh HISTORY
135The
136.Fn getnetent ,
137.Fn getnetbyaddr ,
138.Fn getnetbyname ,
139.Fn setnetent ,
140and
141.Fn endnetent
142functions appeared in
143.Bx 4.2 .
144.Sh BUGS
145The data space used by
146these functions is static; if future use requires the data, it should be
147copied before any subsequent calls to these functions overwrite it.
148Only Internet network
149numbers are currently understood.
150Expecting network numbers to fit
151in no more than 32 bits is probably
152naive.
153