boost asio iostream - 如何获取本地IP地址 [英] boost asio iostream - how to get local IP address

查看:615
本文介绍了boost asio iostream - 如何获取本地IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:
我正在使用boost :: asio :: ip :: tcp :: iostream连接到服务器:

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

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

现在我想检索自己的本地IP地址。我已经在谷歌的深处发现了如何使用 socket ,但是一个流呢?
我希望由于tcp :: iostream构建在套接字的顶部,它应该是这样的:
s.local_endpoint()。address()
但是经过长时间的谷歌搜索和duckduckgo我没有发现如何做到这一点。我尝试了几种最明显的排列,但仍然没有运气。
那么,有没有简单的方法,或者我必须使用套接字?
如果它很重要,它只需要在Linux上运行。

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.

推荐答案

假设Linux,请使用 getifaddrs(3) 获取本地系统的接口列表。

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

这篇关于boost asio iostream - 如何获取本地IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆