?
Solved

Retrieveing the AS400 IP Address or Hostname using RPG.

Posted on 2005-03-29
10
Medium Priority
?
2,796 Views
Last Modified: 2008-01-09
I am currently developing a CGI program (using RPG) which will output an email which contains a URL to another program which allows the user to click on the link to easliy access the program. I have got the RPG program woorking fine and the email is generated however the only hicup is that i have had to hardcode the URL into the program so that it can be written to the email contents.  

My dilema now is that when i move the program between three different evironments (development, quality, and production) i am required to change the hardcoded section of code. I have been playing around with C procedures and trying to implement these within the RPG to try and retrieve the IP address of hostname, however i am struggling to find a solution as everything i have come across needs one to retrieve the other (ie need IP address to retrive the host name and vice versa). Is there a procedure that API which i can use which will simply identify the HOSTNAME or IP Address for the AS400.


The three environments are located to two separate machines, development and quality on one machine and production on another, obviously there are two difference IP address for the two machines and the only difference between the development and quality URL's is that the Quality URL contains a port number, i have determine who to extract the port number being used, am just struggling on the IP address or host name.

Any help would be greatly appreciated.

Thanks in advance.
Jon
0
Comment
Question by:jdwan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
10 Comments
 
LVL 6

Expert Comment

by:dedy_djajapermana
ID: 13659525
Hi Jon,

The list of interface (IP addesses) of AS/400 are stored in file QUSRSYS/QATOCIFC
You can retrieve the IP address from the file.

cheers!
dd
0
 

Author Comment

by:jdwan
ID: 13659573
dd,

Thanks, however i did come across this file in my prior searching the reason i didn't use this file was because there are several IP addresses in the file and i need to determine which one to use still, for example if i am accessing my program externally, the as400 has been set up to have a remote IP address, as far as i can see this solution still doesn't get me away from having to have some type of hardcoding in my program (unless i am missing something with the file) i would prefer to be able to retrieve the hostname or ip address on the fly with out have to make assumption or hardcode anything.

I am not even sure if what i am asking is trying to be a little to smart.

Regards
Jon
0
 
LVL 9

Expert Comment

by:ShadowProgrammer
ID: 13659643
In instances like this, failing anyone providing EXACTLY the solution of being able to retrieve the data, I would suggest you create a data area in each environment to hold the required information, you can then retrieve that easily in either RPG or CL.
To complete the solution, if necessary a simple CL (or complex RPG) + display file can be created to be a maintenance program.
As an extra to that program, you could also validate that the IP address entered matches one of the IP addresses stored in QUSRSYS/QATOCIFC or even show these as a list for one to be selected.

If you have the authority, make the data area owner QSECOFR with *PUBLIC only having read rights. Make the maintence program owner QSECOFR, running under owners authority so that way - no one without *SECOFR authority can change the data area.

Tony.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 6

Expert Comment

by:dedy_djajapermana
ID: 13659648
i'm using V5R1M0 at this moment, and afaik, no such function to retrieve the IP address of local system.
i don't quite understand with
<quote>
the as400 has been set up to have a remote IP address, as far as i can see this solution still doesn't get me away from having to have some type of hardcoding in my program
<unquote>

do you have multiple interface in your system?
otherwise, your ip address is always the last entry of the file
0
 
LVL 27

Accepted Solution

by:
tliotta earned 2000 total points
ID: 13665975
Jon:

You're right in not using the file. The IP address should be retrieved via API. I'll try to list the API sequence this evening... I'm far too busy this afternoon.

Tom
0
 
LVL 27

Expert Comment

by:tliotta
ID: 13667811
Jon:

You'll want to call three APIs in order -- gethostname() to get the default host name for the system you're running on, then gethostbyname() to resolve that host name to a network address. The network address can then be converted to dotted-decimal format with inetntoa().

Tom
0
 

Author Comment

by:jdwan
ID: 13676760
Thanks Tom,

I have had a bit of a paly around with these API's hopefully you will be able to help me from here, i am not that familiar with C procedures with in the RPG, but i have had ago at it, still seem to be having some problems, i have added the code i am using below, would you please be able to have a llok at it to see if you can see any obvious problems (keeping in mind that i am not familar with converting C procedures into RPG).

With my code it doesn't even appear to get past the line

gethostname(p_host:p_length)      

When debugging, this procedure returns -1, which is the unsuccessful code, as mentioned before ay help would be appreciated.

Thanks
Jon

H DFTACTGRP(*NO) ACTGRP(*NEW)                                                  
D gethostname     PR            10I 0 ExtProc('gethostname')                    
D   g_h_name                      *   value options(*string)                    
D   g_h_length                  10I 0                                          
 *                                                                              
D INADDR_NONE     C                   CONST(4294967295)                        
                                                                               
D inet_ntoa       PR              *   ExtProc('inet_ntoa')                      
D  internet_addr                10U 0 value                                    
                                                                               
D p_hostent       S               *                                            
D hostent         DS                  Based(p_hostent)                          
D   h_name                        *                                            
D   h_aliases                     *                                            
D   h_addrtype                  10I 0                                          
D   h_length                    10I 0                                          
D   h_addr_list                   *                                            
D p_h_addr        S               *   Based(h_addr_list)                        
D h_addr          S             10U 0 Based(p_h_addr)                    
D gethostbyname   PR              *   extproc('gethostbyname')          
D   host_name                     *   value options(*string)            
                                                                         
D p_host          S               *                                      
D p_address       S               *                                      
D p_length        S             10I 0                                    
D p_rtrn          S             10I 0                                    
 *                                                                      
D host            S             32A   based(p_host)                      
D IP              S             10U 0                                    
D Msg             S             50A                                      
                                                                         
C                   eval      p_length = %size(p_host)                  
C                   alloc     p_length      p_address                    
C                   eval      p_host = p_address                        
 *                                                                      
C                   eval      p_rtrn = gethostname(p_host:p_length)      
C                   if        p_rtrn = 0                                
c                   eval      p_hostent = gethostbyname(%trim(host))        
                                                                           
c                   if        p_hostent <> *NULL                            
c                   eval      IP = h_addr                                  
c                   endif                                                  
                                                                           
c                   if        IP = INADDR_NONE                              
c                   eval      Msg = 'Host not found! (gethostbyname)'      
c                   else                                                    
c                   eval      Msg = 'IP = ' + %str(inet_ntoa(IP))          
c                   endif                                                  
                                                                       
c                   else                                                                                                                              
c                   eval      Msg = 'Host not found! (gethostname)'                                                                                
c                   endif                                                  
                                                                           
c                   dsply                   Msg                            
c                   eval      *inlr = *on                                  
0
 
LVL 27

Expert Comment

by:tliotta
ID: 13677964
Jon:

I'd say start with:

*---------------- begin
D p_host          S               *                                      
...
C                   eval      p_length = %size(p_host)                  
*---------------- end

I'm pretty sure you don't want the size of p_host in bytes which would be <16> since that's the size of a pointer.

Perhaps better would be:

*---------------- begin
D p_host          S               *                                      
D host_name       S            256    based( p_host )
...
C                   eval      p_length = %size(host_name)                
*---------------- end

Of course, if you're going to reserve 256 bytes, there's no need to do anything but just declare host_name and forget alloc/dealloc. And since you'll want to allow for 255 bytes plus trailing null, you might as well just say "set aside 256 bytes".

In any case, you definitely don't want to reserve just the length of a pointer.

Now, you seem familiar enough with the APIs since you've pretty much coded reasonably; are you then familiar with using them in C? If so, why not just write it as a C module and bind it in to whatever your program is?

Finally, keep this handy:

http://www.opensource400.org/callc.html

Tom
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question