]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getservent.3
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man3 / getservent.3
CommitLineData
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
16getservent, getservbyname, getservbyport, setservent, endservent \-
c13182ef 17get service entry
42009080
AC
18.SH LIBRARY
19Standard 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
34The
35.BR getservent ()
01089ed5
MK
36function reads the next entry from the services database (see
37.BR services (5))
c6fa0841
MK
38and returns a
39.I servent
40structure containing
01089ed5
MK
41the broken-out fields from the entry.
42A connection is opened to the database if necessary.
fea681da 43.PP
60a90ecd
MK
44The
45.BR getservbyname ()
c6fa0841
MK
46function returns a
47.I servent
48structure
01089ed5 49for the entry from the database
c6fa0841
MK
50that matches the service
51.I name
52using protocol
53.IR proto .
54If
55.I proto
56is NULL, any protocol will be matched.
01089ed5 57A connection is opened to the database if necessary.
fea681da 58.PP
60a90ecd
MK
59The
60.BR getservbyport ()
c6fa0841
MK
61function returns a
62.I servent
63structure
01089ed5 64for the entry from the database
c6fa0841
MK
65that matches the port
66.I port
67(given in network byte order)
68using protocol
69.IR proto .
70If
71.I proto
72is NULL, any protocol will be matched.
01089ed5 73A connection is opened to the database if necessary.
fea681da 74.PP
60a90ecd
MK
75The
76.BR setservent ()
01089ed5
MK
77function opens a connection to the database,
78and sets the next entry to the first entry.
c6fa0841
MK
79If
80.I stayopen
81is nonzero,
01089ed5
MK
82then the connection to the database
83will not be closed between calls to one of the
84.BR getserv* ()
85functions.
fea681da 86.PP
60a90ecd
MK
87The
88.BR endservent ()
01089ed5 89function closes the connection to the database.
fea681da 90.PP
c6fa0841
MK
91The
92.I servent
93structure is defined in
94.I <netdb.h>
95as follows:
51f5698d 96.PP
bd191423 97.in +4n
b8302363 98.EX
fea681da 99struct 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
108The members of the
109.I servent
110structure are:
fea681da
MK
111.TP
112.I s_name
113The official name of the service.
114.TP
115.I s_aliases
01089ed5 116A NULL-terminated list of alternative names for the service.
fea681da
MK
117.TP
118.I s_port
119The port number for the service given in network byte order.
120.TP
121.I s_proto
122The name of the protocol to use with this service.
47297adb 123.SH RETURN VALUE
60a90ecd
MK
124The
125.BR getservent (),
d556548b 126.BR getservbyname (),
60a90ecd
MK
127and
128.BR getservbyport ()
23b21158 129functions return a pointer to a
c6fa0841
MK
130statically allocated
131.I servent
b437fdd9 132structure, or NULL if an
fea681da
MK
133error occurs or the end of the file is reached.
134.SH FILES
135.TP
136.I /etc/services
137services database file
9927122b
ZL
138.SH ATTRIBUTES
139For 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
144allbox;
c466875e 145lb lb lbx
9927122b
ZL
146l l l.
147Interface Attribute Value
148T{
149.BR getservent ()
150T} Thread safety T{
151MT-Unsafe race:servent
9927122b
ZL
152race:serventbuf locale
153T}
154T{
155.BR getservbyname ()
156T} Thread safety T{
157MT-Unsafe race:servbyname
9927122b
ZL
158locale
159T}
160T{
161.BR getservbyport ()
162T} Thread safety T{
163MT-Unsafe race:servbyport
9927122b
ZL
164locale
165T}
166T{
167.BR setservent (),
9927122b
ZL
168.BR endservent ()
169T} Thread safety T{
170MT-Unsafe race:servent
9927122b
ZL
171locale
172T}
173.TE
c466875e
MK
174.hy
175.ad
847e0d88 176.sp 1
9927122b
ZL
177In the above table,
178.I servent
179in
180.I race:servent
181signifies that if any of the functions
bf7bc8b8
MK
182.BR setservent (),
183.BR getservent (),
9927122b 184or
bf7bc8b8 185.BR endservent ()
9927122b
ZL
186are used in parallel in different threads of a program,
187then data races could occur.
3113c7f3 188.SH STANDARDS
87292ccb 189POSIX.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)