1GETNETENT(3) BSD Library Functions Manual GETNETENT(3)
2
4 getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent — get net‐
5 works entry
6
8 #include <netdb.h>
9
10 struct netent *
11 getnetent();
12
13 struct netent *
14 getnetbyname(char name);
15
16 struct netent *
17 getnetbyaddr(unsigned long net, int type);
18
19 void
20 setnetent(int stayopen);
21
22 void
23 endnetent();
24
26 The getnetent(), getnetbyname(), and getnetbyaddr() subroutines each
27 return a pointer to an object with the following structure containing the
28 broken-out fields of a line in the networks database.
29
30 struct netent {
31 char *n_name; /* official name of net */
32 char **n_aliases; /* alias list */
33 int n_addrtype; /* net number type */
34 long n_net; /* net number */
35 };
36
37 The members of this structure are:
38
39 n_name The official name of the network.
40
41 n_aliases A zero-terminated list of alternate names for the network.
42
43 n_addrtype The type of the network number returned: AF_INET.
44
45 n_net The network number. Network numbers are returned in machine
46 byte order.
47
48 If the stayopen flag on a setnetent() subroutine is NULL, the networks
49 database is opened. Otherwise, the setnetent() has the effect of rewind‐
50 ing the networks database. The endnetent() subroutine may be called to
51 close the networks database when processing is complete.
52
53 The getnetent() subroutine simply reads the next line while
54 getnetbyname() and getnetbyaddr() search until a matching name or net
55 number is found (or until EOF is encountered). The type must be AF_INET.
56 The getnetent() subroutine keeps a pointer in the database, allowing suc‐
57 cessive calls to be used to search the entire file.
58
59 Before a while loop using getnetent(), a call to setnetent() must be made
60 in order to perform initialization; a call to endnetent() must be used
61 after the loop. Both getnetbyname() and getnetbyaddr() make calls to
62 setnetent() and endnetent().
63
65 /etc/networks
66
68 Null pointer (0) returned on EOF or error.
69
71 networks(5), RFC 1101.
72
74 The getnetent(), getnetbyaddr(), getnetbyname(), setnetent(), and
75 endnetent() functions appeared in 4.2BSD.
76
78 The data space used by these functions is static; if future use requires
79 the data, it should be copied before any subsequent calls to these func‐
80 tions overwrite it. Only Internet network numbers are currently under‐
81 stood. Expecting network numbers to fit in no more than 32 bits is prob‐
82 ably naive.
83
844th Berkeley Distribution May 20, 1996 4th Berkeley Distribution