]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/getservent.3
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex...
[thirdparty/man-pages.git] / man3 / getservent.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sat Jul 24 19:19:11 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Wed Oct 18 20:23:54 1995 by Martin Schulze <joey@infodrom.north.de>
29 .\" Modified Mon Apr 22 01:50:54 1996 by Martin Schulze <joey@infodrom.north.de>
30 .\" 2001-07-25 added a clause about NULL proto (Martin Michlmayr or David N. Welton)
31 .\"
32 .TH GETSERVENT 3 2008-08-19 "GNU" "Linux Programmer's Manual"
33 .SH NAME
34 getservent, getservbyname, getservbyport, setservent, endservent \-
35 get service entry
36 .SH SYNOPSIS
37 .nf
38 .B #include <netdb.h>
39 .sp
40 .B struct servent *getservent(void);
41 .sp
42 .BI "struct servent *getservbyname(const char *" name ", const char *" proto );
43 .sp
44 .BI "struct servent *getservbyport(int " port ", const char *" proto );
45 .sp
46 .BI "void setservent(int " stayopen );
47 .sp
48 .B void endservent(void);
49 .fi
50 .SH DESCRIPTION
51 The
52 .BR getservent ()
53 function reads the next entry from the services database (see
54 .BR services (5))
55 and returns a \fIservent\fP structure containing
56 the broken-out fields from the entry.
57 A connection is opened to the database if necessary.
58 .PP
59 The
60 .BR getservbyname ()
61 function returns a \fIservent\fP structure
62 for the entry from the database
63 that matches the service \fIname\fP using protocol \fIproto\fP.
64 If \fIproto\fP is NULL, any protocol will be matched.
65 A connection is opened to the database if necessary.
66 .PP
67 The
68 .BR getservbyport ()
69 function returns a \fIservent\fP structure
70 for the entry from the database
71 that matches the port \fIport\fP (given in network byte order)
72 using protocol \fIproto\fP.
73 If \fIproto\fP is NULL, any protocol will be matched.
74 A connection is opened to the database if necessary.
75 .PP
76 The
77 .BR setservent ()
78 function opens a connection to the database,
79 and sets the next entry to the first entry.
80 If \fIstayopen\fP is nonzero,
81 then the connection to the database
82 will not be closed between calls to one of the
83 .BR getserv* ()
84 functions.
85 .PP
86 The
87 .BR endservent ()
88 function closes the connection to the database.
89 .PP
90 The \fIservent\fP structure is defined in \fI<netdb.h>\fP as follows:
91 .sp
92 .in +4n
93 .nf
94 struct servent {
95 char *s_name; /* official service name */
96 char **s_aliases; /* alias list */
97 int s_port; /* port number */
98 char *s_proto; /* protocol to use */
99 }
100 .fi
101 .in
102 .PP
103 The members of the \fIservent\fP structure are:
104 .TP
105 .I s_name
106 The official name of the service.
107 .TP
108 .I s_aliases
109 A NULL-terminated list of alternative names for the service.
110 .TP
111 .I s_port
112 The port number for the service given in network byte order.
113 .TP
114 .I s_proto
115 The name of the protocol to use with this service.
116 .SH RETURN VALUE
117 The
118 .BR getservent (),
119 .BR getservbyname ()
120 and
121 .BR getservbyport ()
122 functions return a pointer to a
123 statically allocated \fIservent\fP structure, or a NULL pointer if an
124 error occurs or the end of the file is reached.
125 .SH FILES
126 .TP
127 .I /etc/services
128 services database file
129 .SH CONFORMING TO
130 4.3BSD, POSIX.1-2001.
131 .SH SEE ALSO
132 .BR getnetent (3),
133 .BR getprotoent (3),
134 .BR getservent_r (3),
135 .BR services (5)