Problem solve Get help with specific problems with your technologies, process and projects.

No more QPADEV* devices with Telnet sessions

Learn how this Telnet exit program generates a useful device name for incoming Telnet sessions.

This Telnet exit program generates a useful device name for incoming Telnet sessions. It looks up the hostname in the DNS and uses it to generate a device name. When it doesn't find a name in the DNS it generates a device name from the last two bytes from the IP address of the Telnet session. This can be useful when the device name, such as QPADEV0001, gives no clue as to the location of the connection. This utility is very useful when routing different groups of users to different subsystems. Another advantage is that interactive jobs can be disconnected by the system and sign on again in the normal way when you use the QINACTITV system value.

Works like a charm!


  Installation program (CL):
             PGM                                                      
             CHGOBJOWN  OBJ(QGPL/TNEXCL) OBJTYPE(*PGM) NEWOWN(QSECOFR)
             CHGOBJOWN  OBJ(QGPL/TNEXRP) OBJTYPE(*PGM) NEWOWN(QSECOFR)
             RVKOBJAUT  OBJ(QGPL/TNEXCL) OBJTYPE(*PGM) USER(*ALL) +   
                          AUT(*ALL)                                   
             RVKOBJAUT  OBJ(QGPL/TNEXRP) OBJTYPE(*PGM) USER(*ALL) +   
                          AUT(*ALL)                                   
             CHGPGM     PGM(TNEXCL) USRPRF(*OWNER)                    
             ADDEXITPGM EXITPNT(QIBM_QTG_DEVINIT) FORMAT(INIT0100) +  
                          PGMNBR(1) PGM(QGPL/TNEXCL) TEXT('TN +       
                          SERVER EXIT PROGRAM') REPLACE(*YES)         
             ENDPGM                                                   


Telnet Exit CL program:

             PGM        PARM(&USRDI &DEVDI &CNNDI &ENVOPT &ENVLEN +
                          &ALWCNN &ALWASG)
             DCL        VAR(&N) TYPE(*CHAR) LEN(3) VALUE(X'000000')
             DCL        VAR(&D1) TYPE(*CHAR) LEN(4)
             DCL        VAR(&D3) TYPE(*CHAR) LEN(4)
             DCL        VAR(&D2) TYPE(*DEC) LEN(8)

             DCL        VAR(&USRDI) TYPE(*CHAR) LEN(1024)
             DCL        VAR(&DEVDI) TYPE(*CHAR) LEN(1024)
             DCL        VAR(&CNNDI) TYPE(*CHAR) LEN(1024)
             DCL        VAR(&ENVOPT) TYPE(*CHAR) LEN(1024)
             DCL        VAR(&ENVLEN) TYPE(*CHAR) LEN(4)
             DCL        VAR(&ALWCNN) TYPE(*CHAR) LEN(1)
             DCL        VAR(&ALWASG) TYPE(*CHAR) LEN(1)
             DCL        VAR(&ADDR) TYPE(*CHAR) LEN(4)
             DCL        VAR(&HOSTNAME1) TYPE(*CHAR) LEN(256)
             DCL        VAR(&HOSTNAME2) TYPE(*CHAR) LEN(256)
             DCL        VAR(&HOSTNAME3) TYPE(*CHAR) LEN(256)
             DCL        VAR(&NAME) TYPE(*CHAR) LEN(10)
             DCL        VAR(&X) TYPE(*DEC) LEN(3)
             DCL        VAR(&ABC) TYPE(*CHAR) LEN(26) +
                          VALUE('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
             DCL        VAR(&DEVD) TYPE(*CHAR) LEN(10)
             DCL        VAR(&STS) TYPE(*DEC) LEN(5)
             MONMSG     MSGID(CPF0000)

/* IF USER HAS DEFINED A DEVICE NAME  */
             CHGVAR     VAR(&DEVD) VALUE(%SST(&DEVDI 1 10))
             IF         COND(&DEVD *NE ' ') THEN(RETURN)
/* DO  NOTHING */

             CHGVAR     VAR(&ADDR) VALUE(%SST(&CNNDI 9 4))
             CALL       PGM(TNEXRP) PARM(&ADDR &HOSTNAME1 &HOSTNAME2 +
                          &HOSTNAME3) /* DNS lookup */
             MONMSG     MSGID(CPF0000) EXEC(DO)
             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +
                          MSGDTA('Programm TNEXRP not found in +
                          *LIBL') TOMSGQ(*SYSOPR)
             GOTO       CMDLBL(END)
             ENDDO
             /* DEVICE = HOSTNAME*/
             CHGVAR     VAR(&NAME) VALUE(&HOSTNAME3)

/*  HOSTNAME NOT FOUND THEN LAST 2 BYTES  IP ADDRESS */
             IF         COND(&NAME *EQ ' ') THEN(DO)
             CHGVAR     VAR(&D1) VALUE(&N *CAT %SST(&ADDR 3 1))
             CHGVAR     VAR(&D2) VALUE(%BIN(&D1))
             CHGVAR     VAR(&D1) VALUE(&D2)

             CHGVAR     VAR(&D3) VALUE(&N *CAT %SST(&ADDR 4 1))
             CHGVAR     VAR(&D2) VALUE(%BIN(&D3))
             CHGVAR     VAR(&D3) VALUE(&D2)
             CHGVAR     VAR(&NAME) VALUE('I' *CAT %SST(&D1 2 3) *CAT +
                          %SST(&D3 2 3))
             ENDDO


             IF         COND(&NAME *EQ ' ') THEN(GOTO CMDLBL(END))

             IF         COND(%SST(&NAME 10 1) *NE ' ') THEN(CHGVAR +
                          VAR(%SST(&NAME 10 1)) VALUE(' '))
/* SEARCH AVAILABLE DEVICE */
 NXT:        CHGVAR     VAR(&X) VALUE(&X + 1)
             IF         COND(&X *EQ 27) THEN(GOTO CMDLBL(END))
             CHGVAR     VAR(&DEVD) VALUE(&NAME *TCAT %SST(&ABC &X 1))
             RTVCFGSTS  CFGD(&DEVD) CFGTYPE(*DEV) STSCDE(&STS)
             MONMSG     MSGID(CPF9801) EXEC(CHGVAR VAR(&STS) VALUE(0))
             IF         COND(&STS *GT 20) THEN(GOTO NXT)
             CHGVAR     VAR(%SST(&DEVDI 1 10)) VALUE(&DEVD)
 END:        ENDPGM


RPGLE program for DNS lookup:

     hbnddir('QC2LE')
      *
     dgethostba        pr              *   extproc('gethostbyaddr')
     d                                 *   value
     d                               10i 0 value
     d                               10i 0 value
      *
     di                s              5  0
     dx                s              5  0
     dp                s               *
     dphostname        s               *   based(p)
     dl                c                   'abcdefghijklmnopqrstuvwxyz-'
     du                c                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
      *
     c     *entry        plist
     c                   parm                    addr              4
     c                   parm                    hostname1       256
     c                   parm                    hostname2       256
     c                   parm                    hostname3       256
     c                   eval      p=gethostba(%addr(addr):4:2)
     c                   if        p<>*NULL
     c                   eval      hostname1=%str(phostname:256)
     c                   else
     c                   eval      hostname1=''
     c                   endif
      * Hostname whithou domain name
     c                   eval      i=%scan('.':hostname1:1)
     c                   if        i>1
     c                   eval      i=i-1
     c                   eval      hostname2=%subst(hostname1:1:i)
     c                   else
     c                   eval      hostname2=''
     c                   endif
     c     l:u           xlate     hostname2     hostname3
      *
     c                   move      *on           *inlr 

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our systems management gurus are waiting to answer your technical questions.

Dig Deeper on Performance

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close