xref: /freebsd/lib/libc/net/getservent.3 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     From: @(#)getservent.3	8.3 (Berkeley) 1/12/94
29.\"
30.Dd December 7, 2020
31.Dt GETSERVENT 3
32.Os
33.Sh NAME
34.Nm getservent ,
35.Nm getservbyport ,
36.Nm getservbyname ,
37.Nm setservent ,
38.Nm endservent
39.Nd get service entry
40.Sh LIBRARY
41.Lb libc
42.Sh SYNOPSIS
43.In netdb.h
44.Ft struct servent *
45.Fn getservent
46.Ft struct servent *
47.Fn getservbyname "const char *name" "const char *proto"
48.Ft struct servent *
49.Fn getservbyport "int port" "const char *proto"
50.Ft void
51.Fn setservent "int stayopen"
52.Ft void
53.Fn endservent void
54.Sh DESCRIPTION
55The
56.Fn getservent ,
57.Fn getservbyname ,
58and
59.Fn getservbyport
60functions
61each return a pointer to an object with the
62following structure
63containing the broken-out
64fields of a line in the network services data base,
65.Pa /etc/services .
66.Bd -literal -offset indent
67struct servent {
68	char	*s_name;	/* official name of service */
69	char	**s_aliases;	/* alias list */
70	int	s_port;		/* port service resides at */
71	char	*s_proto;	/* protocol to use */
72};
73.Ed
74.Pp
75The members of this structure are:
76.Bl -tag -width s_aliases
77.It Fa s_name
78The official name of the service.
79.It Fa s_aliases
80A zero terminated list of alternate names for the service.
81.It Fa s_port
82The port number at which the service resides.
83Port numbers are returned in network byte order.
84.It Fa s_proto
85The name of the protocol to use when contacting the
86service.
87.El
88.Pp
89The
90.Fn getservent
91function
92reads the next line of the file, opening the file if necessary.
93.Pp
94The
95.Fn setservent
96function
97opens and rewinds the file.
98If the
99.Fa stayopen
100flag is non-zero,
101the net data base will not be closed after each call to
102.Fn getservbyname
103or
104.Fn getservbyport .
105.Pp
106The
107.Fn endservent
108function
109closes the file.
110.Pp
111The
112.Fn getservbyname
113and
114.Fn getservbyport
115functions
116sequentially search from the beginning
117of the file until a matching
118protocol name or
119port number (which must be specified in
120network byte order) is found,
121or until
122.Dv EOF
123is encountered.
124If a protocol name is also supplied (non-
125.Dv NULL ) ,
126searches must also match the protocol.
127.Sh FILES
128.Bl -tag -width /etc/services -compact
129.It Pa /etc/services
130.It Pa /var/db/services.db
131.El
132.Sh DIAGNOSTICS
133Null pointer returned on
134.Dv EOF
135or error.
136.Sh SEE ALSO
137.Xr getprotoent 3 ,
138.Xr services 5 ,
139.Xr services_mkdb 8
140.Sh HISTORY
141The
142.Fn getservent ,
143.Fn getservbyport ,
144.Fn getservbyname ,
145.Fn setservent ,
146and
147.Fn endservent
148functions appeared in
149.Bx 4.2 .
150.Sh BUGS
151These functions use a thread-specific data storage;
152if the data is needed for future use, it should be
153copied before any subsequent calls overwrite it.
154Expecting port numbers to fit in a 32 bit
155quantity is probably naive.
156