Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

Converting service names to port numbers and vice versa

&pagelevel(3)&pagelevel

A service is expected to be on a specific port and use just one communications protocol. This view is consistent within the Internet domain but does not apply in some other network architectures. A service may also be available on several ports, in which case higher-level library functions have to be forwarded or extended.

The getservbyname() function converts a service name to a port number. The service name and, optionally, the name of a qualifying protocol are passed when getservbyname() is called.The getservbyport() function converts a port number to a service name. The port number and, optionally, the name of a qualifying protocol are passed when getservbyport() is called.

getservbyname() and getservbyport() return a pointer to an object of data type struct servent as their result.

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

struct servent {
     char *s_name;          /* official 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 */
};

Up to openNet Server V3.4 with SOCKETS(BS2000) V2.5, conversion took place on the basis of a static list contained in SOCKETS(BS2000).
In openNet Server V3.5 and higher with SOCKETS(BS2000) V2.6, a services file with the default name SYSDAT.BCAM.ETC.SERVICES is offered which is managed by BCAM (see the “BCAM Volume 1/2” manual). This file is supplied with the default assignment of ports 1-1023. If you have appropriate user rights, you can modify this file. You can then modify default port assignments and add port assignments.


Example

The following program code returns the port number of the telnet service, which uses the TCP protocol:

struct servent *sp;
...
sp = getservbyname("telnet", "tcp");