Hey, C! What's my IP?
byron at theclarkfamily.name
Tue Jan 16 21:51:12 MST 2007
On Tue, Jan 16, 2007 at 09:22:36PM -0700, Topher Fischer wrote:
> Is there a "standard" (de facto or otherwise) way of finding a local
> machine's IP address in C? I've googled about, but I still haven't
> found what I'm looking for. The only thing I've come up with so far is
> calling gethostbyname on my machine's hostname, but that obviously won't
> work when I leave my home network.
One way to do it would be to use the SIOCGIFCONF ioctl on a socket.
That should give you back all the interfaces and at least their IP
address. This works for sure on linux, not so sure about other flavors
of *nix. If you care about those you'll probably want to
strace/truss/ktrace ifconfig to see how it gets the information.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://plug.org/pipermail/plug/attachments/20070116/6a53e9d2/attachment.bin
More information about the PLUG