Source code of HPW routine I255613

Client program that runs on Host

 

*********************************************************************
*
*                                I255613
*
*                        TCP/IP Password Client
*
*             Written by William van den Heuvel, 1998
*
*             Update: 1998-11-10
*
*********************************************************************
*
* this program uses the EZASMI assembler macro API:
* EZASMI TYPE=SOCKET      - open client socket
* EZASMI TYPE=CLOSE       - close client socket
*
***********************************************************************
*
* on entry,
* register 1 points to the API parameters.
*
*......................................................................
*
* on completion,
* register 15 will contain a return code (RC):
*
* RC=0 - normal completion (always)
*
***********************************************************************




**********************************************************************
*
I255613  CSECT
I255613  AMODE ANY
I255613  RMODE ANY
*
R0       EQU   0
R1       EQU   1
R2       EQU   2
R3       EQU   3
R4       EQU   4
R5       EQU   5
R6       EQU   6
R7       EQU   7
R8       EQU   8
R9       EQU   9
R10      EQU   10   PARM - address of pointer to PARM-string)
R11      EQU   11   BASE - base register of this program
R12      EQU   12   CAA  - reserved for LE
R13      EQU   13   DSA  - Dynamic Storage Area
R14      EQU   14   return address
R15      EQU   15   entry point address
*
DSA      EQU   R13
CAA      EQU   R12
BASE     EQU   R11
API      EQU   R10        API parameters
GWA      EQU   R9         GLOBAL storage
TIE      EQU   R8         TASK storage
*
         USING API_DSECT,API
         USING DSA_DSECT,DSA
         USING GWA_DSECT,GWA
         USING TIE_DSECT,TIE
*
*********************************************************************



*********************************************************************
*
         LEMENTRY BASE=BASE,LENGTH=DSA_DSECT_LENGTH,PARAM=API,TRACE=0
*
* note:
*        API -> API_DSECT
*        DSA -> DSA_DSECT
*
***********************************************************************


         LEMTRACE 0,'I255613: entry'


***********************************************************************
*
*        get GLOBAL storage (GWA)
         L     GWA,API_GWA         get pointer to GWA
*
*        get TASK storage (TIE)
         L     TIE,API_TIE         get pointer to TIE
*
***********************************************************************











***********************************************************************
*
*        open socket
*
*        The socket is the connection between this program and
*        the TCP/IP system. The socket will remain available until
*        discarded by CLOSE.
*
B100     EQU   *
         LEMTRACE 0,'I255613: SOCKET'
*
         EZASMI TYPE=SOCKET,                                           X
               AF='INET',             TCP/IP protocol                  X
               SOCTYPE='STREAM',      TCP/IP protocol                  X
               TASK=(TIE),            TASK storage (TIE)               X
               RETCODE=DSA_RETCODE,   return code (0 or -1)            X
               ERRNO=DSA_ERRNO,       error number (if RETCODE = -1)   X
               ERROR=B110             if API error occurs
         B     B120
*
*......................................................................
*
*        SOCKET failed (ERROR exit)
B110     EQU   *
         LEMTRACE 8,'I255613: SOCKET failed - ERROR exit'
         B     X100
*
*......................................................................
*
*        if RETCODE is -1 (error) then ERRNO contains the error code
*        else RETCODE contains the socket descriptor
B120     EQU   *
*
*        error?
         L    R15,DSA_RETCODE    R15 = RETCODE
         C    R15,=F'-1'         RETCODE = -1?
         BNE  B130               no; successful
*
*......................................................................
*
*        unsuccessful
*        ERRNO contains the error code
         LEMTRACE 8,'I255613: SOCKET failed - ERRNO=',(DSA_ERRNO,4,B)
         B     X100
*
*......................................................................
*
*        successful
B130     EQU   *
*
*        save socket number
*        R15  contains the socket number (bits 16-31)
         STCM R15,B'0011',API_SOCKET
*
*......................................................................
*
*        TRACE
         LEMTRACE 4,'I255613: SOCKET=',(API_SOCKET,2,B)
*
***********************************************************************






***********************************************************************
*
*        call I255614 passing API
*
         LR    R1,API
         L     R15,=V(I255614)
         BASR  R14,R15
*
***********************************************************************








***********************************************************************
*
*        close socket
*
D100     EQU   *
         LEMTRACE 0,'I255613: CLOSE'
*
*        The socket number is in API_SOCKET
*
         EZASMI TYPE=CLOSE,                                            X
               TASK=(TIE),            TASK storage (TIE)               X
               S=API_SOCKET,          server socket                    X
               RETCODE=DSA_RETCODE,   return code (0 or -1)            X
               ERRNO=DSA_ERRNO,       error number (if RETCODE = -1)   X
               ERROR=D110             if API error occurs
         B     D120
*
*......................................................................
*
*        CLOSE failed (ERROR exit)
D110     EQU   *
         LEMTRACE 8,'I255613: close failed - ERROR exit'
         B     X100
*
*......................................................................
*
*        if RETCODE is -1 (error) then ERRNO contains the error code
*        else RETCODE contains the socket descriptor
D120     EQU   *
*
*        error?
         L    R15,DSA_RETCODE    R15 = RETCODE
         C    R15,=F'-1'         RETCODE = -1?
         BNE  D130               no; successful
*
*......................................................................
*
*        unsuccessful
*        ERRNO contains the error code
         LEMTRACE 8,'I255613: CLOSE failed - ERRNO=',(DSA_ERRNO,4,B)
         B     X100
*
*......................................................................
*
*        successful
D130     EQU   *
*
*        CLEAR socket descriptor
         XR   R15,R15
         STCM R15,B'0011',API_SOCKET
*
*......................................................................
*
*        TRACE
         LEMTRACE 0,'I255613: SOCKET=',(API_SOCKET,2,B)
*
***********************************************************************





**********************************************************************
*
*        return to caller
X100     EQU *
         LEMTRACE 0,'I255613: exit'
         LEMEXIT
*
*********************************************************************




**********************************************************************
*
*  GWA   Global Work Area
*
GWA_DSECT EZASMI TYPE=GLOBAL,STORAGE=DSECT
*
*********************************************************************





**********************************************************************
*
*  TIE   Task Work Area
*
TIE_DSECT EZASMI TYPE=TASK,STORAGE=DSECT
*
*********************************************************************




***********************************************************************
*
* DSA - Dynamic Storage Area (pointed to by register 13)
*
DSA_DSECT     LEMDSA
*
*......................................................................
*
DSA_RETCODE   DS     F     return code
*                           0 = successful
*                          -1 = check ERRNO for error code
*
DSA_ERRNO     DS     F     error code (only if RETCODE=-1)
*
*......................................................................
*
              DS   0D   D-align what follows
DSA_DSECT_LENGTH EQU  *-DSA_DSECT
*
***********************************************************************
*
* API - parameters passed between modules
* this dsect is address via register API
*
*......................................................................
*
API_DSECT       DSECT
*
* following fields are set by I25561:
API_MAXSOC       DS  H    maximum number of sockets         for INITAPI
API_CONNECT_IP   DS  XL4 IP-address of server               for CONNECT
API_CONNECT_PORT DS  H   port number of server              for CONNECT
*
*......................................................................
*
* following fields are set by I255611:
API_GWA         DS  A    pointer to GLOBAL storage for EZASMI macro
API_TIE         DS  A    pointer to TASK   storage for EZASMI macro
API_MAXSNO      DS  H    highest socket number             from INITAPI
                DS  H    unused
*
*......................................................................
*
* following fields are set by I255612:
API_LOCAL_IP    DS  XL4  IP-address of local host        from GETHOSTID
API_LOCAL_NAME  DS  CL26 local hostname (LL-string)    from GETHOSTNAME
*
*......................................................................
*
* following fields are set by I255613:
API_SOCKET      DS  H    socket number                      from SOCKET
*
***********************************************************************
        END