|
Hey Scott,
i'm guessing that the answer to this is "Of course not!"... But, is there any
way to retrieve/know the ip adress of a client workstation that is behind a
router which uses dhcp?
I have a situation where calling qdcrevd does not work to return the actual pc
ip address because the workstation is communicating with the iseries first
through a local router which has dhcp and its own firewall and then across the
internet to the iseries.
-----Original Message-----
From: "Scott Klement"<midrange-l@xxxxxxxxxxxxxxxx>
Sent: 9/1/05 12:06:43 PM
To: "Midrange Systems Technical Discussion"<midrange-l@xxxxxxxxxxxx>
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
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.