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 line from the file /etc/ser‐
24 vices and returns a structure servent containing the broken out fields
25 from the line. The /etc/services file is opened if necessary.
26
27 The getservbyname() function returns a servent structure for the line
28 from /etc/services that matches the service name using protocol proto.
29 If proto is NULL, any protocol will be matched.
30
31 The getservbyport() function returns a servent structure for the line
32 that matches the port port given in network byte order using protocol
33 proto. If proto is NULL, any protocol will be matched.
34
35 The setservent() function opens and rewinds the /etc/services file. If
36 stayopen is true (1), then the file will not be closed between calls to
37 getservbyname() and getservbyport().
38
39 The endservent() function closes /etc/services.
40
41 The servent structure is defined in <netdb.h> as follows:
42
43 struct servent {
44 char *s_name; /* official service name */
45 char **s_aliases; /* alias list */
46 int s_port; /* port number */
47 char *s_proto; /* protocol to use */
48 }
49
50 The members of the servent structure are:
51
52 s_name The official name of the service.
53
54 s_aliases
55 A zero terminated list of alternative names for the service.
56
57 s_port The port number for the service given in network byte order.
58
59 s_proto
60 The name of the protocol to use with this service.
61
63 The getservent(), getservbyname() and getservbyport() functions return
64 the servent structure, or a NULL pointer if an error occurs or the end
65 of the file is reached.
66
68 /etc/services
69 services database file
70
72 4.3BSD, POSIX.1-2001.
73
75 getnetent(3), getprotoent(3), services(5)
76
77
78
79BSD 2001-07-25 GETSERVENT(3)