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       struct servent *getservbyport(int port, const char *proto);
16
17       void setservent(int stayopen);
18       void endservent(void);
19

DESCRIPTION

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

RETURN VALUE

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

FILES

70       /etc/services
71              services database file
72

ATTRIBUTES

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

CONFORMING TO

96       POSIX.1-2001, POSIX.1-2008, 4.3BSD.
97

SEE ALSO

99       getnetent(3), getprotoent(3), getservent_r(3), services(5)
100

COLOPHON

102       This page is part of release 5.12 of the Linux  man-pages  project.   A
103       description  of  the project, information about reporting bugs, and the
104       latest    version    of    this    page,    can     be     found     at
105       https://www.kernel.org/doc/man-pages/.
106
107
108
109GNU                               2021-03-22                     GETSERVENT(3)
Impressum