Many of my past hacks, involved systems that needed to know the TCP/IP address of a client workstation, and I’ve generally used one of two methods for doing so:
- a program on the client initiates a HTTP request to a PHP or CGI resource, which records the client’s IP address from an environment variable passed to the dynamic resource. (E.g. a CGI script accesses
$REMOTE_ADDR
.) What I typically use for doing this are cURL or preferably libcURL. - a program on the client connects with a socket to a process on a server, and the latter gets the client IP address from the
sockaddr *
passed it by the kernel.
This method is quite foolproof for single homed hosts – machines that have one network interface only.
Unfortunately, the system breaks, or at least gets very brittle, when you have client workstations with
- multiple network interfaces
- wireless LAN interfaces
- wireless 3G interfaces
In that case, my server process may be contacted by a legitimate workstation supplying the “wrong” IP address. You suddenly have a database entry for a client with IP address 192.168.40.20, but that client previously registered as, say, 192.168.1.39, and some time later the same workstation re-appears with the former address, or – even worse – with third IP address because its owner has just activated 3G.
This is a problem, when you require unique addresses, for example, when deploying Bacula clients.
As far as I know, there is no solution to this, apart from attempting to determine on the client whether it is using a wireless interface, and if so, avoid contacting the server.
Does anybody know of a foolproof method (in C) to check whether a wireless interface is being used, for Linux, Mac OS X, and (particularly) for Windows? I’d be very interested!