z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


GETSERVBYPORT

z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference
SC27-3660-00

Use the GETSERVBYPORT command to translate a port number to the name of the service that is using the port.

Format

Read syntax diagramSkip visual syntax diagram
                                          .-,--TCP----------.   
>>-SOCKET--(--"GETSERVBYPORT"--,--portid--+-----------------+--->
                                          '-,--protocolname-'   

>--)-----------------------------------------------------------><

Parameters

portid
The port number of the service
protocolname
The name of a network protocol, for example, TCP or UDP. By default, the protocolname parameter is set to TCP.

Returned value

This command returns a string that contains the return code, service name, the port number that the service is using, and the network protocol, for example, 0 FTP 21 TCP. The return code can be 0 or the REXX API error number. The return code 0 indicates that the requested socket command was completed successfully.

See Socket call error return codes for additional information about the numeric error codes that are returned by this command.

The following REXX socket API error numbers can be returned:
  • 2001 EINVALIDRXSOCKETCALL
  • 2005 ESUBTASKNOTACTIVE

LE C/C++ equivalent

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

Code example

Figure 1. GETSERVBYPORT command example
/* REXX EZARXR18 */
/*
 * This sample demonstrates the use of the GETSERVBYPORT
 * socket command.
 */
if perror(socket("INITIALIZE","MYSET01"),"INITIALIZE") = 0,
   then do
   src = socket("GETSERVBYPORT","21");
   Say "Port 21 is using service "SUBWORD(src,2);
end;
src = perror(socket("TERMINATE","MYSET01"),"TERMINATE");
exit 0;

/* This routine returns -1 if the first word if arg 1 is not zero */
perror: if word(arg(1),1) = 0 then return 0; else
    Say arg(2) "Error : "arg(1);
    return -1;

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014