Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1298570
  • 博文数量: 287
  • 博客积分: 11000
  • 博客等级: 上将
  • 技术积分: 3833
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-16 08:43
文章分类
文章存档

2013年(15)

2012年(17)

2011年(17)

2010年(135)

2009年(85)

2008年(18)

分类: 系统运维

2010-06-05 09:17:09

List Network Interfaces
Q: Greetings! I would like to check the status of a TCP/IP interface. If the status is not *active I would want to get a notification to the system operator, and if the status is failed to vary off and on. Can this be accomplished in a CL?

A: Netstat has no output other than the display. And the Work with interfaces option of CFGTCP menu has no command equivalent. But if you are on v5r1, or later, there are now APIs that let you retrieve the status of interfaces, as well as other TCP/IP operational info. In tnis case, List Network Interface (QtocLstNetIfc) puts all the interface info into a user space. You'd need to poll the status from time to time. This can be called (CALLPRC) from a CLLE - Service Program: QTOCNETSTS. You don't need to name the service program in the compile - it's included automatically. CALLPRC PRC('QtocLstNetIfc') + PARM('X QTEMP ' + 'NIFC0100' + X'0000000000000000') does the trick, putting the data into *USRSPC QTEMP/X. Then use the appropriate user space APIs to get the information. Look up CL & APIs under Programming in InfoCenter. Thanks to Vern Hamberg

And with RPG: * CRTRPGMOD MODULE(NETIFCR) SRCFILE(xxx/QRPGLESRC) SRCMBR(NETIFCR) * CRTPGM PGM(NETIFCR) BNDSRVPGM(QTOCNETSTS) * H DEBUG OPTION(*SRCSTMT:*NODEBUGIO) BNDDIR('QC2LE') H dftactgrp(*NO) FQSYSPRT O F 198 Printer USROPN D uSpaceName s 20 inz('NETIFC QTEMP ') D cmdStr1 s 256 inz('OVRPRTF FILE(QSYSPRT) PAGESIZE(- D *N 198) CPI(15) OVRSCOPE(*JOB)') D cmdStr2 s 256 inz('DLTOVR FILE(QSYSPRT) LVL(*JOB)') *---------------------------------------------------------------- * Get user space list info from header section. *---------------------------------------------------------------- D ds based(uHeadPtr) D uOffSetToList 125 128i 0 D uNumOfEntrys 133 136i 0 D uSizeOfEntry 137 140i 0 * D uListEntry1 ds Based(uListPtr ) D InetAdr 15 overlay(uListEntry1:1) D Reservedr 1 overlay(uListEntry1:16) D InetAdrb 10i 0 overlay(uListEntry1:17) D NetAdr 15 overlay(uListEntry1:21) D Reserved1 1 overlay(uListEntry1:36) D NetAdrb 10i 0 overlay(uListEntry1:37) D NetName 10 overlay(uListEntry1:41) D LineDsc 10 overlay(uListEntry1:51) D IfcName 10 overlay(uListEntry1:61) D Reserved2 2 overlay(uListEntry1:71) D IfcSts 10i 0 overlay(uListEntry1:73) D IfcTypSrv 10i 0 overlay(uListEntry1:77) D IfcMtu 10i 0 overlay(uListEntry1:81) D IfcLinTyp 10i 0 overlay(uListEntry1:85) D HostAdr 15 overlay(uListEntry1:89) D Reserved3 1a overlay(uListEntry1:104) D HostAdrb 10i 0 overlay(uListEntry1:105) D IfcSbnMask 15 overlay(uListEntry1:109) D Reserved4 1a overlay(uListEntry1:124) D IfcSbnMaskb 10i 0 overlay(uListEntry1:125) D DrtBrdCstAdr 15 overlay(uListEntry1:129) D Reserved5 1a overlay(uListEntry1:144) D DrtBrdCstAdrb 10i 0 overlay(uListEntry1:145) D ChgDate 8 overlay(uListEntry1:149) D ChgTime 6 overlay(uListEntry1:157) D AsoLclIfc 15 overlay(uListEntry1:163) D Reserved6 3a overlay(uListEntry1:178) D AsoLclIfcb 10i 0 overlay(uListEntry1:181) D ChgSts 10i 0 overlay(uListEntry1:185) D PacketRules 10i 0 overlay(uListEntry1:189) D AutoStart 10i 0 overlay(uListEntry1:193) D TorkenRingSeq 10i 0 overlay(uListEntry1:197) D IfcType 10i 0 overlay(uListEntry1:201) D ProxyARPEbl 10i 0 overlay(uListEntry1:205) D ProxyARPAlw 10i 0 overlay(uListEntry1:209) D CfgMTU 10i 0 overlay(uListEntry1:213) D NetNameFull 24 overlay(uListEntry1:217) D IfcNameFull 24 overlay(uListEntry1:241) *---------------------------------------------------------------- * Error return code parm for APIs. *---------------------------------------------------------------- D vApiErrDs ds D vbytpv 10i 0 inz(%size(vApiErrDs)) D vbytav 10i 0 inz(0) D vmsgid 7a D vresvd 1a D vrpldta 50a *---------------------------------------------------------------- * Create Prototypes for calls *---------------------------------------------------------------- **-- Create user space: ----------------------------------------- D quscrtus PR ExtPgm('QUSCRTUS') D 20 D 10 const D 10i 0 const D 1 const D 10 const D 50 const D 10 const Db like(vApiErrDS) **-- Delete user space: ------------------------------------------ D qusdltus Pr ExtPgm( 'QUSDLTUS' ) D 20 Const Db like(vApiErrDS) **-- Call system command: --------------------------------------- D system PR 10I 0 extproc('system') D i_cmd * value options(*string) * D EXCP_MSGID S 7A import('_EXCP_MSGID') **-- List network connections: ---------------------------------- D LstNetIfc PR ExtProc('QtocLstNetIfc') D 20 D 8 const Db like(vApiErrDS) **-- Retrieve pointer to user space: ---------------------------- D qusptrus PR ExtPgm('QUSPTRUS') D 20 D * Db like(vApiErrDS) D main PR extpgm('NETIFCR') D main PI *---------------------------------------------------------------- * Create user space C callp QUSCRTUS( C uSpaceName: C 'TEST': C 1500000: C x'00': C '*ALL': C 'User Space JCR ': C '*NO': C vApiErrDs) * Get pointer to user space C callp QUSPTRUS( C uSpaceName: C uHeadPtr: C vApiErrDs) * call api to load job log into user space. C callp LstNetIfc( C uSpaceName: C 'NIFC0100': C vApiErrDs) * Process elements * C callp system(cmdStr1) C open QSYSPRT C eval uListPtr = uHeadPtr + uOffSetToList C except Head 1B C do uNumOfEntrys C exsr cvtTxtSr C except Out C eval uListPtr = uListPtr + uSizeOfEntry 1E C enddo C close QSYSPRT C callp system(cmdStr2) * Delete user space C callp qusdltus( C uSpaceName: C vApiErrDs) * C eval *inlr = *on C return **-- Convert text : ---------------------------------------------- C cvtTxtSr BegSr C Move *blanks IfcStsC 11 C Select C When IfcSts = 0 c eval IfcStsC = 'Inactive' C When IfcSts = 1 c eval IfcStsC = 'Active' C When IfcSts = 2 c eval IfcStsC = 'Starting' C When IfcSts = 3 c eval IfcStsC = 'Ending' C When IfcSts = 4 c eval IfcStsC = 'RCYPND' C When IfcSts = 5 c eval IfcStsC = 'RCYCNL' C When IfcSts = 6 c eval IfcStsC = 'Failed' C When IfcSts = 7 c eval IfcStsC = 'Failed(TCP)' C When IfcSts = 8 c eval IfcStsC = 'DOD' C EndSl C EndSr OQSYSPRT E HEAD 1 O 8 'Inet Adr' O 23 'Net Adr' O 40 'Net Name' O 51 'Line Dsc' O 61 'Ifc Name' O 75 'Ifc Status' O 85 'Host Adr' O E OUT 1 O InetAdr O NetAdr + 1 O NetName + 1 O LineDsc + 1 O IfcName + 1 O IfcStsC + 1 O HostAdr + 1 Thanks to Vengoal Chang

阅读(1058) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~