/// Create an iterator from an addrinfo list returned by getaddrinfo.
  static basic_resolver_iterator create(
      asio::detail::addrinfo_type* address_info,
      const std::string& host_name, const std::string& service_name)
  {
    basic_resolver_iterator iter;
    if (!address_info)
      return iter;

    std::string actual_host_name = host_name;
    if (address_info->ai_canonname)
      actual_host_name = address_info->ai_canonname;

    iter.values_.reset(new values_type);

    while (address_info)
    {
      if (address_info->ai_family == ASIO_OS_DEF(AF_INET)
          || address_info->ai_family == ASIO_OS_DEF(AF_INET6))
      {
        using namespace std; // For memcpy.
        typename InternetProtocol::endpoint endpoint;
        endpoint.resize(static_cast<std::size_t>(address_info->ai_addrlen));
        memcpy(endpoint.data(), address_info->ai_addr,
            address_info->ai_addrlen);
        iter.values_->push_back(
            basic_resolver_entry<InternetProtocol>(endpoint,
              actual_host_name, service_name));
      }
      address_info = address_info->ai_next;
    }

    return iter;
  }
Ejemplo n.º 2
0
 /**
  * This constructor is typically used to perform name resolution for local
  * service binding.
  *
  * @param service_name A string identifying the requested service. This may
  * be a descriptive name or a numeric string corresponding to a port number.
  *
  * @param resolve_flags A set of flags that determine how name resolution
  * should be performed. The default flags are suitable for local service
  * binding.
  *
  * @note On POSIX systems, service names are typically defined in the file
  * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  * may use additional locations when resolving service names.
  */
 basic_resolver_query(const std::string& service_name,
     resolver_query_base::flags resolve_flags = passive | address_configured)
   : hints_(),
     host_name_(),
     service_name_(service_name)
 {
   typename InternetProtocol::endpoint endpoint;
   hints_.ai_flags = static_cast<int>(resolve_flags);
   hints_.ai_family = PF_UNSPEC;
   hints_.ai_socktype = endpoint.protocol().type();
   hints_.ai_protocol = endpoint.protocol().protocol();
   hints_.ai_addrlen = 0;
   hints_.ai_canonname = 0;
   hints_.ai_addr = 0;
   hints_.ai_next = 0;
 }
 /// Construct with specified host name and service name for any protocol.
 basic_resolver_query(const std::string& host_name,
     const std::string& service_name, int flags = address_configured)
   : hints_(),
     host_name_(host_name),
     service_name_(service_name)
 {
   typename InternetProtocol::endpoint endpoint;
   hints_.ai_flags = flags;
   hints_.ai_family = PF_UNSPEC;
   hints_.ai_socktype = endpoint.protocol().type();
   hints_.ai_protocol = endpoint.protocol().protocol();
   hints_.ai_addrlen = 0;
   hints_.ai_canonname = 0;
   hints_.ai_addr = 0;
   hints_.ai_next = 0;
 }