xref: /freebsd/lib/libc/net/getnetent.3 (revision e5b786625f7f82a1fa91e41823332459ea5550f9)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  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. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)getnetent.3	8.1 (Berkeley) 6/4/93
29.\"
30.Dd June 27, 2022
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 LIBRARY
41.Lb libc
42.Sh SYNOPSIS
43.In netdb.h
44.Ft struct netent *
45.Fn getnetent void
46.Ft struct netent *
47.Fn getnetbyname "const char *name"
48.Ft struct netent *
49.Fn getnetbyaddr "uint32_t net" "int type"
50.Ft void
51.Fn setnetent "int stayopen"
52.Ft void
53.Fn endnetent void
54.Ft int
55.Fn getnetent_r "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errnop"
56.Ft int
57.Fn getnetbyaddr_r "uint32_t net" "int type" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" int *h_errorp"
58.Ft int
59.Fn getnetbyname_r "const char *name" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errorp"
60.Sh DESCRIPTION
61The
62.Fn getnetent ,
63.Fn getnetbyname ,
64and
65.Fn getnetbyaddr
66functions
67each return a pointer to an object with the
68following structure describing an internet network.
69This structure contains either the information obtained
70from the nameserver, broken-out fields of a line in the network data base
71.Pa /etc/networks ,
72or entries supplied by the
73.Xr yp 8
74system.
75The order of the lookups is controlled by the
76`networks' entry in
77.Xr nsswitch.conf 5 .
78.Bd -literal -offset indent
79struct netent {
80	char		*n_name;	/* official name of net */
81	char		**n_aliases;	/* alias list */
82	int		n_addrtype;	/* net number type */
83	uint32_t	n_net;		/* net number */
84};
85.Ed
86.Pp
87The members of this structure are:
88.Bl -tag -width n_addrtype
89.It Fa n_name
90The official name of the network.
91.It Fa n_aliases
92A zero terminated list of alternate names for the network.
93.It Fa n_addrtype
94The type of the network number returned; currently only AF_INET.
95.It Fa n_net
96The network number.
97Network numbers are returned in machine byte
98order.
99.El
100.Pp
101The
102.Fn getnetent
103function
104reads the next line of the file, opening the file if necessary.
105.Pp
106The
107.Fn setnetent
108function
109opens and rewinds the file.
110If the
111.Fa stayopen
112flag is non-zero,
113the net data base will not be closed after each call to
114.Fn getnetbyname
115or
116.Fn getnetbyaddr .
117.Pp
118The
119.Fn endnetent
120function
121closes the file.
122.Pp
123The
124.Fn getnetbyname
125function
126and
127.Fn getnetbyaddr
128sequentially search from the beginning
129of the file until a matching
130net name or
131net address and type is found,
132or until
133.Dv EOF
134is encountered.
135The
136.Fa type
137argument
138must be
139.Dv AF_INET .
140Network numbers are supplied in host order.
141.Pp
142Functions with the
143.Em _r
144suffix provide reentrant versions of their respective counterparts.
145The caller must supply five additional parameters: a
146.Vt struct netent
147variable to be filled on success, a
148.Va buffer
149of
150.Va buflen
151bytes in size, a
152.Vt struct netent
153.Va result
154variable that will point to the result on success or be set to
155.Dv NULL
156on failure or if the name is not found.
157The
158.Va h_errnop
159variable will be filled with the error code if any.
160All these functions return 0 on success.
161.Sh FILES
162.Bl -tag -width /etc/nsswitch.conf -compact
163.It Pa /etc/networks
164.It Pa /etc/nsswitch.conf
165.It Pa /etc/resolv.conf
166.El
167.Sh DIAGNOSTICS
168Null pointer returned on
169.Dv EOF
170or error.
171.Sh SEE ALSO
172.Xr networks 5
173.Pp
174.%T RFC 1101
175.Sh HISTORY
176The
177.Fn getnetent ,
178.Fn getnetbyaddr ,
179.Fn getnetbyname ,
180.Fn setnetent ,
181and
182.Fn endnetent
183functions appeared in
184.Bx 4.2 .
185.Sh BUGS
186The data space used by
187these functions is thread-specific; if future use requires the data, it should be
188copied before any subsequent calls to these functions overwrite it.
189Only Internet network
190numbers are currently understood.
191Expecting network numbers to fit
192in no more than 32 bits is probably
193naive.
194