Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

getservent(), getservbyport(), getservbyname(), setservent(), endservent() - get information about services

&pagelevel(4)&pagelevel

#include <netdb.h>

struct servent *getservent(void);
struct servent *getservbyname(const char *name, const char *proto);
struct servent *getservbyport(int port, const char *proto);
void setservent(int stayopen); 
void endservent(void);

Description

The getservbyport(), getservbyname() and getservent() functions return information about the available services. Each of these functions returns a pointer to an object with the servent structure described below.

The servent structure corresponds to the fields of a line in the service /etc/inet/services database and is defined 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 */
};
Components of the servent structure:

s_name

Name of the service.

s_aliases

A list of alternative (alias) names 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.

getservent() reads the next line in the file. If necessary, getservent() opens the file first.

getservent() opens the file and resets it to the start. If the stayopen flag is not equal to zero, the database is not closed after any getservent() call (neither directly nor indirectly via one of the other getserv...() calls).

endservent() closes the file.

getservbyname() and getservbyport() search sequentially through the file from the start until

  • a matching service name is found or

  • the matching port number is found or

  • The end of the file is reached.

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 information about services and their port numbers is not available in BCAM as they are components of OSI layer 7. Since the assignment of port numbers to services is static, the assignment is implemented by entering the services in the file /etc/inet/services (as is usual in UNIX systems).

All information is in a static area and therefore has to be copied if it is to be saved.

File

/etc/inet/services

See also

getprotoent()