logo       

Re: retrieving local ip address: msg#00024

lib.boost.asio.user

Subject: Re: retrieving local ip address


Themistoklis Bourdenas <themis-5/j9+EM7HEWSyL2BtYuC/A@xxxxxxxxxxxxxxxx> wrote:
> How do I you retrieve the IP Address of the local host using asio?
> boost::asio::ip::hostname() only returns the host's name but I want an
> ip address (not loopback 127.0.0.1).
>
> I also tried to get the local_endpoint() from a udp socket but by
> accessing endpoint's address() I get a "the specified class was not
> found" exception.

I should take a look at that. What platform are you running on?

Anyway, you can use the name returned by host_name() to do a lookup
using a resolver. E.g.:

tcp::resolver resolver(io_service);
tcp::resolver::query query(host_name(), "");
tcp::resolver::iterator iter = resolver.resolve(query);
...

Note: this is not the same as enumerating the network interfaces on
the host. Asio doesn't provide any classes for that.

Cheers,
Chris

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise