Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost asio iostream - how to get local IP address

Here is my problem: I'm using boost::asio::ip::tcp::iostream to connect to server:

boost::asio::ip::tcp::iostream s(IP, "1237");

And now I want to retrieve my own, local IP address. I have found somewhere in the depths of google how to do it with a socket, but what about a stream? I expect that since tcp::iostream is built on the top of a socket it should be something like: s.local_endpoint().address() but after a long search with google and duckduckgo I have found no clue how to do it. I have tried several most obvious permutations, but still no luck. So, is there any simple way to do it, or do I have to use socket? It only has to work on Linux, if it is important.

like image 272
Darth Hunterix Avatar asked Jun 24 '12 18:06

Darth Hunterix


1 Answers

Assuming Linux, Use getifaddrs(3) to get a list of interfaces for the local system.

like image 83
Sam Miller Avatar answered Nov 15 '22 01:11

Sam Miller