getting IP address

In my drvier I need to know my own IP address. gethostname()
returns the hostname, but gethostbyname() and similar routines get the
data from /etc/hosts which is empty.

Q: how do I find out what is the IP of the machine I am running on,
in my program(driver)?

Thanks

Berkeley Process Control <bpc@berkeleyprocess.com> wrote:

In my drvier I need to know my own IP address. gethostname()
returns the hostname, but gethostbyname() and similar routines get the
data from /etc/hosts which is empty.

Q: how do I find out what is the IP of the machine I am running on,
in my program(driver)?

If your driver a “network driver”? Ie, is it loaded into io-net?
If “yes”;

your driver will receive a “address up” message, whenever
somebody config the interface (for example ifconfig)

else

the term “ip of my machine” is not really valid, what if your
machine have more then one interface (en0 and ppp0 for example),
which one are you looking for ?

A program usually use “ioctl(SIOCGIFCONF)” to get information
of ALL interfaces (ip address) from stack, and get what they
want.

The “gethostbyname” is also valid, note it will also ask DNS
if you have one. The reason you got a NULL answer, menas you
didn’t set up your network properly (either no entry in /etc/host
no DNS, or DNS no response.


-xtang