Retrieve iSeries Host Name

I have a CL that I am using to monitor system messages and I want to be able to alert our helpdesk with the server name of the issue. Originally I was pulling the System Name value from RTVNETA, but can't do this because we have production and HA failover servers with the same 'system name'.  I want to use the TCP Host Name (configured in the CHGTCPDMN command.

Does anyone know of a way to pull that information within a CL?

I appreciate any help.
Matthew RoessnerSenior Systems ProgrammerAsked:
Who is Participating?
Matthew RoessnerConnect With a Mentor Senior Systems ProgrammerAuthor Commented:
I actually found and used a different API. My code is below for anyone who wants to check it out:


/*DECLARE VARIABLES */                                      
         DCL  &name           *CHAR     (10)                
         DCL  &RcvVar         *CHAR     750                
             DCL        VAR(&APIERR) TYPE(*CHAR) LEN(8) +  
             DCL        VAR(&FORMAT) TYPE(*CHAR) LEN(8) +  
         dcl  &RcvVarLen      *CHAR     4                  
     chgvar %Bin(&RcvVarLen) 750                            
     callprc 'QtocRtvTCPA' ( +                              
                            &RcvVar    +                    
                            &RcvVarLen +                    
                            &Format    +                      
    chgvar &name %SST(&rcvvar 177 10)                          
              SNDMSG     MSG('Server Name: ' *BCAT &name) +    
Gary PattersonConnect With a Mentor VP Technology / Senior Consultant Commented:
Use the gethostname() API to get the TCP hostname:

- Gary Patterson

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
Do you have any examples of how to use this successfully in a CL program? I had previously found this API, but have been unable to get it working. I am sure it is a result of my lack of knowledge regarding APIs...

Thank you again for the help
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Jon SnydermanConnect With a Mentor Commented:
With CL, you can simply use QSYS/RTVNETA SYSNAME('&VARIABLE').

Jon SnydermanCommented:
Glad it worked, but Wow!  Wouldnt the one liner that I listed be a lot cleaner with lower CPU cycles?

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
The RVTNETA doesn't return the same value as the API I used. We set our 'system name' in the network attributes to be the same as our serial number. We set our TCP name up as the same as our DNS name.  I wanted to retrieve the TCP system name, not the network attribute system name. They are 2 separate things...
Jon SnydermanCommented:
My bad.  Sorry guys.  (back peddling now)  I thought you were looking for the sysname.  Not the TCP host name.

To use gethostname(), code something like this:
   dcl   &hostname    *char  257
   dcl   &size        *int           value( 256 )

   callprc     'gethostname'  ( &hostname (&size *byval) )
   callprc     'strlen'       ( &hostname ) rtnval( &size )

   sndpgmmsg   msg( 'Host name is' *bcat %sst(&hostname 1 &size) )


Open in new window

Compile that example as a *MODULE. Use CRTPGM to bind it as a *pgm while referencing BNDDIR( QC2LE ). The gethostname() API is always available to everything, but strlen() needs to look in the ILE C functions through QC2LE. I can never remember which service program supplies strlen() and related functions, but QC2LE always finds them.

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
Found a different API to use that worked. Thanks guys
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.