]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getservent.3
user_namespaces.7: Minor rewordings of recently added text
[thirdparty/man-pages.git] / man3 / getservent.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
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.\"
4b8c67d9 34.TH GETSERVENT 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
35.SH NAME
36getservent, getservbyname, getservbyport, setservent, endservent \-
c13182ef 37get service entry
fea681da
MK
38.SH SYNOPSIS
39.nf
40.B #include <netdb.h>
68e4db0a 41.PP
fea681da 42.B struct servent *getservent(void);
68e4db0a 43.PP
fea681da 44.BI "struct servent *getservbyname(const char *" name ", const char *" proto );
68e4db0a 45.PP
fea681da 46.BI "struct servent *getservbyport(int " port ", const char *" proto );
68e4db0a 47.PP
fea681da 48.BI "void setservent(int " stayopen );
68e4db0a 49.PP
fea681da
MK
50.B void endservent(void);
51.fi
52.SH DESCRIPTION
60a90ecd
MK
53The
54.BR getservent ()
01089ed5
MK
55function reads the next entry from the services database (see
56.BR services (5))
c6fa0841
MK
57and returns a
58.I servent
59structure containing
01089ed5
MK
60the broken-out fields from the entry.
61A connection is opened to the database if necessary.
fea681da 62.PP
60a90ecd
MK
63The
64.BR getservbyname ()
c6fa0841
MK
65function returns a
66.I servent
67structure
01089ed5 68for the entry from the database
c6fa0841
MK
69that matches the service
70.I name
71using protocol
72.IR proto .
73If
74.I proto
75is NULL, any protocol will be matched.
01089ed5 76A connection is opened to the database if necessary.
fea681da 77.PP
60a90ecd
MK
78The
79.BR getservbyport ()
c6fa0841
MK
80function returns a
81.I servent
82structure
01089ed5 83for the entry from the database
c6fa0841
MK
84that matches the port
85.I port
86(given in network byte order)
87using protocol
88.IR proto .
89If
90.I proto
91is NULL, any protocol will be matched.
01089ed5 92A connection is opened to the database if necessary.
fea681da 93.PP
60a90ecd
MK
94The
95.BR setservent ()
01089ed5
MK
96function opens a connection to the database,
97and sets the next entry to the first entry.
c6fa0841
MK
98If
99.I stayopen
100is nonzero,
01089ed5
MK
101then the connection to the database
102will not be closed between calls to one of the
103.BR getserv* ()
104functions.
fea681da 105.PP
60a90ecd
MK
106The
107.BR endservent ()
01089ed5 108function closes the connection to the database.
fea681da 109.PP
c6fa0841
MK
110The
111.I servent
112structure is defined in
113.I <netdb.h>
114as follows:
51f5698d 115.PP
bd191423 116.in +4n
b8302363 117.EX
fea681da 118struct servent {
7295b7ed
MK
119 char *s_name; /* official service name */
120 char **s_aliases; /* alias list */
121 int s_port; /* port number */
122 char *s_proto; /* protocol to use */
fea681da 123}
b8302363 124.EE
bd191423 125.in
fea681da 126.PP
c6fa0841
MK
127The members of the
128.I servent
129structure are:
fea681da
MK
130.TP
131.I s_name
132The official name of the service.
133.TP
134.I s_aliases
01089ed5 135A NULL-terminated list of alternative names for the service.
fea681da
MK
136.TP
137.I s_port
138The port number for the service given in network byte order.
139.TP
140.I s_proto
141The name of the protocol to use with this service.
47297adb 142.SH RETURN VALUE
60a90ecd
MK
143The
144.BR getservent (),
145.BR getservbyname ()
146and
147.BR getservbyport ()
23b21158 148functions return a pointer to a
c6fa0841
MK
149statically allocated
150.I servent
b437fdd9 151structure, or NULL if an
fea681da
MK
152error occurs or the end of the file is reached.
153.SH FILES
154.TP
155.I /etc/services
156services database file
9927122b
ZL
157.SH ATTRIBUTES
158For an explanation of the terms used in this section, see
159.BR attributes (7).
160.TS
161allbox;
162lbw15 lb lbw25
163l l l.
164Interface Attribute Value
165T{
166.BR getservent ()
167T} Thread safety T{
168MT-Unsafe race:servent
169.br
170race:serventbuf locale
171T}
172T{
173.BR getservbyname ()
174T} Thread safety T{
175MT-Unsafe race:servbyname
176.br
177locale
178T}
179T{
180.BR getservbyport ()
181T} Thread safety T{
182MT-Unsafe race:servbyport
183.br
184locale
185T}
186T{
187.BR setservent (),
188.br
189.BR endservent ()
190T} Thread safety T{
191MT-Unsafe race:servent
192.br
193locale
194T}
195.TE
847e0d88 196.sp 1
9927122b
ZL
197In the above table,
198.I servent
199in
200.I race:servent
201signifies that if any of the functions
bf7bc8b8
MK
202.BR setservent (),
203.BR getservent (),
9927122b 204or
bf7bc8b8 205.BR endservent ()
9927122b
ZL
206are used in parallel in different threads of a program,
207then data races could occur.
47297adb 208.SH CONFORMING TO
87292ccb 209POSIX.1-2001, POSIX.1-2008, 4.3BSD.
47297adb 210.SH SEE ALSO
fea681da
MK
211.BR getnetent (3),
212.BR getprotoent (3),
23b21158 213.BR getservent_r (3),
fea681da 214.BR services (5)