× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Scott, thanks for the detailed and educational reply!

Based on your reply, it sounds like this is a FAQ, so I apologize for
posting it.
I only dabble with networking when I must and needed help with the "right"
approach to this particular requirement.  

Here are more details on the requirement.  
Colleague of mine is adding a CBE (Common Base Event) to the existing
commercial tool for our first venture into trying to standardize some of our
tools to comply with Autonomic Computing initiative.  
My understanding of a CBE is that it is simply an XML file.  This XML file
has to have certain tags populated by our code, one of which will be now
notorious "host" IP address.  This CBE will then be made available via
WebService for the world to consume (perhaps Tivoli, not sure; our tool
shouldn't care).
Since the tool could be running in shops with many iSeries and the
WebService consumer (i.e. Tivoli) needs to differentiate between different
iSeries somehow, CBE needs to have the IP tag field populated by our tool.
Based on these requirements, I'd say it falls under "auditing and like"
definition from your post (i.e. system management and tracking).

I realize that iSeries can have many network interfaces, but we can't put
them all in, only one.
I looked at your code and it looks like you're using ioctl calls to get info
on each interface.  This seems like the "right" approach, but how do we pick
one of the interfaces?  Is there a naming convention for the Ethernet line
interfaces?  I think that's the one we'd want, right?  I mean what would be
the point of putting loopback or dial-up interface address?
Ethernet lines are more likely to be used in their internal LAN.

Presently, we have gethostname-gethostbyname-inet_ntoa working in our
development environment by selecting first element of the h_addr_list array,
but as you say, what are the guarantees of it working in all environments.
I don't know how likely they're to have hosts table or DNS setup. I'd think
if they're running something like Tivoli, they'd need something like that,
wouldn't they?

As always, your expert insight is appreciated.  

Elvis 

...nothing's ever easy...

-----Original Message-----
Subject: Re: get host IP address

> I've gone through the archives and it seems that the recommended way to
get
> local host IP address is via gethostbyname function call.

Not this again!

gethostbyname() looks up an IP address for an internet domain name.  It 
searches your local "HOSTS TABLE" and it also searches DNS.  Whether or 
not this will actually give you your "local host IP address" is entirely 
dependent on whether you have a domain name that can be looked up to find 
it in DNS.

It's not a smart way to approach the problem, and unless you're in control 
of how DNS is set up. you shouldn't expect it to work.

Furthermore, you don't assign an IP address to a host. You assign an IP 
address to a network interface.  Sometimes, you even assign more than one 
IP address to a network interface.

Consequently, the "right way" to find out the IP address really depends on 
what you want to use it for.

Consider the scenario of an iSeries system (actually, this is true for all 
computers, not just the iSeries) who is connected to two different 
ethernet LANs, plus a dial-up to the internet.  There are a minimum of 4 
different IP addresses assigned to this iSeries:


127.0.0,1 -- this IP address is always present, and it's used when one
              program on the system wants to communicate with another one
              on the same system.


One is associated with the dial-up (Point to Point) interface for talking
to the internet, and will most likely change with each connection.

One is associated with each of the LAN interfaces.


So now you have 4 IP addresses?  which one is the "Right one"?

Well, if you're talking to another program on the same system (such as 
using FTP to move a file from one place to another, or to print a stream 
file from a batch job) it's safe to hardcode 127.0.0.1.  The nice thing 
about this interface is that it's very fast, very secure (since it's only 
accessible from within the same system) and it'll always be there with the 
same address on every computer that your software gets installed on.

If you're trying to "talk-back" to a 5250 client that has connected, 
you'll need to find out which network interface they've come in through. 
The QDCRDEVD API is able to tell you the IP address of the "local" network 
interface that they used.

If you're writing a program that communicates over a TCP/IP network, the 
getsockname() API can be used to find out the IP address of the interface 
that the system routed your request through.

If you're simplying trying to look this up for the purposes of printing it 
on a report or keeping track of it for auditing purposes or something like 
that, you'll want to keep track of ALL of the IP addresses on the system.

I wrote a demonstration program that lists all of the IP addresses on the 
system (though, you could modify it to only list a particular network 
interface if you wanted to) that you can download from the following link:

http://www.iseriesnetwork.com/noderesources/code/clubtechcode/DspIpIfc.zip




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.