1getnetent(3) Library Functions Manual getnetent(3)
2
3
4
6 getnetent, getnetbyname, getnetbyaddr, setnetent, endnetent - get net‐
7 work entry
8
10 Standard C library (libc, -lc)
11
13 #include <netdb.h>
14
15 struct netent *getnetent(void);
16
17 struct netent *getnetbyname(const char *name);
18 struct netent *getnetbyaddr(uint32_t net, int type);
19
20 void setnetent(int stayopen);
21 void endnetent(void);
22
24 The getnetent() function reads the next entry from the networks data‐
25 base and returns a netent structure containing the broken-out fields
26 from the entry. A connection is opened to the database if necessary.
27
28 The getnetbyname() function returns a netent structure for the entry
29 from the database that matches the network name.
30
31 The getnetbyaddr() function returns a netent structure for the entry
32 from the database that matches the network number net of type type.
33 The net argument must be in host byte order.
34
35 The setnetent() function opens a connection to the database, and sets
36 the next entry to the first entry. If stayopen is nonzero, then the
37 connection to the database will not be closed between calls to one of
38 the getnet*() functions.
39
40 The endnetent() function closes the connection to the database.
41
42 The netent structure is defined in <netdb.h> as follows:
43
44 struct netent {
45 char *n_name; /* official network name */
46 char **n_aliases; /* alias list */
47 int n_addrtype; /* net address type */
48 uint32_t n_net; /* network number */
49 }
50
51 The members of the netent structure are:
52
53 n_name The official name of the network.
54
55 n_aliases
56 A NULL-terminated list of alternative names for the network.
57
58 n_addrtype
59 The type of the network number; always AF_INET.
60
61 n_net The network number in host byte order.
62
64 The getnetent(), getnetbyname(), and getnetbyaddr() functions return a
65 pointer to a statically allocated netent structure, or a null pointer
66 if an error occurs or the end of the file is reached.
67
69 /etc/networks
70 networks database file
71
73 For an explanation of the terms used in this section, see at‐
74 tributes(7).
75
76 ┌───────────────┬───────────────┬──────────────────────────────────────┐
77 │Interface │ Attribute │ Value │
78 ├───────────────┼───────────────┼──────────────────────────────────────┤
79 │getnetent() │ Thread safety │ MT-Unsafe race:netent race:netentbuf │
80 │ │ │ env locale │
81 ├───────────────┼───────────────┼──────────────────────────────────────┤
82 │getnetbyname() │ Thread safety │ MT-Unsafe race:netbyname env locale │
83 ├───────────────┼───────────────┼──────────────────────────────────────┤
84 │getnetbyaddr() │ Thread safety │ MT-Unsafe race:netbyaddr locale │
85 ├───────────────┼───────────────┼──────────────────────────────────────┤
86 │setnetent(), │ Thread safety │ MT-Unsafe race:netent env locale │
87 │endnetent() │ │ │
88 └───────────────┴───────────────┴──────────────────────────────────────┘
89 In the above table, netent in race:netent signifies that if any of the
90 functions setnetent(), getnetent(), or endnetent() are used in parallel
91 in different threads of a program, then data races could occur.
92
94 POSIX.1-2008.
95
97 POSIX.1-2001, 4.3BSD.
98
99 Before glibc 2.2, the net argument of getnetbyaddr() was of type long.
100
102 getnetent_r(3), getprotoent(3), getservent(3)
103 RFC 1101
104
105
106
107Linux man-pages 6.05 2023-07-20 getnetent(3)