Unix Programming - Identifying the owner of an IP address

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2004 > Identifying the owner of an IP address





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Identifying the owner of an IP address
Rennie deGraaf

2004-11-27, 5:51 pm

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

~From within a C program, what is the best way to determine if a
particular IP address belongs to the host the program is running on? The
host may be a router, so it can have an arbitrary number of interfaces
and IP addresses, and it might not use DNS. The program runs as root,
so I can use weird low-level kernel interfaces if necessary.

If possible, I need this to work on both Linux 2.4 and Linux 2.6, but
other systems aren't as important at the momment.

Rennie
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBqM1zIvU5mZP08HERAl7bAKDOA2wng0tu
886sXUokZuv5qP8WSQCaA5ri
8KpQHqFR9ESlDR/f5bEmGEk=
=sA3W
-----END PGP SIGNATURE-----
David Schwartz

2004-11-27, 5:51 pm


"Rennie deGraaf" <ca.ucalgary.cpsc@degraaf> wrote in message
news:U34qd.368832$%k.8340@pd7tw2no...

> ~From within a C program, what is the best way to determine if a
> particular IP address belongs to the host the program is running on? The
> host may be a router, so it can have an arbitrary number of interfaces
> and IP addresses, and it might not use DNS. The program runs as root,
> so I can use weird low-level kernel interfaces if necessary.


Try to bind to it. If you can, it belongs to the host. There is an
exception of some Linux machines that are specifically configured to allow
you to bind to any IP, but this is only used in cases where any IP might
potentially belong to the host.

DS


Pascal Bourguignon

2004-11-27, 5:51 pm

"David Schwartz" <davids@webmaster.com> writes:

> "Rennie deGraaf" <ca.ucalgary.cpsc@degraaf> wrote in message
> news:U34qd.368832$%k.8340@pd7tw2no...
>
>
> Try to bind to it. If you can, it belongs to the host. There is an
> exception of some Linux machines that are specifically configured to allow
> you to bind to any IP, but this is only used in cases where any IP might
> potentially belong to the host.


Another clue would be given by the sources of ifconfig.

On the other hand popen("ifconfig","r") is not too complicated either,
and would be more portable than anything else I bet.

--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
Christopher Nehren

2004-11-27, 8:48 pm

On 2004-11-27, Pascal Bourguignon scribbled these
curious markings:
> On the other hand popen("ifconfig","r") is not too complicated either,
> and would be more portable than anything else I bet.


And it breaks as soon as you leave Stalin^H^Hmanland.

--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
Linux: "How rebellious ... in a conformist sort of way."
Unix is user friendly. However, it isn't idiot friendly.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com