EZASO6AC CSECT
EZASO6AC AMODE ANY
EZASO6AC RMODE ANY
PRINT NOGEN
***********************************************************************
* *
* MODULE NAME: EZASO6AC - THIS IS A VERY SIMPLE IPV6 CLIENT *
* *
* Copyright: Licensed Materials - Property of IBM *
* *
* "Restricted Materials of IBM" *
* *
* 5694-A01 *
* *
* (C) Copyright IBM Corp. 2002, 2003 *
* *
* US Government Users Restricted Rights - *
* Use, duplication or disclosure restricted by *
* GSA ADP Schedule Contract with IBM Corp. *
* *
* Status: CSV1R5 *
* *
* *
* LANGUAGE: ASSEMBLER *
* *
* ATTRIBUTES: NON-REUSEABLE *
* *
* REGISTER USAGE: *
* R1 = *
* R2 = *
* R3 = BASE REG 1 *
* R4 = BASE REG 2 (UNUSED) *
* R5 = FUTURE BASE? *
* R6 = TEMP *
* R7 = RETURN REG *
* R8 = *
* R9 = A(WORK AREA) *
* R10 = *
* R11 = *
* R12 = *
* R13 = SAVE AREA *
* R14 = *
* R15 = *
* *
* INPUT: ANY PARM TURNS TRACE OFF, NO PARM IS NOISY MODE *
* OUTPUT: WTO RESULTS OF EACH TEST CASE IF TRACING *
* RETURN CODE IS 0 WHETHER IT CONNECTS OR NOT! *
* *
***********************************************************************
GBLB &TRACE ASSEMBLER VARIABLE TO CONTROL TRACE GENERATION
&TRACE SETB 1 1=TRACE ON 0=TRACE OFF
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
R11 EQU 11
R12 EQU 12
R13 EQU 13
R14 EQU 14
R15 EQU 15
*---------------------------------------------------------------------*
* START OF EXECUTABLE CODE *
*---------------------------------------------------------------------*
USING *,R3,R4 TELL ASSEMBLER OF OTHERS
SAVE (14,12),T,*
LR R3,R15 COPY EP REG TO FIRST BASE
LA R5,2048 GET R5 HALFWAY THERE
LA R5,2048(R5) GET R5 THERE
LA R4,0(R5,R3) GET R4 THERE
LA R12,12 JUST FOR FUN!
ST R1,PARMADDR SAVE ADDRESS OF PARAMETER LIST
L R1,0(R1) GET POINTER
LH R1,0(R1) GET LENGTH
* STC R1,TRACE USE IT AS FLAG
L R7,=A(SOCSAVE) GET NEW SAVE AREA
ST R7,8(R13) SAVE ADDRESS OF NEW SAVE AREA
ST R13,4(R7) COMPLETE SAVE AREA CHAIN
LR R13,R7 NOW SWAP THEM
L R9,=A(MYCB) POINT TO THE CONTROL BLOCK
USING MYCB,R9 TELL ASSEMBLER
*---------------------------------------------------------------------*
* BUILD MESSAGE FOR CONSOLE
*---------------------------------------------------------------------*
* INITIALIZE MESSAGE TEXT FIELDS
LOOP EQU *
MVC MSGNUM(8),SUBTASK WHO I AM
MVC TYPE,MSGSTART MOVE 'STARTED' TO MESSAGE
*
MVC MSGRSLT1,MSGSUCC ...SUCCESSFUL TEXT
MVC MSGRSLT2,BLANK35
*
STM R14,R12,12(R13) JUST FOR DEBUGGING
BAL R14,WTOSUB --> DO STARTING WTO
***********************************************************************
* *
* Issue INITAPI to connect to interface *
* *
***********************************************************************
MVC TYPE,MINITAPI MOVE 'INITAPI' TO MESSAGE
*
POST ECB,1 FOLLOWING IS SYNC ONLY
MVI SYNFLAG,0 MOVE A 1 FOR ASYNCH
EZASMI TYPE=INITAPI, ISSUE INITAPI MACRO X
SUBTASK=SUBTASK, SPECIFY SUBTASK IDENTIFIER X
MAXSOC=MAXSOC, SPECIFY MAXIMUM NUMBER OF SOCKETS X
MAXSNO=MAXSNO, (HIGHEST SOCKET NUMBER ASSIGNED) X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
APITYPE=APITYPE, (SPECIFY APITYPE FIELD) X
ERROR=ERROR Abend if error on macro
* IDENT=IDENT, TCP ADDR SPACE AND MY ADDR SPACE
*
* ASYNC=('ECB'), (SPECIFY TO USE ECBS)
* ASYNC=('EXIT',MYEXIT) (SPECIFY TO USE EXITS)
BAL R14,RCCHECK --> CHECK RESULTS
***********************************************************************
* *
* Issue SOCKET Macro to obtain a socket descriptor *
* *** INET and STREAM *** *
* *
***********************************************************************
MVC TYPE,MSOCKET MOVE 'SOCKET' TO MESSAGE
*
EZASMI TYPE=SOCKET, Issue SOCKET Macro X
AF='INET6', INET, IUCV, or INET6 X
SOCTYPE='STREAM', STREAM(TCP) DATAGRAM(UDP) or RAW X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
REQAREA=REQAREA, FOR EXITS (AND ECBS) X
ERROR=ERROR Abend if Macro error
*
BAL R14,RCCHECK --> CHECK RESULTS
STH R8,S SAVE RETCODE (=SOCKET DESCRIPTOR)
LTR R8,R8 CHECK IT
BM DOSHUTDO --> WE ARE DONE!
***********************************************************************
* *
* Issue CONNECT Socket *
* *
***********************************************************************
MVC TYPE,MCONNECT MOVE 'CONNECT' TO MESSAGE
MVC PORT(2),PORTS Load STREAM port #
MVC ADDRESS(16),ADDR LOAD THE INTERNET ADDRESS
*
EZASMI TYPE=CONNECT, Issue Macro X
S=S, STREAM X
NAME=NAME, SOCKET NAME STRUCTURE X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
REQAREA=REQAREA, FOR EXITS (AND ECBS) X
ERROR=ERROR Abend if Macro error
*
BAL R14,RCCHECK --> CHECK RC
LTR R8,R8 RECHECK IT
BM DOSHUTDO --> WE ARE DONE
***********************************************************************
* *
* Issue GETPEERNAME *
* *
***********************************************************************
MVC TYPE,MGETPEER MOVE 'GTPEERN' TO MESSAGE
*
EZASMI TYPE=GETPEERNAME, Issue Macro X
S=S, STREAM X
NAME=NAME, (SOCKET NAME STRUCTURE) X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
REQAREA=REQAREA, FOR EXITS (AND ECBS) X
ERROR=ERROR Abend if Macro error
*
BAL R14,RCCHECK --> CHECK RC
***********************************************************************
* *
* ISSUE GETNAMEINFO MACRO *
* *
***********************************************************************
MVC TYPE,MGNAMEI MOVE 'GETNAMEINFO' TO MESSAGE
LA R6,NI_NAMEREQD
ST R6,FLAGS
*
EZASMI TYPE=GETNAMEINFO, ISSUE GETNAMEINFO MACRO X
NAME=NAME, X
NAMELEN=NAMELEN, X
HOST=HOSTNAME, X
HOSTLEN=HOSTNAMEL, X
SERVICE=SERVNAME, X
SERVLEN=SERVNAMEL, X
FLAGS=FLAGS, X
ERRNO=ERRNO, (SPECIFY ERRNO FIELD) X
RETCODE=RETCODE, (SPECIFY RETCODE FIELD) X
ERROR=ERROR ABEND IF MACRO ERROR
*
BAL R14,RCCHECK CHECK FOR SUCCESSFUL CALL
*
* DISPLAY HOSTNAME
*
MVC MSGRSLT1,=C'HOST NAME ' INDICATE WHAT WERE PROCESSING
XC MSGRSLT2,MSGRSLT2
MVC MSGRSLT2,HOSTNAME LOAD UP THE DATA
STM R14,R12,12(R13) JUST FOR DEBUGGING
BAL R14,WTOSUB SEND TO THE CONSOLE
*
* DISPLAY SERVNAME
*
MVC MSGRSLT1,=C'SERV NAME ' INDICATE WHAT WERE PROCESSING
XC MSGRSLT2,MSGRSLT2
MVC MSGRSLT2,SERVNAME LOAD UP THE DATA
STM R14,R12,12(R13) JUST FOR DEBUGGING
BAL R14,WTOSUB SEND TO THE CONSOLE
***********************************************************************
* *
* Issue WRITE - Write data from buffer *
* *
***********************************************************************
MVC TYPE,MWRITE MOVE 'WRITE ' TO MESSAGE
*
EZASMI TYPE=WRITE, Issue Macro X
S=S, STREAM SOCKET X
NBYTE=NBYTE, SIZE OF BUFFER X
BUF=BUF, BUFFER X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
REQAREA=REQAREA, FOR EXITS (AND ECBS) X
ERROR=ERROR Abend if Macro error
*
BAL R14,RCCHECK --> CHECK RC
***********************************************************************
* *
* Issue SHUTDOWN - HOW = 1 (end communication TO socket) *
* *
***********************************************************************
DOSHUTDO EQU *
MVC HOW(4),=F'1'
*
BAL R14,SHUTSUB --> SHUTDOWN
*
BAL R14,RCCHECK --> CHECK RC
***********************************************************************
* *
* Issue READ - Read data and store in buffer *
* *
***********************************************************************
MVC TYPE,MREAD MOVE 'READ ' TO MESSAGE
*
EZASMI TYPE=READ, Issue Macro X
S=S, STREAM SOCKET X
NBYTE=NBYTE, SIZE OF BUFFER X
BUF=BUF2, (BUFFER) X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
REQAREA=REQAREA, FOR EXITS (AND ECBS) X
ERROR=ERROR Abend if Macro error
*
BAL R14,RCCHECK --> CHECK RC
MVC MSGRSLT1,MSGBUFF TITLE
MVC MSGRSLT2,BUF2 MOVE THE DATA
BAL R14,WTOSUB --> PRINT IT
***********************************************************************
* *
* Issue SHUTDOWN - HOW = 0 (end communication FROM socket) *
* *
***********************************************************************
MVC HOW(4),=F'0'
*
BAL R14,SHUTSUB --> SHUTDOWN
*
BAL R14,RCCHECK --> CHECK RC
***********************************************************************
* *
* Terminate Connection to API *
* *
***********************************************************************
MVC TYPE,MTERMAPI MOVE 'TERMAPI' TO MESSAGE
*
POST ECB,1 FOLLOWING IS SYNC ONLY
EZASMI TYPE=TERMAPI Issue EZASMI Macro for Termapi
*
BAL R14,RCCHECK --> CHECK RC
*---------------------------------------------------------------------*
* Issue console message for task termination
*---------------------------------------------------------------------*
MVC TYPE,MSGEND Move 'ENDED' to message
*
MVC MSGRSLT1,MSGSUCC ...SUCCESSFUL text
MVC MSGRSLT2,BLANK35
BAL R14,WTOSUB --> DO WTO
LA R14,1 CONSTANT
AH R14,APITYPE ADD
STH R14,APITYPE STORE
CH R14,=H'3' COMPARE
* BE LOOP --> LETS DO IT AGAIN!
*
*---------------------------------------------------------------------*
* Return to Caller
*---------------------------------------------------------------------*
L R13,4(R13)
RETURN (14,12),T,RC=0
WTOSUB EQU *
LR R7,R14 SAVE RETURN REG
MVC MSGCMD,TYPE COPY COMMAND
WTO TEXT=MSG
BR R7 --> RETURN
*
SHUTSUB EQU *
LR R7,R14
MVC TYPE,MSHUTDOW MOVE 'SHUTDOW' TO MESSAGE
*
EZASMI TYPE=SHUTDOWN, Issue Macro X
S=S, STREAM X
HOW=HOW, End communication in both directions X
ERRNO=ERRNO, (Specify ERRNO field) X
RETCODE=RETCODE, (Specify RETCODE field) X
REQAREA=REQAREA, FOR EXITS (AND ECBS) X
ERROR=ERROR Abend if Macro error
*
BR R7 --> RETURN TO CALLER
*---------------------------------------------------------------------*
* ABEND PROGRAM AND GET DUMP TO DEBUG!
ERROR ABEND 1,DUMP
CNOP 2,4
* USES R6,R7,R8 RETCODE RETURNED IN R8
RCCHECK EQU *
LR R7,R14 COPY TO REAL RETURN REG
MVC MSGRSLT1,MSGSUCC ...SUCCESS TEXT
L R6,RETCODE
LTR R6,R6
BM NOWAIT
CLI SYNFLAG,0 PLAIN CASE?
BE NOWAIT --> SKIP IT
MVC KEY+14(8),SUBTASK
MVC KEY+23(8),TYPE
KEY WTO 'WAIT: XXXXXXXX XXXXXXXX'
WAIT ECB=ECB
NOWAIT EQU *
* LA R15,ECB
* ST R15,ECB
ST R9,ECB MAKE THIS THE TOKEN AGAIN
L R6,RETCODE CHECK FOR SUCCESSFUL CALL
CLC TYPE,=CL8'GETHOSTI'
BE HOSTIDRC HANDLE PRINTING HOST ID
LTR R8,R6 SAVE A COPY
*
BNL CONT00
FAILMSG EQU *
MVC MSGRSLT1,MSGFAIL ...FAIL TEXT
CONT00 EQU *
*
*---------------------------------------------------------------------*
* FORMAT THE RETCODE= -XXXXXXX ERRNO= XXXXXXX MSG RESULTS
* ***> R6 = RETCODE VALUE ON ENTRY
*---------------------------------------------------------------------*
MVC MSGRTCT,MSGRETC ' RETCODE= '
MVI MSGRTCS,C'+'
LTR R6,R6
BNM NOTM -->
MVI MSGRTCS,C'-' MOVE SIGN WHICH IS ALWAYS MINUS
NOTM EQU *
MVC MSGERRT,MSGERRN ' ERRNO= '
*
CVD R6,DWORK CONVERT IT TO DECIMAL
UNPK MSGRTCV,DWORK+4(4) UNPACK IT
OI MSGRTCV+6,X'F0' CORRECT THE SIGN
*
ERRNOFMT EQU *
L R6,ERRNO GET ERRNO VALUE
CVD R6,DWORK CONVERT IT TO DECIMAL
UNPK MSGERRV,DWORK+4(4) UNPACK IT
OI MSGERRV+6,X'F0' CORRECT THE SIGN
*
MVC MSGRSLT2(35),MSGRTCD
*
MVI MSGRTHX,X'40' CLEAR HEX INDICATOR
SR R6,R6 CLEAR OUT...
ST R6,RETCODE RETCODE AND...
ST R6,ERRNO ERRNO
*
*
CLI TRACE,0
BNE NOTRACE
LR R14,R7 GIVE HIM RETURN REG
B WTOSUB --> DO WTO
NOTRACE EQU *
BR R7 --> RETURN TO CALLER
*
HOSTIDRC EQU * VALID HOSTID MAY LOOK LIKE NEG. RC
C R6,=F'-1' ONLY -1 RC INDICATES FAILURE
BE FAILMSG ...BAD RC, USE STANDARD MSG
LR R8,R6 ...NEXT CALL EXPECTS ADDR IN R8
MVC MSGRSLT1,MSGSUCC ...SUCCESS TEXT
UNPK HEXRC(9),RETCODE(5) PLUS ONE FOR FAKE SIGN
TR HEXRC(8),HEXTAB ...CONVERT UNPK TO PRINTABLE HEX
MVI HEXRC+8,X'40' ...SPACE OUT FAKED SIGN BYTE
MVI MSGRTHX,C'X' ...INDICATE INFO IS HEX
B ERRNOFMT
*
SYNFLAG DC H'0' DEFAULT TO SYN
TRACE DC H'0' DEFAULT TO TRACE
MYEXIT DC A(MYEXIT1,SUBTASK)
MYEXIT1 SAVE (14,12),T,*
LR R2,R15
USING MYEXIT1,R2
LM R8,R9,0(R1) GET TWO TOKENS
MVC EXKEY+14(8),0(R8) TELL WHO
MVC EXKEY+23(8),TYPE TELL WHAT
EXKEY WTO 'EXIT: XXXXXXXX XXXXXXXX'
POST ECB,1
RETURN (14,12),T,RC=0
DROP R2
*---------------------------------------------------------------------*
* ELEMENTS USED TO RUN PROGRAM *
*---------------------------------------------------------------------*
EZASMGW EZASMI TYPE=GLOBAL, STORAGE DEFINITION FOR GWA X
STORAGE=CSECT
*---------------------*
* INITAPI macro parms *
*---------------------*
SUBTASK DC CL8'EZASO6AC' SUBTASK PARM VALUE
IDENT DC 0CL16' '
DC CL8'TCPV32' DEFAULT TO FIRST ONE AVAILABLE
DC CL8'EZASO6AC' MY ADDR SPACE NAME OR JOBNAME
MAXSNO DC F'0' (HIGHEST SOCKET DESCRIPTOR AVAILABLE)
MAXSOC DC AL2(50) MAXSOC PARM VALUE
APITYPE DC H'2' OR PUT A 3 HERE
*---------------------------------------------------------------------*
* SOCKET macro parms *
*--------------------*
S DC H'0' SOCKET DESCRIPTOR FOR STREAM
*---------------------*
* CONNECT MACRO PARMS *
*---------------------*
CNOP 0,4
NAME DC 0CL28' ' SOCKET IPV6 NAME STRUCTURE
DC AL1(16) Address Length
DC AL1(19) Family
PORT DC H'0'
FLOWINFO DC XL4'00'
ADDRESS DC XL16'FF'
DC XL4'00' SCOPEID
ADDR DC XL16'00000000000000000000000000000001' Internet Address
PORTS DC H'11007'
*---------------------*
* WRITE MACRO PARMS *
*---------------------*
NBYTE DC F'50' SIZE OF BUFFER
BUF DC CL50' THIS IS FROM EZASO6AC!' BUFFER FOR WRITE
*------------------------*
* SHUTDOWN MACRO PARMS *
*------------------------*
HOW DC F'2' END COMMUNICATION TO- AND FROM-SOCKET
*---------------------*
* READ MACRO PARMS *
*---------------------*
BUF2 DC CL50'BUF2' BUFFER FOR READ
*---------------*
*---------------*
MNTOP DC CL8'NTOP '
MPTON DC CL8'PTON '
MFADDRI DC CL8'FADDRI '
MGADDRI DC CL8'GADDRI '
MGNAMEI DC CL8'GNAMEI '
MINITAPI DC CL8'INITAPI'
MSOCKET DC CL8'SOCKET'
MCONNECT DC CL8'CONNECT'
MGETPEER DC CL8'GETPEERN'
MREAD DC CL8'READ'
MWRITE DC CL8'WRITE'
MSHUTDOW DC CL8'SHUTDOWN'
MTERMAPI DC CL8'TERMAPI'
MSGSTART DC CL8' STARTED'
MSGEND DC CL8' ENDED '
MSGSUCC DC CL10' SUCCESS ' Command results...
MSGFAIL DC CL10' FAIL:-( ' ...
MSGRETC DC CL10' RETCODE= ' ...
MSGERRN DC CL10' ERRNO= ' ...
MSGBUFF DC CL10' BUFFER: ' ...
BLANK35 DC CL35' '
*---------------------------------------------------------------------*
* MESSAGE AREA *
*--------------*
MSG DC 0F'0' MESSAGE AREA
DC AL2(MSGE-MSGNUM) LENGTH OF MESSAGE
MSGNUM DC CL10'EZASO6AC:' 'EZASO6AC: '
MSGCMD DC CL8' ' COMMAND ISSUED
MSGRSLT1 DC CL10' ' COMMAND RESULTS (SUCC, PASS, FAIL)
MSGRSLT2 DC CL35' ' RETURNED VALUES
MSGE EQU * End of message
*---------------------------------------------------------------------*
* MESSAGE RESULTS AREAS (fill in and move to MSGRSLT2) *
*------------------------------------------------------*
*
MSGRTCD DC 0CL35' ' GENERAL RETURNED VALUE
MSGRTCT DC CL9' RETCODE=' ' RETCODE= '
MSGRTHX DC CL1' ' 'X' X FOR GETHOSTID
MSGRTCS DC CL1' ' '-' (NEGATIVE SIGN)
HEXRC EQU MSGRTCS HEX RC WILL START AT SIGN LOCATION
MSGRTCV DC CL7' ' RETURNED VALUE (RETCODE)
MSGERRT DC CL10' ERRNO=' ' ERRNO= '
MSGERRV DC CL7' ' RETURNED VALUE (ERRNO)
DWORK DC D'0' WORK AREA
HEXTAB EQU *-240 TAB TO CONVERT TO PRINTABLE HEX
* FIRST 240 BYTES NOT REFERENCED
DC CL16'0123456789ABCDEF'
PARMADDR DC A(0) PARM ADDRESS SAVE AREA
EZBREHST DSECT=NO,LIST=YES,HOSTENT=NO,ADRINFO=YES
LTORG
*---------------------------------------------------------------------*
* REG/SAVEAREA *
*--------------*
SOCSAVE DC 9D'0' SAVE AREA
*---------------------------------------------------------------------*
CNOP 0,8
MYCB EQU * MY CONTROL BLOCK
REQAREA EQU *
ECB DC A(ECB) SELF POINTER
DC CL100'WORK AREA'
MYTIE EZASMI TYPE=TASK,STORAGE=CSECT TIE
TYPE DC CL8'TYPE'
ERRNO DC F'0'
RETCODE DC F'0'
*
HOSTNAME DS CL255 HOST NAME FOR GETNAMEINFO
SERVNAME DS CL32 SERVICE NAME FOR GETNAMEINFO
CNOP 0,4
HOSTNAMEL DC AL4(L'HOSTNAME) LENGTH OF HOST NAME
SERVNAMEL DC AL4(L'SERVNAME) LENGTH OF SERVICE NAME
NAMELEN DC AL4(L'NAME) LENGTH OF NAME
FLAGS DC F'0' GETNAMEINFO FLAGS
*
MYNEXT DC A(MYCB) NEXT IN CHAIN FOR MULTIPLES
CNOP 0,8
MYLEN EQU *-MYCB
MYCB2 EQU *
ORG *+MYLEN
CNOP 0,8
DC CL8'&SYSDATE'
DC CL8'&SYSTIME'
END
Figure 1. EZASO6AC sample client program for IPv6