TechTip: Getting the IP Address of a Workstation Device

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Someone asked me the other day if it was possible to get the IP address of a workstation. What I found out was that not only is that possible, but you can also find out the IP address of any attached device. It's all done using the QDCRDEVD API. It took me more time to find the information on the API at the IBM Web site than it did to write the function to return the IP address. I've included the code at the end of this article.

The function is really simple once you have the parameters for the API figured out. The name of the device is the only parameter passed into the function. The function then calls the QDCRDEVD and returns the IP address from the data received. I have added some really simple error handling so that the IP address will be "ERROR" if the QDCRDEVD API does not execute properly.

As I mentioned, this same process can be used to determine the IP address of virtually any network device. The function could be modified easily to return IP addresses for other devices. I only needed the workstation devices so I didn't bother with the rest.

There are a few limitations to the QDCRDEVD API that you should be aware of before using it. The first one is that the device name must use all uppercase letters (QPADEV0001, not qapdev0001). If you have lowercase letters, it will return an error. Also, the API will not work at all with a device connected via pass-through (STRPASTHR), and it will not work for PC jobs that are calling RPG and/or CL commands.

There is a plethora of other information available about the device(s) in the datastream returned from QDCRDEVD. If you are interested, go to the IBM Information Center and search for QDCRDEVD.

--Jeff Olen
This email address is being protected from spambots. You need JavaScript enabled to view it.

Code for RTVIPADR


     H NOMAIN                                                                  
      *************************************************************************
      *  RTVIPADR - Retrieve the IP address of a display device               *
      *                                                                       *
      * Uses QDCRDEVD API                                                     *
      *                                                                       *
      *************************************************************************
     D                                                                         
     D* Prototype                                                              
     D RtvIPAdr        PR            15                                        
     D DeviceNm                      10    Value                               
     D                                                                         
      *************************************************************************
      * RtvIPAdR function                                                     *
      *************************************************************************
     P RtvIPAdr        B                   Export                              
     D                                                                         
     D RtvIPAdr        PI            15                                        
     D DeviceNm                      10    Value                               
     D* Declare variables for calling QDCRDEVD API                             
     D Err             S             15                                        
     D DevType         S              8    Inz('DEVD0600')                     
     D DataLen         S              4B 0 Inz(971)                            
     D Data            S            971                                        
     D                                                                         
     D* Data structure for error info                                          
     D ErrorDS         DS                                                      
     D  ErrLen                 1      4B 0 Inz(15)                             
     D  ErrID                  9     15                                        
     D                                                                         
     D* receiver field for IP address                                          
     D IPAddr          S             15                                        
     D                                                                         
     C* Call the QDCRDEVD API                                                  
     C                   Call      'QDCRDEVD'                                  
     C                   Parm                    Data                          
     C                   Parm                    DataLen                       
     C                   Parm                    DevType                       
     C                   Parm                    DeviceNm
     C                   Parm                    Err                           
     C                                                                         
     C* Move error info into Data Structure                                    
     C                   Eval      ErrorDS = Err                               
     C                                                                         
     C* If error found then return "ERROR" otherwise return IP address         
     C                   If        ErrID <> *blanks                            
     C                   Eval      IPAddr = 'ERROR'                            
     C                   Else                                                  
     C* Pull out the IP address                                                
     C                   Eval      IPAddr = %subst(Data:878:15)                
     C                   Endif                                                 
     C                                                                         
     C* Return the IP address to the calling pgm                               
     C                   Return    IPAddr                                      
     P                 E                                                       
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$