Debian Codegraph @

upstream/debian-unstable/man3/getnetent.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH getnetent 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 getnetent, getnetbyname, getnetbyaddr, setnetent, endnetent \-
10 get network entry
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <netdb.h>
17 .P
18 .B struct netent *getnetent(void);
19 .P
20 .BI "struct netent *getnetbyname(const char *" name );
21 .BI "struct netent *getnetbyaddr(uint32_t " net ", int " type );
22 .P
23 .BI "void setnetent(int " stayopen );
24 .B void endnetent(void);
25 .fi
26 .SH DESCRIPTION
27 The
28 .BR getnetent ()
29 function reads the next entry from the networks database
30 and returns a
31 .I netent
32 structure containing
33 the broken-out fields from the entry.
34 A connection is opened to the database if necessary.
35 .P
36 The
37 .BR getnetbyname ()
38 function returns a
39 .I netent
40 structure
41 for the entry from the database
42 that matches the network
43 .IR name .
44 .P
45 The
46 .BR getnetbyaddr ()
47 function returns a
48 .I netent
49 structure
50 for the entry from the database
51 that matches the network number
52 .I net
53 of type
54 .IR type .
55 The
56 .I net
57 argument must be in host byte order.
58 .P
59 The
60 .BR setnetent ()
61 function opens a connection to the database,
62 and sets the next entry to the first entry.
63 If
64 .I stayopen
65 is nonzero,
66 then the connection to the database
67 will not be closed between calls to one of the
68 .BR getnet* ()
69 functions.
70 .P
71 The
72 .BR endnetent ()
73 function closes the connection to the database.
74 .P
75 The
76 .I netent
77 structure is defined in
78 .I <netdb.h>
79 as follows:
80 .P
81 .in +4n
82 .EX
83 struct netent {
84 char *n_name; /* official network name */
85 char **n_aliases; /* alias list */
86 int n_addrtype; /* net address type */
87 uint32_t n_net; /* network number */
88 }
89 .EE
90 .in
91 .P
92 The members of the
93 .I netent
94 structure are:
95 .TP
96 .I n_name
97 The official name of the network.
98 .TP
99 .I n_aliases
100 A NULL-terminated list of alternative names for the network.
101 .TP
102 .I n_addrtype
103 The type of the network number;
104 always
105 .BR AF_INET .
106 .TP
107 .I n_net
108 The network number in host byte order.
109 .SH RETURN VALUE
110 The
111 .BR getnetent (),
112 .BR getnetbyname (),
113 and
114 .BR getnetbyaddr ()
115 functions return a pointer to a
116 statically allocated
117 .I netent
118 structure, or a null pointer if an
119 error occurs or the end of the file is reached.
120 .SH FILES
121 .TP
122 .I /etc/networks
123 networks database file
124 .SH ATTRIBUTES
125 For an explanation of the terms used in this section, see
126 .BR attributes (7).
127 .TS
128 allbox;
129 lb lb lbx
130 l l l.
131 Interface Attribute Value
132 T{
133 .na
134 .nh
135 .BR getnetent ()
136 T} Thread safety T{
137 .na
138 .nh
139 MT-Unsafe race:netent
140 race:netentbuf env locale
141 T}
142 T{
143 .na
144 .nh
145 .BR getnetbyname ()
146 T} Thread safety T{
147 .na
148 .nh
149 MT-Unsafe race:netbyname
150 env locale
151 T}
152 T{
153 .na
154 .nh
155 .BR getnetbyaddr ()
156 T} Thread safety T{
157 .na
158 .nh
159 MT-Unsafe race:netbyaddr
160 locale
161 T}
162 T{
163 .na
164 .nh
165 .BR setnetent (),
166 .BR endnetent ()
167 T} Thread safety T{
168 .na
169 .nh
170 MT-Unsafe race:netent env
171 locale
172 T}
173 .TE
174 .P
175 In the above table,
176 .I netent
177 in
178 .I race:netent
179 signifies that if any of the functions
180 .BR setnetent (),
181 .BR getnetent (),
182 or
183 .BR endnetent ()
184 are used in parallel in different threads of a program,
185 then data races could occur.
186 .SH STANDARDS
187 POSIX.1-2008.
188 .SH HISTORY
189 POSIX.1-2001, 4.3BSD.
190 .P
191 Before glibc 2.2, the
192 .I net
193 argument of
194 .BR getnetbyaddr ()
195 was of type
196 .IR long .
197 .SH SEE ALSO
198 .BR getnetent_r (3),
199 .BR getprotoent (3),
200 .BR getservent (3)
201 .\" .BR networks (5)
202 .br
203 RFC\ 1101