]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
5fbde956 | 3 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
4 | .\" |
5 | .\" References consulted: | |
6 | .\" Linux libc source code | |
7 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
8 | .\" 386BSD man pages | |
9 | .\" Modified Sat Jul 24 19:19:11 1993 by Rik Faith (faith@cs.unc.edu) | |
10 | .\" Modified Wed Oct 18 20:23:54 1995 by Martin Schulze <joey@infodrom.north.de> | |
11 | .\" Modified Mon Apr 22 01:50:54 1996 by Martin Schulze <joey@infodrom.north.de> | |
12 | .\" 2001-07-25 added a clause about NULL proto (Martin Michlmayr or David N. Welton) | |
13 | .\" | |
4c1c5274 | 14 | .TH getservent 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
15 | .SH NAME |
16 | getservent, getservbyname, getservbyport, setservent, endservent \- | |
c13182ef | 17 | get service entry |
42009080 AC |
18 | .SH LIBRARY |
19 | Standard C library | |
20 | .RI ( libc ", " \-lc ) | |
fea681da MK |
21 | .SH SYNOPSIS |
22 | .nf | |
23 | .B #include <netdb.h> | |
68e4db0a | 24 | .PP |
fea681da | 25 | .B struct servent *getservent(void); |
68e4db0a | 26 | .PP |
fea681da | 27 | .BI "struct servent *getservbyname(const char *" name ", const char *" proto ); |
fea681da | 28 | .BI "struct servent *getservbyport(int " port ", const char *" proto ); |
68e4db0a | 29 | .PP |
fea681da | 30 | .BI "void setservent(int " stayopen ); |
fea681da MK |
31 | .B void endservent(void); |
32 | .fi | |
33 | .SH DESCRIPTION | |
60a90ecd MK |
34 | The |
35 | .BR getservent () | |
01089ed5 MK |
36 | function reads the next entry from the services database (see |
37 | .BR services (5)) | |
c6fa0841 MK |
38 | and returns a |
39 | .I servent | |
40 | structure containing | |
01089ed5 MK |
41 | the broken-out fields from the entry. |
42 | A connection is opened to the database if necessary. | |
fea681da | 43 | .PP |
60a90ecd MK |
44 | The |
45 | .BR getservbyname () | |
c6fa0841 MK |
46 | function returns a |
47 | .I servent | |
48 | structure | |
01089ed5 | 49 | for the entry from the database |
c6fa0841 MK |
50 | that matches the service |
51 | .I name | |
52 | using protocol | |
53 | .IR proto . | |
54 | If | |
55 | .I proto | |
56 | is NULL, any protocol will be matched. | |
01089ed5 | 57 | A connection is opened to the database if necessary. |
fea681da | 58 | .PP |
60a90ecd MK |
59 | The |
60 | .BR getservbyport () | |
c6fa0841 MK |
61 | function returns a |
62 | .I servent | |
63 | structure | |
01089ed5 | 64 | for the entry from the database |
c6fa0841 MK |
65 | that matches the port |
66 | .I port | |
67 | (given in network byte order) | |
68 | using protocol | |
69 | .IR proto . | |
70 | If | |
71 | .I proto | |
72 | is NULL, any protocol will be matched. | |
01089ed5 | 73 | A connection is opened to the database if necessary. |
fea681da | 74 | .PP |
60a90ecd MK |
75 | The |
76 | .BR setservent () | |
01089ed5 MK |
77 | function opens a connection to the database, |
78 | and sets the next entry to the first entry. | |
c6fa0841 MK |
79 | If |
80 | .I stayopen | |
81 | is nonzero, | |
01089ed5 MK |
82 | then the connection to the database |
83 | will not be closed between calls to one of the | |
84 | .BR getserv* () | |
85 | functions. | |
fea681da | 86 | .PP |
60a90ecd MK |
87 | The |
88 | .BR endservent () | |
01089ed5 | 89 | function closes the connection to the database. |
fea681da | 90 | .PP |
c6fa0841 MK |
91 | The |
92 | .I servent | |
93 | structure is defined in | |
94 | .I <netdb.h> | |
95 | as follows: | |
51f5698d | 96 | .PP |
bd191423 | 97 | .in +4n |
b8302363 | 98 | .EX |
fea681da | 99 | struct servent { |
7295b7ed MK |
100 | char *s_name; /* official service name */ |
101 | char **s_aliases; /* alias list */ | |
102 | int s_port; /* port number */ | |
103 | char *s_proto; /* protocol to use */ | |
fea681da | 104 | } |
b8302363 | 105 | .EE |
bd191423 | 106 | .in |
fea681da | 107 | .PP |
c6fa0841 MK |
108 | The members of the |
109 | .I servent | |
110 | structure are: | |
fea681da MK |
111 | .TP |
112 | .I s_name | |
113 | The official name of the service. | |
114 | .TP | |
115 | .I s_aliases | |
01089ed5 | 116 | A NULL-terminated list of alternative names for the service. |
fea681da MK |
117 | .TP |
118 | .I s_port | |
119 | The port number for the service given in network byte order. | |
120 | .TP | |
121 | .I s_proto | |
122 | The name of the protocol to use with this service. | |
47297adb | 123 | .SH RETURN VALUE |
60a90ecd MK |
124 | The |
125 | .BR getservent (), | |
d556548b | 126 | .BR getservbyname (), |
60a90ecd MK |
127 | and |
128 | .BR getservbyport () | |
23b21158 | 129 | functions return a pointer to a |
c6fa0841 MK |
130 | statically allocated |
131 | .I servent | |
b437fdd9 | 132 | structure, or NULL if an |
fea681da MK |
133 | error occurs or the end of the file is reached. |
134 | .SH FILES | |
135 | .TP | |
136 | .I /etc/services | |
137 | services database file | |
9927122b ZL |
138 | .SH ATTRIBUTES |
139 | For an explanation of the terms used in this section, see | |
140 | .BR attributes (7). | |
c466875e MK |
141 | .ad l |
142 | .nh | |
9927122b ZL |
143 | .TS |
144 | allbox; | |
c466875e | 145 | lb lb lbx |
9927122b ZL |
146 | l l l. |
147 | Interface Attribute Value | |
148 | T{ | |
149 | .BR getservent () | |
150 | T} Thread safety T{ | |
151 | MT-Unsafe race:servent | |
9927122b ZL |
152 | race:serventbuf locale |
153 | T} | |
154 | T{ | |
155 | .BR getservbyname () | |
156 | T} Thread safety T{ | |
157 | MT-Unsafe race:servbyname | |
9927122b ZL |
158 | locale |
159 | T} | |
160 | T{ | |
161 | .BR getservbyport () | |
162 | T} Thread safety T{ | |
163 | MT-Unsafe race:servbyport | |
9927122b ZL |
164 | locale |
165 | T} | |
166 | T{ | |
167 | .BR setservent (), | |
9927122b ZL |
168 | .BR endservent () |
169 | T} Thread safety T{ | |
170 | MT-Unsafe race:servent | |
9927122b ZL |
171 | locale |
172 | T} | |
173 | .TE | |
c466875e MK |
174 | .hy |
175 | .ad | |
847e0d88 | 176 | .sp 1 |
9927122b ZL |
177 | In the above table, |
178 | .I servent | |
179 | in | |
180 | .I race:servent | |
181 | signifies that if any of the functions | |
bf7bc8b8 MK |
182 | .BR setservent (), |
183 | .BR getservent (), | |
9927122b | 184 | or |
bf7bc8b8 | 185 | .BR endservent () |
9927122b ZL |
186 | are used in parallel in different threads of a program, |
187 | then data races could occur. | |
3113c7f3 | 188 | .SH STANDARDS |
87292ccb | 189 | POSIX.1-2001, POSIX.1-2008, 4.3BSD. |
47297adb | 190 | .SH SEE ALSO |
fea681da MK |
191 | .BR getnetent (3), |
192 | .BR getprotoent (3), | |
23b21158 | 193 | .BR getservent_r (3), |
fea681da | 194 | .BR services (5) |