PDA

View Full Version : How to get multiple local IP addresses without gethostbyname()



Aidman
09-11-2004, 06:31 AM
Hi,

I am looking for a way to resolve all IP addresses on a local Unix/Linux system without using gethostbyname, since it has proven unable. For me, gethostbyname returns only one IP while ifconfig -a displays two. I have read that gethostbyname can be fixed through config files, but that is not a solution to me since I am not interested in altering a systemís configurations just to be able to run my program on it. However I have read about the function ioctl, which can be called with SIOCGIFADDR and return an IP. But the problem here is that I have to input interface names which can vary from system to system. So is it possible to enumerate all interface names and thereby resolve all IPs?

Any ideas are highly appreciated.

sean
09-11-2004, 08:52 AM
I am not interested in altering a systemís configurations just to be able to run my program on it.

A simple solution would be to read the configuration's file into memory when you open the program, and replace it with the data you need. Then when your program closes, you read the original data back into the file.