Boost asio:在resolver::query中使用IPv6地址适用于Win32,但不适用于Linux
我目前正在开发一个简单的服务器应用程序,它也应该支持 IPv6。 IPv6 在 Windows 上运行良好(使用 MSVC2010),但在 Linux 上则不然。
想象一下下面的代码:
boost::system::error_code ec;
std::string address="::1", service="http";
tcp::resolver resolver(io_service);
tcp::resolver::query query(address, service);
tcp::resolver::iterator resiter = resolver.resolve(query, ec);
if (ec)
std::cout << "Cannot resolve address: " << address << "(" << ec.message() << ")" << std::endl;
在 Linux 上打印的错误消息是“找不到主机(权威)”,而在 Windows 上却可以。
欢迎任何提示。
I am currently developing a simple server application which should be also IPv6 capable. IPv6 works fine on Windows (using MSVC2010), but it does not on Linux.
Imagine following code:
boost::system::error_code ec;
std::string address="::1", service="http";
tcp::resolver resolver(io_service);
tcp::resolver::query query(address, service);
tcp::resolver::iterator resiter = resolver.resolve(query, ec);
if (ec)
std::cout << "Cannot resolve address: " << address << "(" << ec.message() << ")" << std::endl;
The error message printed on Linux is "Host not found (authoritative)", while it works on Windows.
Any hints are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于名称服务返回的地址搜索顺序,Linux 和 Windows 具有不同的行为。尝试使用不同的标志来对您正在查询的地址类型进行更细粒度的控制。例如,对于此查询,您可以使用 numeric_host 标志。
Linux and Windows have different behavior with respect to the search order of address returned by the name services. Try using different flags to gain more fine-grained control over the type of address you are querying for. For example, for this query you could use the numeric_host flag.