Thread: How to get multiple local IP addresses without gethostbyname()

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    162

    Question How to get multiple local IP addresses without gethostbyname()

    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.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. resolving names and ip addresses
    By dicky in forum Networking/Device Communication
    Replies: 5
    Last Post: 07-01-2004, 03:32 PM
  4. Replies: 2
    Last Post: 10-16-2002, 08:32 PM