1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
.\" $OpenBSD: getnetent.3,v 1.3 1998/06/15 17:56:16 mickey Exp $
.\" $From: getnetent.3,v 8.2 1996/05/09 05:59:10 vixie Exp $
.TH getnetent 3
.SH NAME
getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent \- get networks
entry
.SH SYNTAX
.nf
.B #include <netdb.h>
.PP
.B struct netent *getnetent()
.PP
.B struct netent *getnetbyname(\fIname\fP)
.B char *\fIname\fP;
.PP
.B struct netent *getnetbyaddr(\fInet\fP, \fItype\fP)
.B unsigned long \fInet\fP; int \fItype\fP;
.PP
.B void setnetent(\fIstayopen\fP)
.B int \fIstayopen\fP;
.PP
.B void endnetent()
.fi
.SH DESCRIPTION
The
.IR getnetent ,
.IR getnetbyname ,
and
.I getnetbyaddr
subroutines
each return a pointer to an object with the
following structure
containing the broken-out
fields of a line in the
.I networks
database.
.RS
.PP
.nf
struct netent {
char *n_name; /* official name of net */
char **n_aliases; /* alias list */
int n_addrtype; /* net number type */
long n_net; /* net number */
};
.ft R
.ad
.fi
.RE
.PP
The members of this structure are:
.TP \w'n_addrtype'u+2n
n_name
The official name of the network.
.TP \w'n_addrtype'u+2n
n_aliases
A zero terminated list of alternate names for the network.
.TP \w'n_addrtype'u+2n
n_addrtype
The type of the network number returned: AF_INET.
.TP \w'n_addrtype'u+2n
n_net
The network number. Network numbers are returned in machine byte
order.
.PP
If the
.I stayopen
flag on a
.I setnetent
subroutine is NULL, the
.I networks
database is opened. Otherwise the
.I setnetent
has the effect of rewinding the
.I networks
database.
The
.I endnetent
may be called to
close the
.I networks
database when processing is complete.
.PP
The
.I getnetent
subroutine simply reads the next
line while
.I getnetbyname
and
.I getnetbyaddr
search until a matching
.I name
or
.I net
number is found
(or until EOF is encountered). The \fItype\fP must be AF_INET.
The
.I getnetent
subroutine keeps a pointer in the database, allowing
successive calls to be used
to search the entire file.
.PP
A call to
.I setnetent
must be made before a
.I while
loop using
.I getnetent
in order to perform initialization and an
.I endnetent
must be used after the loop. Both
.I getnetbyname
and
.I getnetbyaddr
make calls to
.I setnetent
and
.I endnetent .
.SH FILES
.I /etc/networks
.SH DIAGNOSTICS
Null pointer (0) returned on EOF or error.
.SH SEE ALSO
.nf
networks(5)
RFC 1101
.SH HISTORY
The getnetent(), getnetbyaddr(), getnetbyname(), setnetent(), and
endnetent() functions appeared in
.Bx 4.2 .
.SH BUGS
The data space used by these functions is static; if future use requires the
data, it should be copied before any subsequent calls to these functions
overwrite it. Only Internet network numbers are currently understood.
Expecting network numbers to fit in no more than 32 bits is probably naive.
|