1GETSERVENT(3) Linux Programmer's Manual GETSERVENT(3)
2
3
4
6 getservent, getservbyname, getservbyport, setservent, endservent - get
7 service entry
8
10 #include <netdb.h>
11
12 struct servent *getservent(void);
13
14 struct servent *getservbyname(const char *name, const char *proto);
15
16 struct servent *getservbyport(int port, const char *proto);
17
18 void setservent(int stayopen);
19
20 void endservent(void);
21
23 The getservent() function reads the next entry from the services data‐
24 base (see services(5)) and returns a servent structure containing the
25 broken-out fields from the entry. A connection is opened to the data‐
26 base if necessary.
27
28 The getservbyname() function returns a servent structure for the entry
29 from the database that matches the service name using protocol proto.
30 If proto is NULL, any protocol will be matched. A connection is opened
31 to the database if necessary.
32
33 The getservbyport() function returns a servent structure for the entry
34 from the database that matches the port port (given in network byte
35 order) using protocol proto. If proto is NULL, any protocol will be
36 matched. A connection is opened to the database if necessary.
37
38 The setservent() function opens a connection to the database, and sets
39 the next entry to the first entry. If stayopen is nonzero, then the
40 connection to the database will not be closed between calls to one of
41 the getserv*() functions.
42
43 The endservent() function closes the connection to the database.
44
45 The servent structure is defined in <netdb.h> as follows:
46
47 struct servent {
48 char *s_name; /* official service name */
49 char **s_aliases; /* alias list */
50 int s_port; /* port number */
51 char *s_proto; /* protocol to use */
52 }
53
54 The members of the servent structure are:
55
56 s_name The official name of the service.
57
58 s_aliases
59 A NULL-terminated list of alternative names for the service.
60
61 s_port The port number for the service given in network byte order.
62
63 s_proto
64 The name of the protocol to use with this service.
65
67 The getservent(), getservbyname() and getservbyport() functions return
68 a pointer to a statically allocated servent structure, or NULL if an
69 error occurs or the end of the file is reached.
70
72 /etc/services
73 services database file
74
76 For an explanation of the terms used in this section, see
77 attributes(7).
78
79 ┌────────────────┬───────────────┬───────────────────────────┐
80 │Interface │ Attribute │ Value │
81 ├────────────────┼───────────────┼───────────────────────────┤
82 │getservent() │ Thread safety │ MT-Unsafe race:servent │
83 │ │ │ race:serventbuf locale │
84 ├────────────────┼───────────────┼───────────────────────────┤
85 │getservbyname() │ Thread safety │ MT-Unsafe race:servbyname │
86 │ │ │ locale │
87 ├────────────────┼───────────────┼───────────────────────────┤
88 │getservbyport() │ Thread safety │ MT-Unsafe race:servbyport │
89 │ │ │ locale │
90 ├────────────────┼───────────────┼───────────────────────────┤
91 │setservent(), │ Thread safety │ MT-Unsafe race:servent │
92 │endservent() │ │ locale │
93 └────────────────┴───────────────┴───────────────────────────┘
94 In the above table, servent in race:servent signifies that if any of
95 the functions setservent(), getservent(), or endservent() are used in
96 parallel in different threads of a program, then data races could
97 occur.
98
100 POSIX.1-2001, POSIX.1-2008, 4.3BSD.
101
103 getnetent(3), getprotoent(3), getservent_r(3), services(5)
104
106 This page is part of release 4.15 of the Linux man-pages project. A
107 description of the project, information about reporting bugs, and the
108 latest version of this page, can be found at
109 https://www.kernel.org/doc/man-pages/.
110
111
112
113GNU 2017-09-15 GETSERVENT(3)