We all know that if we type in ipconfig on a DOS box, we can take a look at the bound IP addresses, right? But how do we do something similar in an application?
If you've tried using gethostbyname, you'll be disappointed. Because that returns 127.0.0.1; largely due to the fact that you've probably supplied "localhost' as the host name. This is valid, and the value returned is logical, just useless.
We have the solution, though, and it is really very simple. Before I point you in the right direction, just take a moment to peruse it's usefulness.
The reason I was looking for this is because I'm working on a little Windows application that will anchor itself to the top-right corner of the screen, has no client area, and resembles a floating title bar. In the title bar is ... the local IP address of the machine, periodically updated, and very useful when you're troubleshooting the local network, or VPN.
If you want a copy of this wonderful little tool, then all you have to do is email me - computerprogramming@suite101.com - and I'll get one out to you right away. Meanwhile, learn with me as we look at the wonderful world of socket programming, and localhost.
The actual article link : Socket Programming gethostbyname.
Happy (network) coding!
Guy.