.TH getservent() "" "" "Sockets Function (libsocket)"
.PC "Get a service entry"
.B "#include <netdb.h>"
\fBstruct servent *getservent(\|);\fR
.PP
Function
.B getservent()
reads the next entry from file
.BR /etc/services ,
which describes the services offered by TCP/IP on your local network.
If necessary, it opens the file.
It returns a pointer to a structure of type
.BR servent ,
which is defined in header file
.BR <netdb.h> :
.DM
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 */
};
.DE
.PP
The following details each member:
.IP \fBs_name\fR
The official name of the service.
.IP \fBs_aliases\fR
This points to a zero-terminated list of alternate names for the service.
.IP \fBs_port\fR
The port number at which the service resides.
Port numbers are returned in network byte order.
.IP \fBs_proto\fR
The name of the protocol to use when contacting the service.
.PP
To close
.BR /etc/services ,
call function
.BR endservent() .
.PP
.B getservent()
returns NULL if an error occurs, or if it encounters the end of the file.
.SH "See Also"
.Xr "endservent()," endserven
.Xr "getservbyname()," getservbn
.Xr "getservbyport()," getservbp
.Xr "libsocket," libsocket
.Xr "netdb.h," netdb.h
.Xr "setservent()" setserven
.SH Notes
This function uses a static data space.
If your application needs to save these data, it must copy them
before any subsequent calls overwrite them.
