6
votes

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.

1
You seem to have the misconception that hosts have only one IP address.Juliano
The question is still valid: how can I retrieve all the IP addresses of the local host?Daniele Pallastrelli

1 Answers

1
votes

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