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


SOCKET

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

Use the SOCKET command to open a socket descriptor in the active socket set.

Restriction: If the socket type is SOCK_RAW or RAW, the user ID associated with the REXX socket application must have z/OS® UNIX System Services superuser authority. The user ID must have the UID value 0 or have read access to the BPX.SUPERUSER security profile. An application can attempt to obtain superuser authority by issuing the z/OS UNIX System Services SYSCALLS command: address syscall 'SETEUID 0'. If this command fails, the user ID does not have the authorization needed to run the program; contact your security administrator.

Format

Read syntax diagramSkip visual syntax diagram
                        .-,--AF_INET-.  .-,--STREAM-.   
>>-SOCKET--(--"SOCKET"--+------------+--+-----------+----------->
                        '-,--domain--'  '-,--type---'   

   .-,--0--------.      
>--+-------------+--)------------------------------------------><
   '-,--protocol-'      

Parameters

domain
The address family of the socket. The supported families are AF_INET (2) and AF_INET6 (19). By default, the domain parameter is set to AF_INET.
type
An optional parameter that specifies the type of socket to be created. By default, this parameter is set to STREAM. The following values are supported:
  • STREAM or SOCK_STREAM
  • DATAGRAM or SOCK_DATAGRAM
  • RAW or SOCK_RAW
protocol
An optional parameter that specifies the protocol that is requested. By default, the value to which this parameter is set depends on the type parameter. The default protocol for stream sockets is TCP. The default protocol for datagram sockets is UDP. There is no default for RAW sockets. To enable the stack to select the applicable protocol, set the protocol parameter to 0.
The following protocols are supported:
Stream sockets
IPPROTO_TCP or TCP
Datagram sockets
IPPROTO_UDP or UDP
RAW sockets
  • IPPROTO_IP or IP
  • IPPROTO_IPV6 or IPV6
  • IPPROTO_ICMP or ICMP
  • IPPROTO_ICMPV6 or ICMPV6
  • IPPROTO_RAW or RAW

Returned value

The command returns a string that contains the return code and the new socket descriptor, for example, 0 6. The return code can be 0, a REXX socket API error number, or the REXX TCP/IP error number that is set by the socket command. 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 TCP/IP error numbers can be returned:
  • 9 EBADF
  • 22 EINVAL
  • 38 ENOTSOCK
  • 45 EOPNOTSUPP
  • 139 EPERM
The following REXX socket API error numbers can be returned:
  • 2001 EINVALIDRXSOCKETCALL
  • 2005 ESUBTASKNOTACTIVE
  • 2007 EMAXSOCKETSREACHED

LE C/C++ equivalent

int socket(int *domain, int type, int protocol);

Code example

Figure 1. SOCKET command example
/*  REXX EZARXR26 */
/*
 * This sample demonstrates the use of the SOCKET
 * socket command.
 *
 * HINT: See other socket command descriptions for
 *       additional examples.
 */
src=SOCKET("INITIALIZE","MYSET01",20);
src=SOCKET("SOCKET","AF_INET","STREAM")
parse var src l_retcode l_socketid
if l_retcode = 0 then do
   Say "Socket Created Successfully.  Socket descriptor is" l_socketid;
   src=SOCKET("CLOSE",l_socketid);
   parse var src l_retcode .
   if l_retcode = 0 then
      say "Socket "l_socketid" closed successfully";
   else do
      say "Close of socket "l_socketid" failed.";
      say src;
   end;
end;
else do
   Say "Socket not created."
   Say "..."src;
end;
x=SOCKET("TERMINATE","MYSET01");
exit;

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014