Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getservbyname(), getservbyport() - get information about services

&pagelevel(3)&pagelevel



#include <netdb.h>

Kernighan-Ritchie-C:
struct servent *getservbyname(name, proto);

char *name;
char *proto;

struct servent *getservbyport(port, proto);

int port;
char *proto;

ANSI-C:
struct servent* getservbyname(char* name, char* proto);

struct servent* getservbyport(int port, char* proto)


Description

Use of the getservbyname() and getservbyport() functions only makes sense in the AF_INET and AF_INET6 address families.

The getservbyname() and getservbyport() functions return information on the available services from the services file with the default name SYSDAT.BCAM.ETC.SERVICES which is managed by BCAM (see the “BCAM Volume 1/2” manual). Both function return a pointer to an object with the servent structure described below.

getservbyname() returns the port number associated with the service name name and theprotocol proto in the servent object. If NULL is specified for proto, the service name and the port number of the first protocol found in the list are output.

getservbyport() returns the service name associated with the port number port and theprotocol proto in the servent object, as well as the (up to) four aliases which can be entered. If NULL is specified for proto, the service name and the aliases of the first protocol found in the list are output for the specified port number.

The servent structure is declared in <netdb.h> as follows:

struct servent {
   char *s_name;            /* name of the service */
   char **s_aliases;        /* alias list */
   int s_port;              /* number of the port on which the service lies*/
   char *s_proto;           /* protocol used */
};

Description of servent components:

s_name

Name of the service

s_aliases

A list of alternative names (aliases) for the service, terminated with null

s_port

Port number assigned to the service. Port numbers are returned in network byte order.

s_proto

Name of the protocol that must be used to access the service.

As long as a protocol name (not NULL) is specified, getservbyname() and getservbyport() search for the service that uses the matching protocol.

Return value

The null pointer is returned if the search reaches the end of the file.

Note

The data returned in the servent object is supplied in a static area and must therefore be copied if it needs to be saved.