TCP/IP management APIs (1)
**
** Description : Print TCP/IP connection status
**
** Program summary
** ---------------
**
** Object - User space APIs:
** QUSCRTUS Create user space Creates a user space in either
** user domain or system domain.
** Only user domain user spaces are
** accessible by the user space APIs.
**
** QUSDLTUS Delete user space Deletes the user space specified.
**
** QUSPTRUS Retrieve pointer to The address of the first byte
** user space of the storage allocated by the
** user space requested is returned.
**
**
** Communication - TCP/IP management APIs:
** QtocRtvTCPA Retrieve TCP/IP Retrieves TCP/IPv4 and TCP/IPv6
** attributes (V5R2) stack attributes.
**
** QtocLstNetCnn List network Returns a non-detailed list of
** connections network connections based on a
** set of selection criteria defined
** in the list qualifier parameter.
**
** QtocRtvNetCnnDta List network Retrieves detailed information
** connection data and connection totals for the
** specified network connection.
**
**
** Sequence of events:
** 1. The current operational status of the TCP/IP stack is retrieved
** to ensure that TCP/IP connection information is available.
**
** 2. A user space is created and a list of the current TCP/IP network
** connections is loaded to the user space.
**
** 3. For each TCP/IP network connection retrieved from user space a
** report line is printed and subsequently the associated network
** connection data are retrieved.
**
** 4. The based data and list structures are allocated to the storage
** adresses defined by the offsets found in the basic and additional
** information API formats.
**
** 5. A report line is printed for each of the servicing jobs associated
** with the current network connection.
**
** 6. Finally the user space is deleted, explicitly allocated storage
** freed and the program is terminated.
**
**
** Programmer's notes:
** Earliest release program will run: V5R1
**
** The examples here are all retrieving information about TCP/IPv4
** stacks and connections. As of V5R2 new API formats are available
** for retrieval of similar TCP/IPv6 stack and connection information.
**
** Be careful to allocate sufficient storage for the return structure
** of the QtocRtvNetCnnDta API initially. The returned value for bytes
** actually available might not include the additional structures,
** Socket options and Associated jobs/tasks.
**
** The QtocRtvNetCnnDta API has a reported problem involving a memory
** leak. The following PTFs have been released to fix the problem:
** R510 SI09122 1000
** R520 SI09175 1000
**
**
** Compile options:
**
** CrtRpgMod Module( CBX105 ) DbgView( *LIST )
**
** CrtPgm Pgm( CBX105 )
** Module( CBX105 )
**
**-- Header specifications: --------------------------------------------**
H Option( *SrcStmt )
**-- Printer file: -----------------------------------------------------**
FQSYSPRT O F 132 Printer InfDs( PrtLinInf ) OflInd( *InOf )
**-- Printer file information: -----------------------------------------**
D PrtLinInf Ds
D PlOvfLin 5i 0 Overlay( PrtLinInf: 188 )
D PlCurLin 5i 0 Overlay( PrtLinInf: 367 )
D PlCurPag 5i 0 Overlay( PrtLinInf: 369 )
**-- System information: -----------------------------------------------**
D SDs
D PsPgmNam *Proc
**-- Global declarations: ----------------------------------------------**
D Lix s 10u 0
D Dix s 10u 0
D BytAlc s 10u 0
D UsrSpc c 'LSTNETCNN QTEMP'
**
D Time s 6s 0
D NbrRcds s 10u 0
D TcpCnnStt s 4a
D ConOpnTyp s 3a
**-- Tcp state table: --------------------------------------------------**
D SttTbl Ds
D TcpStt 5a Dim( 12 )
D 60a Overlay( SttTbl )
D Inz( 'LST SYNR SYNS EST FIN1 FIN2 +
D CLO2 CLO1 LACK WAIT CLO n/s ')
**-- Open type table: --------------------------------------------------**
D OpnTbl Ds
D OpnTyp 4a Dim( 3 )
D 12a Overlay( OpnTbl )
D Inz( 'PSV ACT n/s ' )
**-- Api error data structure: -----------------------------------------**
D ApiError Ds
D AeBytPro 10i 0 Inz( %Size( ApiError ))
D AeBytAvl 10i 0 Inz
D AeMsgId 7a
D 1a
D AeMsgDta 128a
**
**-- API Header information: -------------------------------------------**
D HdrInf Ds Based( pHdrInf )
D HiUsrSpcNamSp 10a
D HiUsrSpcLibSp 10a
**-- User space generic header: ---------- -----------------------------**
D UsrSpcHdr Ds Based( pUsrSpc )
D UsOfsHdr 10i 0 Overlay( UsrSpcHdr: 117 )
D UsOfsLst 10i 0 Overlay( UsrSpcHdr: 125 )
D UsNumLstEnt 10i 0 Overlay( UsrSpcHdr: 133 )
D UsSizLstEnt 10i 0 Overlay( UsrSpcHdr: 137 )
**-- User space pointers: ----------------------------------------------**
D pUsrSpc s * Inz( *Null )
D pHdrInf s * Inz( *Null )
D pLstEnt s * Inz( *Null )
**-- TCP/IP attributes: ------------------------------------------------**
D TCPA0100 Ds
D T1BytRtn 10u 0
D T1BytAvl 10u 0
D T1StkSts 10u 0
D T1ActTim 10u 0
D T1LstStrD 8a
D T1LstStrT 6a
D T1LstEndD 8a
D T1LstEndT 6a
D T1StrJob 10a
D T1StrUsr 10a
D T1StrNbr 6a
D T1StrJobInt 16a
D T1EndJob 10a
D T1EndUsr 10a
D T1EndNbr 6a
D T1EndJobInt 16a
D T1OfsAddInf 10u 0
D T1LenAddInf 10u 0
**-- Connection list qualifier: ----------------------------------------**
D NCLQ0100 Ds
D N1NetCnnTyp 10a Inz( '*ALL' )
D N1LstRqsTyp 10a Inz( '*ALL' )
D 12a Inz( *Allx'00' )
D N1LocAdrLow 10u 0 Inz( 0 )
D N1LocAdrUpr 10u 0 Inz( 0 )
D N1LocPortLow 10u 0 Inz( 0 )
D N1LocPortUpr 10u 0 Inz( 0 )
D N1RmtAdrLow 10u 0 Inz( 0 )
D N1RmtAdrUpr 10u 0 Inz( 0 )
D N1RmtPortLow 10u 0 Inz( 0 )
D N1RmmPortUpr 10u 0 Inz( 0 )
**-- Connection list entry: --------------------------------------------**
D NCNN0100 Ds Based( pLstEnt )
D C1RmtAdr 15a
D 1a
D C1RmtAdrBin 10u 0
D C1LocAdr 15a
D 1a
D C1LocAdrBin 10u 0
D C1RmtPort 10u 0
D C1LocPort 10u 0
D C1TcpState 10u 0
D C1IdlTimMs 10u 0
D C1BytIn 20u 0
D C1BytOut 20u 0
D C1ConOpnTyp 10u 0
D C1NetCnnTyp 10a
D 1a
**-- Following fields were added in V5R2 - do not reference in V5R1:
D 1a
D C1AscUsrPrf 10a
D 2a
**-- Socket connection request: ----------------------------------------**
D SocCnnRqs Ds
D ScProtocol 10u 0
D ScLocIpAdr 10u 0
D ScLocPortNbr 10u 0
D ScRmtIpAdr 10u 0
D ScRmtPortNbr 10u 0
**-- Connection data: --------------------------------------------------**
D NCND0100 Ds Based( pCnnDta )
D D1BytRtn 10u 0
D D1BytAvl 10u 0
D D1CurCnnEst 10u 0
D D1ActOpn 10u 0
D D1PasOpn 10u 0
D D1AttOpnFail 10u 0
D D1EstNxtRes 10u 0
D D1SegSnt 10u 0
D D1SegRtr 10u 0
D D1SegRsn 10u 0
D D1SegRcv 10u 0
D D1SegRcvErr 10u 0
D D1DtgSnt 10u 0
D D1DtgRcv 10u 0
D D1DtgNdlPort 10u 0
D D1DtgNdlOde 10u 0
D D1AddInfOfs 10u 0
D D1AddInfLen 10u 0
**
D NCND0200 Ds Based( pCnnDtaInf )
D D2Protocol 10u 0
D D2LocIpAdr 10u 0
D D2LocPortNbr 10u 0
D D2RmtIpAdr 10u 0
D D2RmtPortNbr 10u 0
D D2RndTrpTim 10u 0
D D2RndTrpVar 10u 0
D D2OutBytBuf 10u 0
D D2UsrSndNxt 10u 0
D D2SndNxt 10u 0
D D2SndUnack 10u 0
D D2OutPshNbr 10u 0
D D2OutUrgNbr 10u 0
D D2OutWdwNbr 10u 0
D D2IncBytBuf 10u 0
D D2RcvNxt 10u 0
D D2UsrRcvNxt 10u 0
D D2IncPshNbr 10u 0
D D2IncUrgNbr 10u 0
D D2IncWdwNbr 10u 0
D D2TotRtr 10u 0
D D2CurRtr 10u 0
D D2MaxWdwSiz 10u 0
D D2CurWdwSiz 10u 0
D D2LastUpd 10u 0
D D2LastUpdAck 10u 0
D D2CngWdw 10u 0
D D2SlwStrThr 10u 0
D D2MaxSegSiz 10u 0
D D2InzSndSeqNb 10u 0
D D2InzRcvSeqNb 10u 0
D D2CnnTspLayer 10u 0
D D2TcpState 10u 0
D D2CnnOpnTyp 10u 0
D D2IdlTimMs 10u 0
D D2IpOpt 40a
D D2BytIn 10u 0
D D2BytOut 10u 0
D D2SocState 10u 0
D D2SocLstOfs 10u 0
D D2SocEntNbr 10u 0
D D2SocEntLen 10u 0
D D2JobLstOfs 10u 0
D D2JobEntNbr 10u 0
D D2JobEntLen 10u 0
**-- Following fields were added in V5R2 - do not reference in V5R1:
D D2AscUsrPrf 10a
D 2a
**-- Socket options list:
D SocOptLst Ds Based( pSocOptLst )
D SoSocOpt 10u 0
D SoOptVal 10u 0
**-- Associated jobs/tasks list:
D JobCnnLst Ds Based( pJobCnnLst )
D JcFmtEnt 10u 0
D JcTskNam 16a
D JcJobNam 10a
D JcJobUsr 10a
D JcJobNbr 6a
D JcJobId 16a
**-- Create user space: -------------------------------------------------**
D CrtUsrSpc Pr ExtPgm( 'QUSCRTUS' )
D CsSpcNamQ 20a Const
D C***tAtr 10a Const
D CsInzSiz 10i 0 Const
D CsInzVal 1a Const
D CsPubAut 10a Const
D CsText 50a Const
**-- Optional 1:
D CsReplace 10a Const Options( *NoPass )
D CsError 32767a Options( *NoPass: *VarSize )
**-- Optional 2:
D CsDomain 10a Const Options( *NoPass )
**-- Delete user space: -------------------------------------------------**
D DltUsrSpc Pr ExtPgm( 'QUSDLTUS' )
D DsSpcNamQ 20a Const
D DsError 32767a Options( *VarSize )
**-- Retrieve pointer to user space: ------------------------------------**
D RtvPtrSpc Pr ExtPgm( 'QUSPTRUS' )
D RpSpcNamQ 20a Const
D RpPointer *
D RpError 32767a Options( *NoPass: *VarSize )
**-- Retrieve TCP/IP attributes: ---------------------------------------**
D RtvTcpA Pr ExtProc( 'QtocRtvTCPA' )
D RtRcvVar 32767a Options( *VarSize )
D RtRcvVarLen 10i 0 Const
D RtFmtNam 8a Const
D RtError 32767a Options( *VarSize )
**-- List network connections: -----------------------------------------**
D LstNetCnn Pr ExtProc( 'QtocLstNetCnn' )
D LcSpcNamQ 20a Const
D LcFmtNam 8a Const
D LcCnnQual 64a Const
D LcCnnQualSiz 10i 0 Const
D LcCnnQualFmt 8a Const
D LcError 32767a Options( *VarSize )
**-- Retrieve network connection data: ---------------------------------**
D RtvCnnDta Pr ExtProc( 'QtocRtvNetCnnDta' )
D RcRcvVar 65535a Options( *VarSize )
D RcRcvVarLen 10i 0 Const
D RcFmtNam 8a Const
D RcSocCnnRqs 20a Const
D RcError 32767a Options( *VarSize )
**
**-- Mainline: ---------------------------------------------------------**
**
C Time Time
C Except Header
**
C CallP RtvTcpA( TCPA0100
C : %Size( TCPA0100 )
C : 'TCPA0100'
C : ApiError
C )
**
C Select
C When AeBytAvl > *Zero
**-- Error occurred...
C Except NoStack
**
C When T1StkSts = 0 Or
C T1StkSts = 2
**-- TCP/IP stack not operational...
C Except NoStack
**
C Other
C Eval BytAlc = 32767
C Eval pCnnDta = %Alloc( BytAlc )
**
C CallP CrtUsrSpc( UsrSpc
C : *Blanks
C : 65535
C : x'00'
C : '*CHANGE'
C : *Blanks
C : '*YES'
C : ApiError
C )
**
C CallP LstNetCnn( UsrSpc
C : 'NCNN0100'
C : NCLQ0100
C : %Size( NCLQ0100 )
C : 'NCLQ0100'
C : ApiError
C )
**
C If AeBytAvl = *Zero
C ExSr PrcLstEnt
C EndIf
**
C CallP DltUsrSpc( UsrSpc
C : ApiError
C )
**
C DeAlloc pCnnDta
**
C If NbrRcds = *Zero
C Except NoRcds
C EndIf
C EndSl
**
C Eval *InLr = *On
C Return
**
**-- Process list entries: ---------------------------------------------**
C PrcLstEnt BegSr
**
C CallP RtvPtrSpc( UsrSpc
C : pUsrSpc
C )
**
C Eval pHdrInf = pUsrSpc + UsOfsHdr
C Eval pLstEnt = pUsrSpc + UsOfsLst
**
C For Lix = 1 to UsNumLstEnt
**
C ExSr PrtCnnDtl
**
C Select
C When C1NetCnnTyp = '*TCP'
C Eval ScProtocol = 1
**
C When C1NetCnnTyp = '*UDP'
C Eval ScProtocol = 2
**
C Other
C Eval ScProtocol = 0
C EndSl
C
C If ScProtocol > 0
**
C Eval ScLocIpAdr = C1LocAdrBin
C Eval ScLocPortNbr= C1LocPort
C Eval ScRmtIpAdr = C1RmtAdrBin
C Eval ScRmtPortNbr= C1RmtPort
**
C DoU D1BytAvl <= BytAlc
**
C If D1BytAvl > BytAlc
C Eval BytAlc = D1BytAvl
C Eval pCnnDta = %ReAlloc( pCnnDta: BytAlc )
C EndIf
**
C CallP RtvCnnDta( NCND0100
C : BytAlc
C : 'NCND0200'
C : SocCnnRqs
C : ApiError
C )
C EndDo
**
C If AeBytAvl = *Zero
C ExSr PrcDtaEnt
C EndIf
C EndIf
**
C If Lix < UsNumLstEnt
C Eval pLstEnt = pLstEnt + UsSizLstEnt
C EndIf
C EndFor
**
C EndSr
**-- Process data list entries: ----------------------------------------**
C PrcDtaEnt BegSr
**
C Eval pCnnDtaInf = pCnnDta + D1AddInfOfs
**
**-- Socket options:
C Eval pSocOptLst = pCnnDta + D2SocLstOfs
C For Dix = 1 to D2SocEntNbr
**
**--
C If Dix < D2SocEntNbr
C Eval pSocOptLst = pSocOptLst + D2SocEntLen
C EndIf
C EndFor
**
**-- Associated jobs:
C Eval pJobCnnLst = pCnnDta + D2JobLstOfs
**
C For Dix = 1 to D2JobEntNbr
**
C If JcFmtEnt = 1
C ExSr PrtJobDtl
C EndIf
**
C If Dix < D2JobEntNbr
C Eval pJobCnnLst = pJobCnnLst + D2JobEntLen
C EndIf
C EndFor
**
C EndSr
**-- Print connection detail line: -------------------------------------**
C PrtCnnDtl BegSr
**
C If PlCurLin > PlOvfLin - 3
C Except Header
C EndIf
**
C Eval TcpCnnStt = TcpStt(C1TcpState + 1)
C Eval ConOpnTyp = OpnTyp(C1ConOpnTyp + 1)
**
C Eval NbrRcds = NbrRcds + 1
C Except CnnDtl
**
C EndSr
**-- Print connection job detail line: ---------------------------------**
C PrtJobDtl BegSr
**
C If PlCurLin > PlOvfLin - 2
C Except Header
C EndIf
**
C Except JobDtl
**
C EndSr
**-- Print file definition: --------------------------------------------**
OQSYSPRT EF Header 2 3
O UDATE Y 8
O Time 18 ' : : '
O 75 'Print TCP/IP connection -
O status'
O 107 'Program:'
O PsPgmNam 118
O 126 'Page:'
O PAGE + 1
OQSYSPRT EF Header 1
O 14 'Remote address'
O 25 '- Port'
O 40 'Local address'
O 52 '- Port'
O 58 'Type'
O 70 'Open'
O 76 'State'
O 90 'Idle time ms'
O 111 'Bytes in'
O 132 'Bytes out'
**
OQSYSPRT EF CnnDtl 1
O C1RmtAdr 15
O C1RmtPort 3 25
O C1LocAdr 42
O C1LocPort 3 52
O C1NetCnnTyp 64
O ConOpnTyp 69
O TcpCnnStt 76
O C1IdlTimMs 3 90
O C1BytIn 3 111
O C1BytOut 3 132
**
OQSYSPRT EF JobDtl 1
O 22 'Connection job name:'
O JcJobNam 33
O 41 '- user:'
O JcJobUsr 52
O 61 '- number:'
O JcJobNbr 68
**
OQSYSPRT EF NoStack 1
O 26 '(TCP/IP stack not active)'
OQSYSPRT EF NoRcds 1
O 26 '(No entries found)'
Thanks to Carsten Flensburg
阅读(1020) | 评论(0) | 转发(1) |