COHERENT manpages
This page displays the COHERENT manpage for getservbyname() [Get a service entry by name].
List of available manpages
Index
getservbyname() -- Sockets Function (libsocket)
Get a service entry by name
#include <netdb.h>
struct servent *getservbyname(name, protocol);
char *name, *protocol;
Function getservbyname() searches file /etc/services, which describes the
services offered by TCP/IP on your local network, for the services offered
by name. If protocol is not NULL, the search must also match the protocol
it names. /etc/services must first have been opened by a call to
setservent().
getservbyname() returns a pointer to a structure of type servent, which is
defined in header file <netdb.h>:
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 */
};
The following details each member:
s_name
The official name of the service.
s_aliases
This points to a zero-terminated list 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 contacting the service.
To close /etc/services, call function endservent().
getservbyname() returns NULL if an error occurs, or if it encounters the
end of the file.
See Also
endservent(),
getservent(),
getservbyport(),
libsocket,
netdb.h,
setservent()
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.