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