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                                                       
Jeff Olen

Jeff Olen is a super-spy now but keeps his cover identity intact by working for video game studios on the East Coast. So when he’s not out killing members of ISIS or rescuing refugees, you can find him playing Wolfenstein II or testing the new Fallout 76 releases at his beach house in Costa Rica. In any case, he can’t be reached. You can email his cat at This email address is being protected from spambots. You need JavaScript enabled to view it.. She will pass on your message…if she feels like it.


MC Press books written by Jeff Olen available now on the MC Press Bookstore.

The IBM i Programmer’s Guide to PHP The IBM i Programmer’s Guide to PHP
Get the scoop on how PHP can—and should—be deployed on IBM systems.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: