mount_setattr.2: Further tweaks after feedback from Christian Brauner
[man-pages.git] / man3 / getservent.3
blobf778873ec84433b6cef882f90398771b733cff8b
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified Sat Jul 24 19:19:11 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified Wed Oct 18 20:23:54 1995 by Martin Schulze <joey@infodrom.north.de>
31 .\" Modified Mon Apr 22 01:50:54 1996 by Martin Schulze <joey@infodrom.north.de>
32 .\" 2001-07-25 added a clause about NULL proto (Martin Michlmayr or David N. Welton)
33 .\"
34 .TH GETSERVENT 3  2021-03-22 "GNU" "Linux Programmer's Manual"
35 .SH NAME
36 getservent, getservbyname, getservbyport, setservent, endservent \-
37 get service entry
38 .SH SYNOPSIS
39 .nf
40 .B #include <netdb.h>
41 .PP
42 .B struct servent *getservent(void);
43 .PP
44 .BI "struct servent *getservbyname(const char *" name ", const char *" proto );
45 .BI "struct servent *getservbyport(int " port ", const char *" proto );
46 .PP
47 .BI "void setservent(int " stayopen );
48 .B void endservent(void);
49 .fi
50 .SH DESCRIPTION
51 The
52 .BR getservent ()
53 function reads the next entry from the services database (see
54 .BR services (5))
55 and returns a
56 .I servent
57 structure containing
58 the broken-out fields from the entry.
59 A connection is opened to the database if necessary.
60 .PP
61 The
62 .BR getservbyname ()
63 function returns a
64 .I servent
65 structure
66 for the entry from the database
67 that matches the service
68 .I name
69 using protocol
70 .IR proto .
72 .I proto
73 is NULL, any protocol will be matched.
74 A connection is opened to the database if necessary.
75 .PP
76 The
77 .BR getservbyport ()
78 function returns a
79 .I servent
80 structure
81 for the entry from the database
82 that matches the port
83 .I port
84 (given in network byte order)
85 using protocol
86 .IR proto .
88 .I proto
89 is NULL, any protocol will be matched.
90 A connection is opened to the database if necessary.
91 .PP
92 The
93 .BR setservent ()
94 function opens a connection to the database,
95 and sets the next entry to the first entry.
97 .I stayopen
98 is nonzero,
99 then the connection to the database
100 will not be closed between calls to one of the
101 .BR getserv* ()
102 functions.
105 .BR endservent ()
106 function closes the connection to the database.
109 .I servent
110 structure is defined in
111 .I <netdb.h>
112 as follows:
114 .in +4n
116 struct servent {
117     char  *s_name;       /* official service name */
118     char **s_aliases;    /* alias list */
119     int    s_port;       /* port number */
120     char  *s_proto;      /* protocol to use */
125 The members of the
126 .I servent
127 structure are:
129 .I s_name
130 The official name of the service.
132 .I s_aliases
133 A NULL-terminated list of alternative names for the service.
135 .I s_port
136 The port number for the service given in network byte order.
138 .I s_proto
139 The name of the protocol to use with this service.
140 .SH RETURN VALUE
142 .BR getservent (),
143 .BR getservbyname (),
145 .BR getservbyport ()
146 functions return a pointer to a
147 statically allocated
148 .I servent
149 structure, or NULL if an
150 error occurs or the end of the file is reached.
151 .SH FILES
153 .I /etc/services
154 services database file
155 .SH ATTRIBUTES
156 For an explanation of the terms used in this section, see
157 .BR attributes (7).
158 .ad l
161 allbox;
162 lb lb lbx
163 l l l.
164 Interface       Attribute       Value
166 .BR getservent ()
167 T}      Thread safety   T{
168 MT-Unsafe race:servent
169 race:serventbuf locale
172 .BR getservbyname ()
173 T}      Thread safety   T{
174 MT-Unsafe race:servbyname
175 locale
178 .BR getservbyport ()
179 T}      Thread safety   T{
180 MT-Unsafe race:servbyport
181 locale
184 .BR setservent (),
185 .BR endservent ()
186 T}      Thread safety   T{
187 MT-Unsafe race:servent
188 locale
193 .sp 1
194 In the above table,
195 .I servent
197 .I race:servent
198 signifies that if any of the functions
199 .BR setservent (),
200 .BR getservent (),
202 .BR endservent ()
203 are used in parallel in different threads of a program,
204 then data races could occur.
205 .SH CONFORMING TO
206 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
207 .SH SEE ALSO
208 .BR getnetent (3),
209 .BR getprotoent (3),
210 .BR getservent_r (3),
211 .BR services (5)