• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2956
  • Last Modified:

Retrieveing the AS400 IP Address or Hostname using RPG.

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
jdwan
Asked:
jdwan
  • 3
  • 2
  • 2
  • +1
1 Solution
 
dedy_djajapermanaCommented:
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
 
jdwanAuthor Commented:
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
 
ShadowProgrammerCommented:
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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dedy_djajapermanaCommented:
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
 
tliottaCommented:
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
 
tliottaCommented:
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
 
jdwanAuthor Commented:
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
 
tliottaCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now