macro and text revision (-mdoc version 3)
[unix-history] / usr / src / lib / libc / net / getservent.3
CommitLineData
ae59e04c 1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
56e6bd55 2.\" All rights reserved.
ed06f32e 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
ed06f32e 5.\"
ae59e04c 6.\" @(#)getservent.3 6.6 (Berkeley) %G%
56e6bd55 7.\"
ae59e04c
CL
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 ,
ed06f32e 34and
ae59e04c
CL
35.Fn getservbyport
36functions
ed06f32e
KM
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,
ae59e04c
CL
41.Pa /etc/services .
42.Bd -literal -offset indent
ed06f32e
KM
43struct servent {
44 char *s_name; /* official name of service */
45 char **s_aliases; /* alias list */
50159ed7 46 int s_port; /* port service resides at */
ed06f32e
KM
47 char *s_proto; /* protocol to use */
48};
ae59e04c
CL
49.Ed
50.Pp
ed06f32e 51The members of this structure are:
ae59e04c
CL
52.Bl -tag -width s_aliases
53.It Fa s_name
ed06f32e 54The official name of the service.
ae59e04c 55.It Fa s_aliases
ed06f32e 56A zero terminated list of alternate names for the service.
ae59e04c 57.It Fa s_port
ed06f32e
KM
58The port number at which the service resides.
59Port numbers are returned in network byte order.
ae59e04c 60.It Fa s_proto
ed06f32e
KM
61The name of the protocol to use when contacting the
62service.
ae59e04c
CL
63.El
64.Pp
65The
66.Fn getservent
67function
ed06f32e 68reads the next line of the file, opening the file if necessary.
ae59e04c
CL
69.Pp
70The
71.Fn setservent
72function
ed06f32e 73opens and rewinds the file. If the
ae59e04c 74.Fa stayopen
ed06f32e
KM
75flag is non-zero,
76the net data base will not be closed after each call to
ae59e04c
CL
77.Fn getservbyname
78or
79.Fn getservbyport .
80.Pp
81The
82.Fn endservent
83function
ed06f32e 84closes the file.
ae59e04c
CL
85.Pp
86The
87.Fn getservbyname
ed06f32e 88and
ae59e04c
CL
89.Fn getservbyport
90functions
ed06f32e
KM
91sequentially search from the beginning
92of the file until a matching
93protocol name or
94port number is found,
ae59e04c
CL
95or until
96.Dv EOF
97is encountered.
98If a protocol name is also supplied (non-
99.Dv NULL ) ,
ed06f32e 100searches must also match the protocol.
ae59e04c
CL
101.Sh FILES
102.Bl -tag -width /etc/services -compact
103.It Pa /etc/services
104.El
105.Sh DIAGNOSTICS
ed06f32e 106Null pointer
ae59e04c
CL
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
ed06f32e 128quantity is probably naive.