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