COHERENT manpages

This page displays the COHERENT manpage for getservbyport() [Get a service entry by port number].

List of available manpages
Index


getservbyport() -- Sockets Function (libsocket)

Get a service entry by port number
#include <netdb.h>
struct servent *getservbyport(port, protocol);
int port; char *protocol;

Function getservbyport()  searches file /etc/services,  which describes the
services offered by TCP/IP on  your local network, for the services offered
by port. 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().

getservbyport() 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().

getservbyport() returns  NULL if an  error occurs, or if  it encounters the
end of the file.

See Also

endservent(),
getservbyname(),
getservent(),
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.