summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getservent.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/getservent.3')
-rw-r--r--src/lib/libc/net/getservent.3163
1 files changed, 113 insertions, 50 deletions
diff --git a/src/lib/libc/net/getservent.3 b/src/lib/libc/net/getservent.3
index 9e0656be00..7888b5f1b8 100644
--- a/src/lib/libc/net/getservent.3
+++ b/src/lib/libc/net/getservent.3
@@ -1,4 +1,4 @@
1.\" $NetBSD: getservent.3,v 1.3 1995/02/25 06:20:38 cgd Exp $ 1.\" $OpenBSD: getservent.3,v 1.20 2007/05/31 19:19:30 jmc Exp $
2.\" 2.\"
3.\" Copyright (c) 1983, 1991, 1993 3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
@@ -11,11 +11,7 @@
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software 14.\" 3. Neither the name of the University nor the names of its contributors
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software 15.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission. 16.\" without specific prior written permission.
21.\" 17.\"
@@ -31,41 +27,51 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 28.\" SUCH DAMAGE.
33.\" 29.\"
34.\" @(#)getservent.3 8.3 (Berkeley) 1/12/94 30.Dd $Mdocdate: May 31 2007 $
35.\"
36.Dd January 12, 1994
37.Dt GETSERVENT 3 31.Dt GETSERVENT 3
38.Os BSD 4.2 32.Os
39.Sh NAME 33.Sh NAME
40.Nm getservent , 34.Nm getservent ,
35.Nm getservent_r ,
41.Nm getservbyport , 36.Nm getservbyport ,
37.Nm getservbyport_r ,
42.Nm getservbyname , 38.Nm getservbyname ,
39.Nm getservbyname_r ,
43.Nm setservent , 40.Nm setservent ,
44.Nm endservent 41.Nm setservent_r ,
42.Nm endservent ,
43.Nm endservent_r
45.Nd get service entry 44.Nd get service entry
46.Sh SYNOPSIS 45.Sh SYNOPSIS
47.Fd #include <netdb.h> 46.Fd #include <netdb.h>
48.Ft struct servent * 47.Ft struct servent *
49.Fn getservent 48.Fn getservent "void"
49.Ft int
50.Fn getservent_r "struct servent *servent" "struct servent_data *servent_data"
50.Ft struct servent * 51.Ft struct servent *
51.Fn getservbyname "char *name" "char *proto" 52.Fn getservbyname "const char *name" "const char *proto"
53.Ft int
54.Fn getservbyname_r "const char *name" "const char *proto" "struct servent *servent" "struct servent_data *servent_data"
52.Ft struct servent * 55.Ft struct servent *
53.Fn getservbyport "int port" proto 56.Fn getservbyport "int port" "const char *proto"
57.Ft int
58.Fn getservbyport_r "int port" "const char *proto" "struct servent *servent" "struct servent_data *servent_data"
54.Ft void 59.Ft void
55.Fn setservent "int stayopen" 60.Fn setservent "int stayopen"
56.Ft void 61.Ft void
57.Fn endservent void 62.Fn setservent_r "int stayopen" "struct servent_data *servent_data"
63.Ft void
64.Fn endservent "void"
65.Ft void
66.Fn endservent_r "struct servent_data *servent_data"
58.Sh DESCRIPTION 67.Sh DESCRIPTION
59The 68The
60.Fn getservent , 69.Fn getservent ,
61.Fn getservbyname , 70.Fn getservbyname ,
62and 71and
63.Fn getservbyport 72.Fn getservbyport
64functions 73functions each return a pointer to an object with the following structure
65each return a pointer to an object with the 74containing the broken-out fields of a line in the network services database,
66following structure
67containing the broken-out
68fields of a line in the network services data base,
69.Pa /etc/services . 75.Pa /etc/services .
70.Bd -literal -offset indent 76.Bd -literal -offset indent
71struct servent { 77struct servent {
@@ -81,64 +87,113 @@ The members of this structure are:
81.It Fa s_name 87.It Fa s_name
82The official name of the service. 88The official name of the service.
83.It Fa s_aliases 89.It Fa s_aliases
84A zero terminated list of alternate names for the service. 90A null-terminated list of alternate names for the service.
85.It Fa s_port 91.It Fa s_port
86The port number at which the service resides. 92The port number at which the service resides.
87Port numbers are returned in network byte order. 93Port numbers are returned in network byte order.
88.It Fa s_proto 94.It Fa s_proto
89The name of the protocol to use when contacting the 95The name of the protocol to use when contacting the service.
90service.
91.El 96.El
92.Pp 97.Pp
93The 98The
94.Fn getservent 99.Fn getservent
95function 100function reads the next line of the file, opening the file if necessary.
96reads the next line of the file, opening the file if necessary.
97.Pp 101.Pp
98The 102The
99.Fn setservent 103.Fn setservent
100function 104function opens and rewinds the file.
101opens and rewinds the file. If the 105If the
102.Fa stayopen 106.Fa stayopen
103flag is non-zero, 107flag is non-zero,
104the net data base will not be closed after each call to 108the services database will not be closed after each call to
105.Fn getservbyname 109.Fn getservbyname
106or 110or
107.Fn getservbyport . 111.Fn getservbyport .
108.Pp 112.Pp
109The 113The
110.Fn endservent 114.Fn endservent
111function 115function closes the file.
112closes the file.
113.Pp 116.Pp
114The 117The
115.Fn getservbyname 118.Fn getservbyname
116and 119and
117.Fn getservbyport 120.Fn getservbyport
118functions 121functions sequentially search from the beginning of the file until a
119sequentially search from the beginning 122matching protocol name or port number (specified in network byte order)
120of the file until a matching 123is found, or until
121protocol name or
122port number is found,
123or until
124.Dv EOF 124.Dv EOF
125is encountered. 125is encountered.
126If a protocol name is also supplied (non- 126If a protocol name is also supplied (non-null),
127.Dv NULL ) ,
128searches must also match the protocol. 127searches must also match the protocol.
129.ne 1i 128.Pp
129The
130.Fn getservent_r ,
131.Fn getservbyport_r ,
132.Fn getservbyname_r ,
133.Fn setservent_r ,
134and
135.Fn endservent_r
136functions are reentrant versions of the above functions that take a
137pointer to a
138.Fa servent_data
139structure which is used to store state information.
140The structure must be zero-filled before it is used
141and should be considered opaque for the sake of portability.
142.Pp
143The
144.Fn getservent_r ,
145.Fn getservbyport_r ,
146and
147.Fn getservbyname_r
148functions
149also take a pointer to a
150.Fa servent
151structure which is used to store the results of the database lookup.
152.Sh RETURN VALUES
153The
154.Fn getservent ,
155.Fn getservbyport ,
156and
157.Fn getservbyname
158functions return a pointer to a
159.Fa servent
160structure on success or a null pointer if end-of-file
161is reached or an error occurs.
162.Pp
163The
164.Fn getservent_r ,
165.Fn getservbyport_r ,
166and
167.Fn getservbyname_r
168functions return 0 on success or \-1 if end-of-file
169is reached or an error occurs.
130.Sh FILES 170.Sh FILES
131.Bl -tag -width /etc/services -compact 171.Bl -tag -width /etc/services -compact
132.It Pa /etc/services 172.It Pa /etc/services
133.El 173.El
134.Sh DIAGNOSTICS
135Null pointer
136(0) returned on
137.Dv EOF
138or error.
139.Sh SEE ALSO 174.Sh SEE ALSO
140.Xr getprotoent 3 , 175.Xr getprotoent 3 ,
141.Xr services 5 176.Xr services 5
177.Sh STANDARDS
178The
179.Fn getservent ,
180.Fn getservbynumber ,
181.Fn getservbyname ,
182.Fn setservent ,
183and
184.Fn endservent
185functions conform to
186.St -p1003.1-2004 .
187.Pp
188The
189.Fn getservent_r ,
190.Fn getservbyport_r ,
191.Fn getservbyname_r ,
192.Fn setservent_r ,
193and
194.Fn endservent_r
195functions are not currently standardized.
196This implementation follows the API used by HP, IBM, and Digital.
142.Sh HISTORY 197.Sh HISTORY
143The 198The
144.Fn getservent , 199.Fn getservent ,
@@ -147,11 +202,19 @@ The
147.Fn setservent , 202.Fn setservent ,
148and 203and
149.Fn endservent 204.Fn endservent
150functions appeared in 205functions appeared in
151.Bx 4.2 . 206.Bx 4.2 .
207.Pp
208The
209.Fn getservent_r ,
210.Fn getservbyport_r ,
211.Fn getservbyname_r ,
212.Fn setservent_r ,
213and
214.Fn endservent_r
215functions appeared in
216.Ox 3.7 .
152.Sh BUGS 217.Sh BUGS
153These functions use static data storage; 218The non-reentrant functions use static data storage; if the data is needed
154if the data is needed for future use, it should be 219for future use, it should be copied before any subsequent calls overwrite it.
155copied before any subsequent calls overwrite it. 220Expecting port numbers to fit in a 32-bit quantity is probably naive.
156Expecting port numbers to fit in a 32 bit
157quantity is probably naive.