endservent
Purpose
Gets service entry.
Library
Sockets Library (libsock.a)
Syntax
#include <netdb.h>
struct servent *getservent ( ) void setservent (stayopen)
int stayopen;
struct servent *getservbyname (name, proto)
char *name, *proto; void endservent ( )
struct servent *getservbyport (port, proto)
int port;
char *proto;
Description
The getservent, getservbyname, and getservbyport subrou-
tines each return a pointer to an object. This object is
a servent structure, which contains the field of a line
in the /etc/services file (the network services data
base). The servent structure is defined in the netdb.h
header file, and it contains the following members:
char *s_name; /* official name of service */
char **s_aliases; /* alias list */
long s_port; /* port where service resides */
char *s_proto; /* protocol to use */
The members of the structure are defined below:
s_name Official name of the service.
s_aliases An array, terminated by a 0, of alternate
names for the service.
s_port The port number at which the service resides.
Port numbers are returned in network byte
order.
s_proto The name of the protocol to use when con-
tacting the service.
The getservent subroutine reads the next line of the
file. If the file is not open, getservent opens it.
The setservent subroutine opens and rewinds the file. If
the stayopen parameter is 0, the service data base is
closed after each call to getservent. Otherwise, the
file is not closed after each call.
The endservent subroutine closes the file.
The getservbyname and getservbyport subroutines search
the file sequentially from its beginning until finding a
matching protocol name or port number, or until encount-
ering the end of the file. When a protocol name is also
supplied, searches also match the protocol.
Return Value
A pointer to a servent structure is returned on success.
Note: The return value points to static data that is
overwritten by subsequent calls.
A NULL pointer (0) is returned if an error occurs or the
end of the file is reached.
File
/etc/services Service name data base.
Related Information
In this book: "getprotoent, getprotobynumber,
getprotobyname, setprotoent, endprotoent."
The discussion of /etc/services in Interface Program for
use with TCP/IP.