.\" @(#)getservent 40.6 90/01/29 SMI; from UCB 4.3
.\" Copyright 1989 AT&T
.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved.
.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved.  The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.nr X
.if \nX=0 .ds x} getservent 3N "" "\&"
.if \nX=1 .ds x} getservent 3N ""
.if \nX=2 .ds x} getservent 3N "" "\&"
.if \nX=3 .ds x} getservent "" "" "\&"
.TH \*(x}
.SH NAME
\f4getservent, getservbyport, getservbyname, setservent, endservent\fP \- get service entry
.SH SYNOPSIS
.nf
.ft 4
.\"please check the location of the following include file
#include <netdb.h>
.P
.ft 4
struct servent *getservent(\|)
.P
.ft 4
struct servent *getservbyname(name, proto)
char *name, *proto;
.P
.ft 4
struct servent *getservbyport(port, proto)
int port;
char *proto;
.P
.ft 4
setservent(stayopen)
int stayopen;
.P
.ft 4
endservent(\|)
.fi
.SH DESCRIPTION
.P
\f4getservent(\|)\fR,
\f2getservbyname(\|)\fR,
and
\f2getservbyport(\|)\fR
each return a pointer to an object with the
following structure containing the broken-out
fields of a line in the network services data base,
\f4/etc/services\fR.
.P
.RS
.ft 4
.nf
struct	servent {
	char	*s_name;        /* official name of service */
	char	**s_aliases;    /* alias list */
	int	s_port;         /* port service resides at */
	char	*s_proto;       /* protocol to use */
};
.ft R
.fi
.RE
.P
The members of this structure are:
.RS
.TP 20
\f2s_name\fR
The official name of the service.
.TP
\f2s_aliases\fR
A zero terminated list of alternate names for the service.
.TP
\f2s_port\fR
The port number at which the service resides.
Port numbers are returned in network short byte order.
.TP
\f2s_proto\fR
The name of the protocol to use when contacting the
service.
.RE
.P
\f4getservent(\|)\fR
reads the next line of the file, opening the file if necessary.
.P
\f4setservent(\|)\fR
opens and rewinds the file.
If the
\f2stayopen\fR
flag is non-zero,
the net data base will not be closed after each call to
\f4getservent(\|)\fR
(either directly, or indirectly through one of
the other \*(lqgetserv\*(rq calls).
.P
\f4endservent(\|)\fR
closes the file.
.P
\f4getservbyname(\|)\fR
and
\f4getservbyport(\|)\fR
sequentially search from the beginning
of the file until a matching
protocol name or port number is found, or until 
\s-1EOF\s0
is encountered.
If a protocol name is also supplied (non-\s-1NULL\s0),
searches must also match the protocol.
.SH FILES
.PD 0
.TP 20
\f4/etc/services\fR
.PD
.SH "SEE ALSO"
\f4getprotoent\fR(3N),
\f4services\fR(4)
.SH DIAGNOSTICS
.P
A
\s-1NULL\s0
pointer is returned on 
\s-1EOF\s0
or error.
.P
All information is contained in a static area
so it must be copied if it is to be saved.
Expecting port numbers to fit in a 32 bit
quantity is probably naive.
