Chris@16: // Chris@16: // ip/basic_resolver_query.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_IP_BASIC_RESOLVER_QUERY_HPP Chris@16: #define BOOST_ASIO_IP_BASIC_RESOLVER_QUERY_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace ip { Chris@16: Chris@16: /// An query to be passed to a resolver. Chris@16: /** Chris@16: * The boost::asio::ip::basic_resolver_query class template describes a query Chris@16: * that can be passed to a resolver. Chris@16: * Chris@16: * @par Thread Safety Chris@16: * @e Distinct @e objects: Safe.@n Chris@16: * @e Shared @e objects: Unsafe. Chris@16: */ Chris@16: template Chris@16: class basic_resolver_query Chris@16: : public resolver_query_base Chris@16: { Chris@16: public: Chris@16: /// The protocol type associated with the endpoint query. Chris@16: typedef InternetProtocol protocol_type; Chris@16: Chris@16: /// Construct with specified service name for any protocol. Chris@16: /** Chris@16: * This constructor is typically used to perform name resolution for local Chris@16: * service binding. Chris@16: * Chris@16: * @param service A string identifying the requested service. This may be a Chris@16: * descriptive name or a numeric string corresponding to a port number. Chris@16: * Chris@16: * @param resolve_flags A set of flags that determine how name resolution Chris@16: * should be performed. The default flags are suitable for local service Chris@16: * binding. Chris@16: * Chris@16: * @note On POSIX systems, service names are typically defined in the file Chris@16: * /etc/services. On Windows, service names may be found in the file Chris@16: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems Chris@16: * may use additional locations when resolving service names. Chris@16: */ Chris@16: basic_resolver_query(const std::string& service, Chris@16: resolver_query_base::flags resolve_flags = passive | address_configured) Chris@16: : hints_(), Chris@16: host_name_(), Chris@16: service_name_(service) Chris@16: { Chris@16: typename InternetProtocol::endpoint endpoint; Chris@16: hints_.ai_flags = static_cast(resolve_flags); Chris@16: hints_.ai_family = PF_UNSPEC; Chris@16: hints_.ai_socktype = endpoint.protocol().type(); Chris@16: hints_.ai_protocol = endpoint.protocol().protocol(); Chris@16: hints_.ai_addrlen = 0; Chris@16: hints_.ai_canonname = 0; Chris@16: hints_.ai_addr = 0; Chris@16: hints_.ai_next = 0; Chris@16: } Chris@16: Chris@16: /// Construct with specified service name for a given protocol. Chris@16: /** Chris@16: * This constructor is typically used to perform name resolution for local Chris@16: * service binding with a specific protocol version. Chris@16: * Chris@16: * @param protocol A protocol object, normally representing either the IPv4 or Chris@16: * IPv6 version of an internet protocol. Chris@16: * Chris@16: * @param service A string identifying the requested service. This may be a Chris@16: * descriptive name or a numeric string corresponding to a port number. Chris@16: * Chris@16: * @param resolve_flags A set of flags that determine how name resolution Chris@16: * should be performed. The default flags are suitable for local service Chris@16: * binding. Chris@16: * Chris@16: * @note On POSIX systems, service names are typically defined in the file Chris@16: * /etc/services. On Windows, service names may be found in the file Chris@16: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems Chris@16: * may use additional locations when resolving service names. Chris@16: */ Chris@16: basic_resolver_query(const protocol_type& protocol, Chris@16: const std::string& service, Chris@16: resolver_query_base::flags resolve_flags = passive | address_configured) Chris@16: : hints_(), Chris@16: host_name_(), Chris@16: service_name_(service) Chris@16: { Chris@16: hints_.ai_flags = static_cast(resolve_flags); Chris@16: hints_.ai_family = protocol.family(); Chris@16: hints_.ai_socktype = protocol.type(); Chris@16: hints_.ai_protocol = protocol.protocol(); Chris@16: hints_.ai_addrlen = 0; Chris@16: hints_.ai_canonname = 0; Chris@16: hints_.ai_addr = 0; Chris@16: hints_.ai_next = 0; Chris@16: } Chris@16: Chris@16: /// Construct with specified host name and service name for any protocol. Chris@16: /** Chris@16: * This constructor is typically used to perform name resolution for Chris@16: * communication with remote hosts. Chris@16: * Chris@16: * @param host A string identifying a location. May be a descriptive name or Chris@16: * a numeric address string. If an empty string and the passive flag has been Chris@16: * specified, the resolved endpoints are suitable for local service binding. Chris@16: * If an empty string and passive is not specified, the resolved endpoints Chris@16: * will use the loopback address. Chris@16: * Chris@16: * @param service A string identifying the requested service. This may be a Chris@16: * descriptive name or a numeric string corresponding to a port number. May Chris@16: * be an empty string, in which case all resolved endpoints will have a port Chris@16: * number of 0. Chris@16: * Chris@16: * @param resolve_flags A set of flags that determine how name resolution Chris@16: * should be performed. The default flags are suitable for communication with Chris@16: * remote hosts. Chris@16: * Chris@16: * @note On POSIX systems, host names may be locally defined in the file Chris@16: * /etc/hosts. On Windows, host names may be defined in the file Chris@16: * c:\\windows\\system32\\drivers\\etc\\hosts. Remote host name Chris@16: * resolution is performed using DNS. Operating systems may use additional Chris@16: * locations when resolving host names (such as NETBIOS names on Windows). Chris@16: * Chris@16: * On POSIX systems, service names are typically defined in the file Chris@16: * /etc/services. On Windows, service names may be found in the file Chris@16: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems Chris@16: * may use additional locations when resolving service names. Chris@16: */ Chris@16: basic_resolver_query(const std::string& host, const std::string& service, Chris@16: resolver_query_base::flags resolve_flags = address_configured) Chris@16: : hints_(), Chris@16: host_name_(host), Chris@16: service_name_(service) Chris@16: { Chris@16: typename InternetProtocol::endpoint endpoint; Chris@16: hints_.ai_flags = static_cast(resolve_flags); Chris@16: hints_.ai_family = BOOST_ASIO_OS_DEF(AF_UNSPEC); Chris@16: hints_.ai_socktype = endpoint.protocol().type(); Chris@16: hints_.ai_protocol = endpoint.protocol().protocol(); Chris@16: hints_.ai_addrlen = 0; Chris@16: hints_.ai_canonname = 0; Chris@16: hints_.ai_addr = 0; Chris@16: hints_.ai_next = 0; Chris@16: } Chris@16: Chris@16: /// Construct with specified host name and service name for a given protocol. Chris@16: /** Chris@16: * This constructor is typically used to perform name resolution for Chris@16: * communication with remote hosts. Chris@16: * Chris@16: * @param protocol A protocol object, normally representing either the IPv4 or Chris@16: * IPv6 version of an internet protocol. Chris@16: * Chris@16: * @param host A string identifying a location. May be a descriptive name or Chris@16: * a numeric address string. If an empty string and the passive flag has been Chris@16: * specified, the resolved endpoints are suitable for local service binding. Chris@16: * If an empty string and passive is not specified, the resolved endpoints Chris@16: * will use the loopback address. Chris@16: * Chris@16: * @param service A string identifying the requested service. This may be a Chris@16: * descriptive name or a numeric string corresponding to a port number. May Chris@16: * be an empty string, in which case all resolved endpoints will have a port Chris@16: * number of 0. Chris@16: * Chris@16: * @param resolve_flags A set of flags that determine how name resolution Chris@16: * should be performed. The default flags are suitable for communication with Chris@16: * remote hosts. Chris@16: * Chris@16: * @note On POSIX systems, host names may be locally defined in the file Chris@16: * /etc/hosts. On Windows, host names may be defined in the file Chris@16: * c:\\windows\\system32\\drivers\\etc\\hosts. Remote host name Chris@16: * resolution is performed using DNS. Operating systems may use additional Chris@16: * locations when resolving host names (such as NETBIOS names on Windows). Chris@16: * Chris@16: * On POSIX systems, service names are typically defined in the file Chris@16: * /etc/services. On Windows, service names may be found in the file Chris@16: * c:\\windows\\system32\\drivers\\etc\\services. Operating systems Chris@16: * may use additional locations when resolving service names. Chris@16: */ Chris@16: basic_resolver_query(const protocol_type& protocol, Chris@16: const std::string& host, const std::string& service, Chris@16: resolver_query_base::flags resolve_flags = address_configured) Chris@16: : hints_(), Chris@16: host_name_(host), Chris@16: service_name_(service) Chris@16: { Chris@16: hints_.ai_flags = static_cast(resolve_flags); Chris@16: hints_.ai_family = protocol.family(); Chris@16: hints_.ai_socktype = protocol.type(); Chris@16: hints_.ai_protocol = protocol.protocol(); Chris@16: hints_.ai_addrlen = 0; Chris@16: hints_.ai_canonname = 0; Chris@16: hints_.ai_addr = 0; Chris@16: hints_.ai_next = 0; Chris@16: } Chris@16: Chris@16: /// Get the hints associated with the query. Chris@16: const boost::asio::detail::addrinfo_type& hints() const Chris@16: { Chris@16: return hints_; Chris@16: } Chris@16: Chris@16: /// Get the host name associated with the query. Chris@16: std::string host_name() const Chris@16: { Chris@16: return host_name_; Chris@16: } Chris@16: Chris@16: /// Get the service name associated with the query. Chris@16: std::string service_name() const Chris@16: { Chris@16: return service_name_; Chris@16: } Chris@16: Chris@16: private: Chris@16: boost::asio::detail::addrinfo_type hints_; Chris@16: std::string host_name_; Chris@16: std::string service_name_; Chris@16: }; Chris@16: Chris@16: } // namespace ip Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_IP_BASIC_RESOLVER_QUERY_HPP