OSDN Git Service

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