xref: /openbsd/lib/libc/net/getnetent.3 (revision 17df1aa7)
1.\"	$OpenBSD: getnetent.3,v 1.15 2007/05/31 19:19:30 jmc 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. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd $Mdocdate: May 31 2007 $
31.Dt GETNETENT 3
32.Os
33.Sh NAME
34.Nm getnetent ,
35.Nm getnetbyaddr ,
36.Nm getnetbyname ,
37.Nm setnetent ,
38.Nm endnetent
39.Nd get network entry
40.Sh SYNOPSIS
41.Fd #include <netdb.h>
42.Ft struct netent *
43.Fn getnetent "void"
44.Ft struct netent *
45.Fn getnetbyname "const char *name"
46.Ft struct netent *
47.Fn getnetbyaddr "in_addr_t net" "int type"
48.Ft void
49.Fn setnetent "int stayopen"
50.Ft void
51.Fn endnetent "void"
52.Sh DESCRIPTION
53The
54.Fn getnetent ,
55.Fn getnetbyname ,
56and
57.Fn getnetbyaddr
58functions each return a pointer to an object with the following structure
59containing the broken-out fields of a line in the network database,
60.Pa /etc/networks .
61.Bd -literal -offset indent
62struct	netent {
63	char		*n_name;	/* official name of net */
64	char		**n_aliases;	/* alias list */
65	int		n_addrtype;	/* net number type */
66	in_addr_t	n_net;		/* net number */
67};
68.Ed
69.Pp
70The members of this structure are:
71.Bl -tag -width n_addrtype
72.It Fa n_name
73The official name of the network.
74.It Fa n_aliases
75A null-terminated list of alternate names for the network.
76.It Fa n_addrtype
77The type of the network number returned; currently only
78.Dv AF_INET .
79.It Fa n_net
80The network number.
81Network numbers are returned in machine byte order.
82.El
83.Pp
84The
85.Fn getnetent
86function reads the next line of the file, opening the file if necessary.
87.Pp
88The
89.Fn setnetent
90function opens and rewinds the file.
91If the
92.Fa stayopen
93flag is non-zero,
94the net database will not be closed after each call to
95.Fn getnetbyname
96or
97.Fn getnetbyaddr .
98.Pp
99The
100.Fn endnetent
101function closes the file.
102.Pp
103The
104.Fn getnetbyname
105and
106.Fn getnetbyaddr
107functions search the domain name server if the system is configured to use one.
108If the search fails, or no name server is configured, they sequentially
109search from the beginning of the file until a matching net name or
110net address and type is found, or until
111.Dv EOF
112is encountered.
113Network numbers are supplied in host order.
114.Sh FILES
115.Bl -tag -width /etc/networks -compact
116.It Pa /etc/networks
117.El
118.Sh DIAGNOSTICS
119Null pointer (0) returned on
120.Dv EOF
121or error.
122.Sh SEE ALSO
123.Xr resolver 3 ,
124.Xr networks 5
125.Sh HISTORY
126The
127.Fn getnetent ,
128.Fn getnetbyaddr ,
129.Fn getnetbyname ,
130.Fn setnetent ,
131and
132.Fn endnetent
133functions appeared in
134.Bx 4.2 .
135.Sh BUGS
136The data space used by these functions is static; if future use
137requires the data, it should be copied before any subsequent calls
138to these functions overwrite it.
139Only Internet network numbers are currently understood.
140Expecting network numbers to fit in no more than 32 bits is naive.
141