xref: /original-bsd/lib/libc/net/getservent.3 (revision 4092c5cc)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)getservent.3	8.1 (Berkeley) 06/04/93
7.\"
8.Dd
9.Dt GETSERVENT 3
10.Os BSD 4.2
11.Sh NAME
12.Nm getservent ,
13.Nm getservbyport ,
14.Nm getservbyname ,
15.Nm setservent ,
16.Nm endservent
17.Nd get service entry
18.Sh SYNOPSIS
19.Fd #include <netdb.h>
20.Ft struct servent *
21.Fn getservent
22.Ft struct servent *
23.Fn getservbyname "char *name" "char *proto"
24.Ft struct servent *
25.Fn getservbyport "int port" proto
26.Ft void
27.Fn setservent "int stayopen"
28.Ft void
29.Fn endservent void
30.Sh DESCRIPTION
31The
32.Fn getservent ,
33.Fn getservbyname ,
34and
35.Fn getservbyport
36functions
37each return a pointer to an object with the
38following structure
39containing the broken-out
40fields of a line in the network services data base,
41.Pa /etc/services .
42.Bd -literal -offset indent
43struct	servent {
44	char	*s_name;	/* official name of service */
45	char	**s_aliases;	/* alias list */
46	int	s_port;		/* port service resides at */
47	char	*s_proto;	/* protocol to use */
48};
49.Ed
50.Pp
51The members of this structure are:
52.Bl -tag -width s_aliases
53.It Fa s_name
54The official name of the service.
55.It Fa s_aliases
56A zero terminated list of alternate names for the service.
57.It Fa s_port
58The port number at which the service resides.
59Port numbers are returned in network byte order.
60.It Fa s_proto
61The name of the protocol to use when contacting the
62service.
63.El
64.Pp
65The
66.Fn getservent
67function
68reads the next line of the file, opening the file if necessary.
69.Pp
70The
71.Fn setservent
72function
73opens and rewinds the file.  If the
74.Fa stayopen
75flag is non-zero,
76the net data base will not be closed after each call to
77.Fn getservbyname
78or
79.Fn getservbyport .
80.Pp
81The
82.Fn endservent
83function
84closes the file.
85.Pp
86The
87.Fn getservbyname
88and
89.Fn getservbyport
90functions
91sequentially search from the beginning
92of the file until a matching
93protocol name or
94port number is found,
95or until
96.Dv EOF
97is encountered.
98If a protocol name is also supplied (non-
99.Dv NULL ) ,
100searches must also match the protocol.
101.Sh FILES
102.Bl -tag -width /etc/services -compact
103.It Pa /etc/services
104.El
105.Sh DIAGNOSTICS
106Null pointer
107(0) returned on
108.Dv EOF
109or error.
110.Sh SEE ALSO
111.Xr getprotoent 3 ,
112.Xr services 5
113.Sh HISTORY
114The
115.Fn getservent ,
116.Fn getservbyport ,
117.Fn getservbyname ,
118.Fn setservent ,
119and
120.Fn endservent
121functions appeared in
122.Bx 4.2 .
123.Sh BUGS
124These functions use static data storage;
125if the data is needed for future use, it should be
126copied before any subsequent calls overwrite it.
127Expecting port numbers to fit in a 32 bit
128quantity is probably naive.
129