[英]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连接到服务器:
boost::asio::ip::tcp::iostream s(IP, "1237");
And now I want to retrieve my own, local IP address. 现在,我想检索自己的本地IP地址。 I have found somewhere in the depths of google how to do it with a socket , but what about a stream?
我在google的深处发现了如何使用套接字来实现 ,但是流又如何呢? 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.
我希望由于tcp :: iostream建立在套接字的顶部,因此应该类似于:s.local_endpoint()。address(),但是经过与google和duckduckgo的长时间搜索之后,我仍然不知道该怎么做。 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.
如果重要的话,它只能在Linux上运行。
假设使用Linux,请使用getifaddrs(3)
获取本地系统的接口列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.