void socks_connection::on_request_domain_lookup(boost::system::error_code const& ec
		, asio::ip::tcp::resolver::iterator iter)
	{
		if (ec || iter == asio::ip::tcp::resolver::iterator())
		{
			if (ec)
			{
				printf("socks_connection::on_request_domain_lookup(%s): (%d) %s\n"
					, command(), ec.value(), ec.message().c_str());
			}
			else
			{
				printf("socks_connection::on_request_domain_lookup(%s): empty response\n"
					, command());
			}

// +----+-----+-------+------+----------+----------+
// |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |
// +----+-----+-------+------+----------+----------+
// | 1  |  1  | X'00' |  1   | Variable |    2     |
// +----+-----+-------+------+----------+----------+

			m_in_buffer[0] = m_version; // version
			m_in_buffer[1] = 4; // response (host unreachable)
			m_in_buffer[2] = 0; // reserved
			m_in_buffer[3] = 1; // IPv4
			memset(&m_in_buffer[4], 0, 4);
			m_in_buffer[8] = 0; // port
			m_in_buffer[9] = 0;

			auto self = shared_from_this();
			asio::async_write(m_client_connection
				, asio::const_buffers_1(&m_in_buffer[0], 10)
				, [=](boost::system::error_code const& ec, size_t)
				{
					self->close_connection();
				});
			return;
		}

		printf("socks_connection::on_request_domain_lookup(%s): connecting to: %s port: %d\n"
			, command()
			, iter->endpoint().address().to_string().c_str()
			, iter->endpoint().port());
		open_forward_connection(iter->endpoint());
	}
void AsyncSecureStream::_handleConnect(std::error_code ec, asio::ip::tcp::resolver::iterator iter) {
    _stream.async_handshake(decltype(_stream)::client,
                            [this, iter](std::error_code ec) {
                                if (ec) {
                                    return _userHandler(ec);
                                }
                                return _handleHandshake(ec, iter->host_name());
                            });
}
Exemple #3
0
	void http_proxy::on_domain_lookup(boost::system::error_code const& ec
		, const asio::ip::tcp::resolver::iterator& iter)
	{
		if (ec || iter == asio::ip::tcp::resolver::iterator())
		{
			if (ec)
			{
				std::printf("http_proxy::on_domain_lookup: (%d) %s\n"
					, ec.value(), ec.message().c_str());
			}
			else
			{
				std::printf("http_server::on_request_domain_lookup: empty response\n");
			}
			error(503, "Resource Temporarily Unavailable");
			return;
		}
		open_forward_connection(iter->endpoint());
	}