How does Boost Asio's hostname resolution work on Linux? Is it possible to use NSS?

后端 未结 2 788
盖世英雄少女心
盖世英雄少女心 2021-02-15 17:46

I\'m attempting to make my networked application work locally (with both the server and client running on the same computer) when there is no network connection. This seems to

相关标签:
2条回答
  • 2021-02-15 18:14

    The problem was that the constructor for query has the address_configured flag set by default which won't return an address if the loopback device is the only device with an address. By just settings flags to 0 or anything other than address_configured the problem is fixed. Here is what I'm successfully using now:

    tcp::resolver::query query(host, PORT, boost::asio::ip::resolver_query_base::numeric_service);
    

    Hope this helps anyone with this problem in the future.

    0 讨论(0)
  • 2021-02-15 18:28

    The constructor for query defaults to having the flag "address_configured".

    ip::basic_resolver_query::address_configured

    Only return IPv4 addresses if a non-loopback IPv4 address is configured for the system. Only return IPv6 addresses if a non-loopback IPv6 address is configured for the system.

    While setting the flag to something else will work, it will also have the side effects of said flag. To avoid this use the "default" of the enum.

    tcp::resolver::query query(host, PORT, boost::asio::ip::resolver_query_base::flags());
    

    It used to be possible to just use 0, but the library has become more strict to prevent accidental use of an int as the service name.

    0 讨论(0)
提交回复
热议问题