1GETSERVENT(3)              Linux Programmer's Manual             GETSERVENT(3)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

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 or‐
35       der) 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

RETURN VALUE

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

FILES

72       /etc/services
73              services database file
74

ATTRIBUTES

76       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
77       tributes(7).
78
79       ┌────────────────┬───────────────┬───────────────────────────┐
80Interface       Attribute     Value                     
81       ├────────────────┼───────────────┼───────────────────────────┤
82getservent()    │ Thread safety │ MT-Unsafe race:servent    │
83       │                │               │ race:serventbuf locale    │
84       ├────────────────┼───────────────┼───────────────────────────┤
85getservbyname() │ Thread safety │ MT-Unsafe race:servbyname │
86       │                │               │ locale                    │
87       ├────────────────┼───────────────┼───────────────────────────┤
88getservbyport() │ Thread safety │ MT-Unsafe race:servbyport │
89       │                │               │ locale                    │
90       ├────────────────┼───────────────┼───────────────────────────┤
91setservent(),   │ Thread safety │ MT-Unsafe race:servent    │
92endservent()    │               │ 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 oc‐
97       cur.
98

CONFORMING TO

100       POSIX.1-2001, POSIX.1-2008, 4.3BSD.
101

SEE ALSO

103       getnetent(3), getprotoent(3), getservent_r(3), services(5)
104

COLOPHON

106       This page is part of release 5.10 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                               2020-12-21                     GETSERVENT(3)
Impressum