Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, September 2004
Finding my own list of IP addresses...


Message 1 in thread

How can I find a list of my own IP addresses, something like a
QValueList<QHostAddress>? This would be the Qt equivalent of ipconfig
under Windows and ifconfig under Linux (and perhaps Mac?)

Basicly, I need to sign the address with a digital signature, so I
can't really do it with pseudovalues. I'm working on a solution for
NAT (slightly complicated because I can't trust a single reply telling
me what my IP address is, I'd have to do a majority vote), but it
would considerably easier if I could get a list like:

127.0.0.1 (loopback)
192.168.0.x (local interface)
a.b.c.d (public IP)

That should cover most cases, I know there are some more exotic
configurations that might be difficult but right now I'm looking to
fix this for typical connections.

Yours truly,
Kjell Rune Skaaraas


Message 2 in thread

Hi,

> How can I find a list of my own IP addresses, something like a
> QValueList<QHostAddress>? This would be the Qt equivalent of ipconfig
> under Windows and ifconfig under Linux (and perhaps Mac?)

This has already been discussed here, see for example:
http://lists.trolltech.com/qt-interest/2003-07/thread00623-0.html
http://lists.trolltech.com/qt-interest/2003-05/thread00327-0.html

--
 [ signature omitted ] 

Message 3 in thread

Yes, I looked at those posts. Pardon me if I seem a little slow, but I
don't see why there can't be a Qt equivalent of ifconfig/ipconfig, and
was hoping this would have been fixed. To do system-dependent system
calls and parse the text output seems like an awfully round-about way
of doing things. Guess I'll just have to do the "heavy" version for
all IPs (i.e. connect out, and ask them to tell me "who" I am). The
potential for exploits seems a lot higher this way, as what I am
trying to avoid is that a machine announces itself as "contact me on
IP a.b.c.d" on the network (long story, virtual network) while not
owning it. I will have to deal with fake entries in some way anyway
due to asshats, but it'd be a lot easier if I didn't have to deal with
poison nodes giving real nodes fake IP information as well...

Kjell Rune Skaaraas

On Thu, 16 Sep 2004 19:30:05 +0200, Dimitri <dimitri@trolltech.com>
wrote:

>Hi,
>
>> How can I find a list of my own IP addresses, something like a
>> QValueList<QHostAddress>? This would be the Qt equivalent of ipconfig
>> under Windows and ifconfig under Linux (and perhaps Mac?)
>
>This has already been discussed here, see for example:
>http://lists.trolltech.com/qt-interest/2003-07/thread00623-0.html
>http://lists.trolltech.com/qt-interest/2003-05/thread00327-0.html


Message 4 in thread

On Friday 17 September 2004 8:55 am, Kjell Rune Skaaraas wrote:
> Yes, I looked at those posts. Pardon me if I seem a little slow, but I
> don't see why there can't be a Qt equivalent of ifconfig/ipconfig, and
> was hoping this would have been fixed. 

It would be MASSIVELY unportable, and few people have any demand for it.  It 
doesn't make sense for Trolltech to spend their time writing it. 

> To do system-dependent system 
> calls and parse the text output seems like an awfully round-about way
> of doing things. 

Considering how much work it is to do it through other API's, it's actually 
quite a bit more straight forward to parse the output of a standard program, 
especially since the ioctl()'s involved aren't documented very well 
sometimes.

> Guess I'll just have to do the "heavy" version for 
> all IPs (i.e. connect out, and ask them to tell me "who" I am). The
> potential for exploits seems a lot higher this way, as what I am
> trying to avoid is that a machine announces itself as "contact me on
> IP a.b.c.d" on the network (long story, virtual network) while not
> owning it. I will have to deal with fake entries in some way anyway
> due to asshats, but it'd be a lot easier if I didn't have to deal with
> poison nodes giving real nodes fake IP information as well...

You don't want to use IP addresses for any type of copy protection scheme.  
First, most people today are sitting on a private IP address behind a NAT box 
of some sort with a DHCP server.  My IP address is currently 192.168.0.145.  
Anyone else have this IP address right now?  Second, when I come into work 
next week, I might have a different IP address.  Third, I use a laptop most 
of the time.  My network at home is on a different (private) subnet.  Using 
IP address, you'd think my laptop was a different at home versus at work, or 
when the DHCP server gave me a different address.  

Where I work, we use two class C private subnets, which after all going 
through a NAT box all have look like the same public IP address.  If you try 
to connect out to find a machines public IP address, all 100 or so machines 
up here would show up as the same machine.  Furthermore, our T1's sometimes 
flake out during storms.  We'd quickly replace your software if we couldn't 
use it when our Internet connectivity was down.  Also, I've written some 
software that was used on computers that for security reasons couldn't be 
connected to the Internet.

No, using IP address won't work for copy control, and will just generally 
annoy everyone.  A much better scheme is to use a computer's network MAC 
address.  It still has some problems, like MAC addresses can be cloned, or a 
computer may not have a network card.  However, almost all computers have 
network cards today, even if they're not a network.  Also, most people aren't 
going to clone a MAC address to try to pirate your software.  In fact, if 
they try to do that for computers on the same LAN, they're network suddenly 
won't work right!

I actually have code to find the MAC address on most operating systems 
supported by Qt.  It's at home, right now, though.  I'll try to find it this 
weekend.  On Windows, Solaris, Linux, and MacOS X, it actually uses ioctl()'s 
to programatically enumerate the Ethernet adapters and their MAC addresses.  
On Irix and Tru64, it parses the output of ifconfig.

---
Geoffrey Wossum
Long Range Systems - http://www.pager.net
 


Message 5 in thread

Kjell

For Linux only, do something like:

#ifdef LINUX_OS


QFile arpFile("/proc/net/arp");
if (arpFile.exists() == FALSE) {
QMessageBox::warning(this,"Network Error",
"/proc/net/arp file is missing");

return(-1);
}
bstatus = arpFile.open(IO_ReadOnly);
if (bstatus == FALSE) {
QMessageBox::warning(this,"Network Error",
"Unable to open network file.");
return(-2);
}
QTextStream t(&arpFile);
while(!t.eof()) {
line = t.readLine();
numLines++;
}
}
#endif

Each line will contain an IP address.
The only bummer here is that the file /proc/net/arp may change with 
future releases of Linux, but then again do a procedure call such as 
ifconfig may change as well.

There are routines for reading the arp files but they are pretty 
complicated I think.

Not sure what arp stands for


Hope this helps




-- 
 [ signature omitted ] 

Message 6 in thread

On September 16, 2004 02:49 pm, David Boosalis wrote:
> Kjell
>
> For Linux only, do something like:
>
> #ifdef LINUX_OS
>
>
> QFile arpFile("/proc/net/arp");
> if (arpFile.exists() == FALSE) {
> QMessageBox::warning(this,"Network Error",
> "/proc/net/arp file is missing");
>
> return(-1);
> }
> bstatus = arpFile.open(IO_ReadOnly);
> if (bstatus == FALSE) {
> QMessageBox::warning(this,"Network Error",
> "Unable to open network file.");
> return(-2);
> }
> QTextStream t(&arpFile);
> while(!t.eof()) {
> line = t.readLine();
> numLines++;
> }
> }
> #endif

(I'm not the one looking for code)

Note that on the three machines I tested (Mandrake 10.0 on two, Gentoo on the 
other), all files contained other machines' IP addresses rather than my own.  
Furthermore, they did not generally contain a complete list of IP addresses 
on my LAN, just a subset.

So it appears that /proc/net/arp isn't particularly useful for very much.  I 
suggest looking at the source code to ifconfig for code on Linux that will 
determine your IP address(es).

-- 
 [ signature omitted ] 

Message 7 in thread

On Thursday 16 September 2004 3:49 pm, David Boosalis wrote:

> Each line will contain an IP address.
> The only bummer here is that the file /proc/net/arp may change with
> future releases of Linux, but then again do a procedure call such as
> ifconfig may change as well.
>
> There are routines for reading the arp files but they are pretty
> complicated I think.
>
> Not sure what arp stands for

Address Resolution Protocol, used to resolve IP addresses to their underlying 
MAC addresses on an 802.x LAN.  /proc/net/arp is the contents of your ARP 
cache (your machine caches ARP responses to avoid doing doing an ARP request 
every time it wants to talk to another machine).  Your ARP cache will only 
very rarely have your own IP address in it, plus it will have every machine 
on the LAN your machine has recently talked to.  This will not work at all 
for determining your own IP address.

---
Geoffrey Wossum
Long Range Systems - http://www.pager.net


Message 8 in thread

This function gets my host name, and then does a lookup on that name.  It 
was written to allow generation of a bitmap for the desktop which contains 
the IP address(es).

This was written for Windows (I've no need to write cross platform) but 
these are just socket calls - I've no reason to suspect this code isn't 
portable with a bit of minor tweeking.

Dave



QString desktopBmpDialog::getAddress( void )
{
 QString address;

 QSocket s;  // this is here solely to wake up windows sockets

 QHostAddress a;
 char buf[ 256 ];
 // get my host name
 if( !gethostname( buf, sizeof( buf )))
 {
  struct hostent FAR* h = gethostbyname( buf );

  int x = 0;
  DWORD addr=0;

  // run through the list of returned addreses
  if( h )
  {
   while( h->h_addr_list[ x ] )
   {
    if( htonl( *(DWORD*)h->h_addr_list[ x ]) > addr )
     addr = htonl( *(DWORD*)h->h_addr_list[ x ]);

    // convert address to string
    a.setAddress( htonl( *(DWORD*)h->h_addr_list[ x ]));

    if( x )
     address += " / ";
    address += a.toString();
    x++;
   }
  }
 }
 return address;
}



"Kjell Rune Skaaraas" <nospam@no.mail> wrote in message 
odmik0h6o2q7hkpci3slrg461bld8ogqfv@4ax.com">news:odmik0h6o2q7hkpci3slrg461bld8ogqfv@4ax.com...
> How can I find a list of my own IP addresses, something like a
> QValueList<QHostAddress>? This would be the Qt equivalent of ipconfig
> under Windows and ifconfig under Linux (and perhaps Mac?)
>
> Basicly, I need to sign the address with a digital signature, so I
> can't really do it with pseudovalues. I'm working on a solution for
> NAT (slightly complicated because I can't trust a single reply telling
> me what my IP address is, I'd have to do a majority vote), but it
> would considerably easier if I could get a list like:
>
> 127.0.0.1 (loopback)
> 192.168.0.x (local interface)
> a.b.c.d (public IP)
>
> That should cover most cases, I know there are some more exotic
> configurations that might be difficult but right now I'm looking to
> fix this for typical connections.
>
> Yours truly,
> Kjell Rune Skaaraas 


Message 9 in thread

Kjell,

I have my own code for finding the Network Interfaces on a box.
Unfortunately, I only have the code for Irix & Solaris.  It's not too hard
to get it for Linux, though.  I have no idea how to do it for Windows.  I
would be willing to give you the code, if you are interested.  The basic
structure of the code was taken from W. Richard Stevens book "UNIX Network
Programming:  Networking APIs:  Sockets & XTI:  Volume 1, Second Edition",
chapters 16 & 17, if you wish to do the programming yourself.

Darin Broady
dbroady@lexmark.com
Lexmark International, Inc.


|---------+------------------------------->
|         |           Kjell Rune Skaaraas |
|         |           <nospam@no.mail>    |
|         |           Sent by:            |
|         |           owner-qt-interest@tr|
|         |           olltech.com         |
|         |                               |
|         |                               |
|         |           09/16/2004 05:26 AM |
|         |           Please respond to   |
|         |           nospam              |
|         |                               |
|---------+------------------------------->
  >--------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                    |
  |       To:       qt-interest@trolltech.com                                                                          |
  |       cc:                                                                                                          |
  |       Subject:  Finding my own list of IP addresses...                                                             |
  >--------------------------------------------------------------------------------------------------------------------|




How can I find a list of my own IP addresses, something like a
QValueList<QHostAddress>? This would be the Qt equivalent of ipconfig
under Windows and ifconfig under Linux (and perhaps Mac?)

Basicly, I need to sign the address with a digital signature, so I
can't really do it with pseudovalues. I'm working on a solution for
NAT (slightly complicated because I can't trust a single reply telling
me what my IP address is, I'd have to do a majority vote), but it
would considerably easier if I could get a list like:

127.0.0.1 (loopback)
192.168.0.x (local interface)
a.b.c.d (public IP)

That should cover most cases, I know there are some more exotic
configurations that might be difficult but right now I'm looking to
fix this for typical connections.

Yours truly,
Kjell Rune Skaaraas

--
 [ signature omitted ]