z/OS Communications Server: IP IMS Sockets Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Sample program for IPv6 client program

z/OS Communications Server: IP IMS Sockets Guide
SC27-3653-00

The EZASO6PC PL⁄I sample program is a client program that shows you how to use the following calls provided by the call socket interface:

  • CONNECT
  • GETNAMEINFO
  • GETPEERNAME
  • INITAPI
  • PTON
  • READ
  • SHUTDOWN
  • SOCKET
  • TERMAPI
  • WRITE
 /*********************************************************************/
 /*                                                                   */
 /*   MODULE NAME:  EZASO6PC - THIS IS A VERY SIMPLE IPV6 CLIENT      */
 /*                                                                   */
 /* Copyright:    Licensed Materials - Property of IBM                */
 /*                                                                   */
 /*               "Restricted Materials of IBM"                       */
 /*                                                                   */
 /*               5694-A01                                            */
 /*                                                                   */
 /*               (C) Copyright IBM Corp. 2002                        */
 /*                                                                   */
 /*               US Government Users Restricted Rights -             */
 /*               Use, duplication or disclosure restricted by        */
 /*               GSA ADP Schedule Contract with IBM Corp.            */
 /*                                                                   */
 /* Status:       CSV1R4                                              */
 /*                                                                   */
 /*********************************************************************/
 EZASO6PC: PROC OPTIONS(MAIN);

 /* INCLUDE CBLOCK - common variables                                 */
 % include CBLOCK;

 ID.TCPNAME = 'TCPCS';                 /* Set TCP to use              */
 ID.ADSNAME = 'EZASO6PS';              /* and address space name      */
 open file(driver);

 /*********************************************************************/
 /*                                                                   */
 /* Execute INITAPI                                                   */
 /*                                                                   */
 /*********************************************************************/

 call ezasoket(INITAPI, MAXSOC, ID, SUBTASK,
                       MAXSNO, ERRNO, RETCODE);
 if retcode < 0 then do;
    msg = 'FAIL: initapi' || errno;
    write file(driver) from (msg);
    goto getout;
 end;

 /*********************************************************************/
 /*                                                                   */
 /* Execute SOCKET                                                    */
 /*                                                                   */
 /*********************************************************************/

 call ezasoket(SOCKET, AF_INET6, TYPE_STREAM, PROTO,
                      ERRNO, RETCODE);
 if retcode < 0 then do;
    msg = blank;                       /* clear field                 */
    msg = 'FAIL: socket, stream, internet' || errno;
    write file(driver) from (msg);
    goto getout;
 end;
 sock_stream = retcode;                /* save socket descriptor      */

 /*********************************************************************/
 /* Execute PTON                                                      */
 /*                                                                   */
 /*********************************************************************/
 PRESENTABLE_ADDR = IPV6_LOOPBACK;  /* Set the address to use         */
 PRESENTABLE_ADDR_LEN = LENGTH(PRESENTABLE_ADDR) ; /* and it's length */
 call ezasoket(PTON, AF_INET6, PRESENTABLE_ADDR,
                     PRESENTABLE_ADDR_LEN, NUMERIC_ADDR,
                     ERRNO, RETCODE);
 msg = blank;                          /* clear field                 */
 if retcode < 0 then do;
    msg = 'FAIL: pton' || errno;
    write file(driver) from (msg);
    goto getout;
 end;
 msg = 'SUCCESS: pton converted ' || PRESENTABLE_ADDR;
 name6_id.address = NUMERIC_ADDR;      /* IPV6 internet address       */

 /*********************************************************************/
 /* Execute CONNECT                                                   */
 /*                                                                   */
 /*********************************************************************/

 name6_id.port = 8888;
 call ezasoket(CONNECT, SOCK_STREAM, NAME6_ID,
                      ERRNO, RETCODE);
 if retcode < 0 then do;
    msg = blank;                       /* clear field                 */
    msg = 'FAIL: connect, stream, internet' || errno;
    write file(driver) from (msg);
    goto getout;
 end;

 /*********************************************************************/
 /*                                                                   */
 /*   Execute GETPEERNAME                                             */
 /*                                                                   */
 /*********************************************************************/

 call ezasoket(GETPEERNAME, SOCK_STREAM,
                      NAME6_ID, ERRNO, RETCODE);
 msg = blank;                          /* clear field                 */
 if retcode < 0 then do;
    msg = 'FAIL: getpeername' || errno;
    write file(driver) from (msg);
 end;

 /*********************************************************************/
 /*                                                                   */
 /*   Execute GETNAMEINFO                                             */
 /*                                                                   */
 /*********************************************************************/

 NAMELEN = 28 ;                 /* Set length of NAME                 */
 GNI_HOST = blank;              /* Clear Host name                    */
 GNI_HOSTLEN = LENGTH(GNI_HOST); /* Set Host name length              */
 GNI_SERVICE = blank;           /* Clear Service name                 */
 GNI_SERVLEN = LENGTH(GNI_SERVICE); /* Set Service name length        */
 GNI_FLAGS = NI_NAMEREQD;       /* Set an error if name is not found  */
 call ezasoket(GETNAMEINFO, NAME6_ID, NAMELEN,
                      GNI_HOST, GNI_HOSTLEN,
                      GNI_SERVICE, GNI_SERVLEN,
                      GNI_FLAGS,
                      ERRNO, RETCODE);
 msg = blank;                          /* clear field                 */
 if retcode < 0 then do;
    msg = 'FAIL: getnameinfo' || errno;
    write file(driver) from (msg);
 end;
 else do;
    msg = 'getnameinfo host=' || GNI_HOST ;
    write file(driver) from (msg);
    msg = 'getnameinfo service=' || GNI_SERVICE ;
    write file(driver) from (msg);
 end;

 /*********************************************************************/
 /*                                                                   */
 /* Execute WRITE                                                     */
 /*                                                                   */
 /*********************************************************************/

 bufout = message;
 nbyte = length(message);
 call ezasoket(WRITE, SOCK_STREAM, NBYTE, BUFOUT,
                      ERRNO, RETCODE);
 msg = blank;                          /* clear field                 */
 if retcode < 0 then do;
    msg = 'FAIL: write' || errno;
    write file(driver) from (msg);
 end;
 else do;
    msg = 'write = ' || bufout;
    write file(driver) from (msg);
 end;

 /*********************************************************************/
 /*                                                                   */
 /* Execute READ                                                      */
 /*                                                                   */
 /*********************************************************************/

 nbyte = length(bufin);
 call ezasoket(READ, SOCK_STREAM,
                     NBYTE, BUFIN, ERRNO, RETCODE);
 msg = blank;                          /* clear field                 */
 if retcode < 0 then do;
    msg = 'FAIL: read' || errno;
    write file(driver) from (msg);
 end;
 else do;
    msg = 'read = ' || bufin;
    write file(driver) from (msg);
 end;

 /*********************************************************************/
 /*                                                                   */
 /* Execute SHUTDOWN from/to                                          */
 /*                                                                   */
 /*********************************************************************/

 getout:
 how = 2;
 call ezasoket(SHUTDOWN, SOCK_STREAM, HOW,
                      ERRNO, RETCODE);
 if retcode < 0 then do;
    msg = blank;                       /* clear field                 */
    msg = 'FAIL: shutdown' || errno;
    write file(driver) from (msg);
 end;

 /*********************************************************************/
 /*                                                                   */
 /* Execute TERMAPI                                                   */
 /*                                                                   */
 /*********************************************************************/

 call ezasoket(TERMAPI);

 close file(driver);
 end ezaso6pc;
Figure 1. EZASO6PC PL/1 sample client program for IPv6

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014