Boost logo

Boost Users :

Subject: Re: [Boost-users] how to know my own IP address
From: dhruva (dhruva_at_[hidden])
Date: 2009-08-14 22:39:25


Hello, > >> I'm using the boost library to create and manage a UDP socket. I > >> was wondering if there is a way to know the public address of my > >> machine using the boost classes. With this code > >> > >> udp::endpoint thisendpoint(udp::v4(), UDPPORT); > >> boost::asio::ip::address myaddress = thisendpoint.address(); > >> std::cout<< "__My IP address: " << myaddress.to_string() << > >> std::endl; > >> > >> I can only print the any_address (0.0.0.0)... thanks, > >> > >> p_viotti _______________________________________________ > > Tommy> You can always adress your own machine via the special > Tommy> ip adress 127.0.0.1 (or the special domain localhost) I have worked on this topic quite extensively. We had a requirement to find the global IP address of the local machine to be able to send ICMP6 packets. The packets needs to be signed by the senders IP address else machines on a network need not respond. The problem is a machine can have multiple NICs. So, you need a mechanism to iterate all available NICs and get the associated IP addresses. In this problem domain, MS Windows wins as they have nice APIs (GetAdaptersAddresses) to do that. Coming to GNU/Linux land, you need to parse the '/proc/net/if_inet6'. So, I ended up writing code that works on windows and gnu/linux. In short, there is no easy way to do it. Using name resolution is not an option as some machines might not have a DNS entry. It is not foolproof. -dhruva See the Web&#39;s breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net