boost asio iostream - how to get local IP address

◇◆丶佛笑我妖孽 提交于 2019-12-19 18:33:04

问题


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:


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



来源:https://stackoverflow.com/questions/11180187/boost-asio-iostream-how-to-get-local-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!