1getservent(3)              Library Functions Manual              getservent(3)
2
3
4

NAME

6       getservent,  getservbyname, getservbyport, setservent, endservent - get
7       service entry
8

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <netdb.h>
14
15       struct servent *getservent(void);
16
17       struct servent *getservbyname(const char *name, const char *proto);
18       struct servent *getservbyport(int port, const char *proto);
19
20       void setservent(int stayopen);
21       void endservent(void);
22

DESCRIPTION

24       The getservent() function reads the next entry from the services  data‐
25       base  (see  services(5)) and returns a servent structure containing the
26       broken-out fields from the entry.  A connection is opened to the  data‐
27       base if necessary.
28
29       The  getservbyname() function returns a servent structure for the entry
30       from the database that matches the service name using  protocol  proto.
31       If proto is NULL, any protocol will be matched.  A connection is opened
32       to the database if necessary.
33
34       The getservbyport() function returns a servent structure for the  entry
35       from the database that matches the port port (given in network byte or‐
36       der) using protocol proto.  If proto is  NULL,  any  protocol  will  be
37       matched.  A connection is opened to the database if necessary.
38
39       The  setservent() function opens a connection to the database, and sets
40       the next entry to the first entry.  If stayopen is  nonzero,  then  the
41       connection  to  the database will not be closed between calls to one of
42       the getserv*() functions.
43
44       The endservent() function closes the connection to the database.
45
46       The servent structure is defined in <netdb.h> as follows:
47
48           struct servent {
49               char  *s_name;       /* official service name */
50               char **s_aliases;    /* alias list */
51               int    s_port;       /* port number */
52               char  *s_proto;      /* protocol to use */
53           }
54
55       The members of the servent structure are:
56
57       s_name The official name of the service.
58
59       s_aliases
60              A NULL-terminated list of alternative names for the service.
61
62       s_port The port number for the service given in network byte order.
63
64       s_proto
65              The name of the protocol to use with this service.
66

RETURN VALUE

68       The getservent(), getservbyname(), and getservbyport() functions return
69       a  pointer  to  a statically allocated servent structure, or NULL if an
70       error occurs or the end of the file is reached.
71

FILES

73       /etc/services
74              services database file
75

ATTRIBUTES

77       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
78       tributes(7).
79
80       ┌────────────────┬───────────────┬─────────────────────────────────────┐
81Interface       Attribute     Value                               
82       ├────────────────┼───────────────┼─────────────────────────────────────┤
83getservent()    │ Thread safety │ MT-Unsafe race:servent              │
84       │                │               │ race:serventbuf locale              │
85       ├────────────────┼───────────────┼─────────────────────────────────────┤
86getservbyname() │ Thread safety │ MT-Unsafe race:servbyname locale    │
87       ├────────────────┼───────────────┼─────────────────────────────────────┤
88getservbyport() │ Thread safety │ MT-Unsafe race:servbyport locale    │
89       ├────────────────┼───────────────┼─────────────────────────────────────┤
90setservent(),   │ Thread safety │ MT-Unsafe race:servent locale       │
91endservent()    │               │                                     │
92       └────────────────┴───────────────┴─────────────────────────────────────┘
93       In  the  above  table, servent in race:servent signifies that if any of
94       the functions setservent(), getservent(), or endservent() are  used  in
95       parallel  in  different  threads  of  a  program, then data races could
96       occur.
97

STANDARDS

99       POSIX.1-2008.
100

HISTORY

102       POSIX.1-2001, 4.3BSD.
103

SEE ALSO

105       getnetent(3), getprotoent(3), getservent_r(3), services(5)
106
107
108
109Linux man-pages 6.05              2023-07-20                     getservent(3)
Impressum