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 a NULL
69 pointer if an error occurs or the end of the file is reached.
70
72 /etc/services
73 services database file
74
76 4.3BSD, POSIX.1-2001.
77
79 getnetent(3), getprotoent(3), getservent_r(3), services(5)
80
82 This page is part of release 3.53 of the Linux man-pages project. A
83 description of the project, and information about reporting bugs, can
84 be found at http://www.kernel.org/doc/man-pages/.
85
86
87
88GNU 2008-08-19 GETSERVENT(3)