update boost on linux

This commit is contained in:
Bassem Girgis
2019-08-10 16:06:25 -05:00
parent 76ad52be58
commit 861b918727
5363 changed files with 483306 additions and 116507 deletions

View File

@@ -2,7 +2,7 @@
// ip/address.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,9 +17,13 @@
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/detail/string_view.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/ip/address_v4.hpp>
#include <boost/asio/ip/address_v6.hpp>
#include <boost/asio/ip/bad_address_cast.hpp>
#if !defined(BOOST_ASIO_NO_IOSTREAM)
# include <iosfwd>
@@ -44,46 +48,48 @@ class address
{
public:
/// Default constructor.
BOOST_ASIO_DECL address();
BOOST_ASIO_DECL address() BOOST_ASIO_NOEXCEPT;
/// Construct an address from an IPv4 address.
BOOST_ASIO_DECL address(const boost::asio::ip::address_v4& ipv4_address);
BOOST_ASIO_DECL address(
const boost::asio::ip::address_v4& ipv4_address) BOOST_ASIO_NOEXCEPT;
/// Construct an address from an IPv6 address.
BOOST_ASIO_DECL address(const boost::asio::ip::address_v6& ipv6_address);
BOOST_ASIO_DECL address(
const boost::asio::ip::address_v6& ipv6_address) BOOST_ASIO_NOEXCEPT;
/// Copy constructor.
BOOST_ASIO_DECL address(const address& other);
BOOST_ASIO_DECL address(const address& other) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
BOOST_ASIO_DECL address(address&& other);
BOOST_ASIO_DECL address(address&& other) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assign from another address.
BOOST_ASIO_DECL address& operator=(const address& other);
BOOST_ASIO_DECL address& operator=(const address& other) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move-assign from another address.
BOOST_ASIO_DECL address& operator=(address&& other);
BOOST_ASIO_DECL address& operator=(address&& other) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assign from an IPv4 address.
BOOST_ASIO_DECL address& operator=(
const boost::asio::ip::address_v4& ipv4_address);
const boost::asio::ip::address_v4& ipv4_address) BOOST_ASIO_NOEXCEPT;
/// Assign from an IPv6 address.
BOOST_ASIO_DECL address& operator=(
const boost::asio::ip::address_v6& ipv6_address);
const boost::asio::ip::address_v6& ipv6_address) BOOST_ASIO_NOEXCEPT;
/// Get whether the address is an IP version 4 address.
bool is_v4() const
bool is_v4() const BOOST_ASIO_NOEXCEPT
{
return type_ == ipv4;
}
/// Get whether the address is an IP version 6 address.
bool is_v6() const
bool is_v6() const BOOST_ASIO_NOEXCEPT
{
return type_ == ipv6;
}
@@ -94,65 +100,76 @@ public:
/// Get the address as an IP version 6 address.
BOOST_ASIO_DECL boost::asio::ip::address_v6 to_v6() const;
/// Get the address as a string in dotted decimal format.
/// Get the address as a string.
BOOST_ASIO_DECL std::string to_string() const;
/// Get the address as a string in dotted decimal format.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use other overload.) Get the address as a string.
BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
BOOST_ASIO_DECL static address from_string(const char* str);
/// (Deprecated: Use make_address().) Create an address from an IPv4 address
/// string in dotted decimal form, or from an IPv6 address in hexadecimal
/// notation.
static address from_string(const char* str);
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
BOOST_ASIO_DECL static address from_string(
const char* str, boost::system::error_code& ec);
/// (Deprecated: Use make_address().) Create an address from an IPv4 address
/// string in dotted decimal form, or from an IPv6 address in hexadecimal
/// notation.
static address from_string(const char* str, boost::system::error_code& ec);
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
BOOST_ASIO_DECL static address from_string(const std::string& str);
/// (Deprecated: Use make_address().) Create an address from an IPv4 address
/// string in dotted decimal form, or from an IPv6 address in hexadecimal
/// notation.
static address from_string(const std::string& str);
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
BOOST_ASIO_DECL static address from_string(
/// (Deprecated: Use make_address().) Create an address from an IPv4 address
/// string in dotted decimal form, or from an IPv6 address in hexadecimal
/// notation.
static address from_string(
const std::string& str, boost::system::error_code& ec);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a loopback address.
BOOST_ASIO_DECL bool is_loopback() const;
BOOST_ASIO_DECL bool is_loopback() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is unspecified.
BOOST_ASIO_DECL bool is_unspecified() const;
BOOST_ASIO_DECL bool is_unspecified() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a multicast address.
BOOST_ASIO_DECL bool is_multicast() const;
BOOST_ASIO_DECL bool is_multicast() const BOOST_ASIO_NOEXCEPT;
/// Compare two addresses for equality.
BOOST_ASIO_DECL friend bool operator==(const address& a1, const address& a2);
BOOST_ASIO_DECL friend bool operator==(const address& a1,
const address& a2) BOOST_ASIO_NOEXCEPT;
/// Compare two addresses for inequality.
friend bool operator!=(const address& a1, const address& a2)
friend bool operator!=(const address& a1,
const address& a2) BOOST_ASIO_NOEXCEPT
{
return !(a1 == a2);
}
/// Compare addresses for ordering.
BOOST_ASIO_DECL friend bool operator<(const address& a1, const address& a2);
BOOST_ASIO_DECL friend bool operator<(const address& a1,
const address& a2) BOOST_ASIO_NOEXCEPT;
/// Compare addresses for ordering.
friend bool operator>(const address& a1, const address& a2)
friend bool operator>(const address& a1,
const address& a2) BOOST_ASIO_NOEXCEPT
{
return a2 < a1;
}
/// Compare addresses for ordering.
friend bool operator<=(const address& a1, const address& a2)
friend bool operator<=(const address& a1,
const address& a2) BOOST_ASIO_NOEXCEPT
{
return !(a2 < a1);
}
/// Compare addresses for ordering.
friend bool operator>=(const address& a1, const address& a2)
friend bool operator>=(const address& a1,
const address& a2) BOOST_ASIO_NOEXCEPT
{
return !(a1 < a2);
}
@@ -168,6 +185,57 @@ private:
boost::asio::ip::address_v6 ipv6_address_;
};
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
/**
* @relates address
*/
BOOST_ASIO_DECL address make_address(const char* str);
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
/**
* @relates address
*/
BOOST_ASIO_DECL address make_address(const char* str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
/**
* @relates address
*/
BOOST_ASIO_DECL address make_address(const std::string& str);
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
/**
* @relates address
*/
BOOST_ASIO_DECL address make_address(const std::string& str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_STRING_VIEW) \
|| defined(GENERATING_DOCUMENTATION)
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
/**
* @relates address
*/
BOOST_ASIO_DECL address make_address(string_view str);
/// Create an address from an IPv4 address string in dotted decimal form,
/// or from an IPv6 address in hexadecimal notation.
/**
* @relates address
*/
BOOST_ASIO_DECL address make_address(string_view str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
// || defined(GENERATING_DOCUMENTATION)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// Output an address as a string.

View File

@@ -2,7 +2,7 @@
// ip/address_v4.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -18,7 +18,9 @@
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/detail/array.hpp>
#include <boost/asio/detail/cstdint.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/string_view.hpp>
#include <boost/asio/detail/winsock_init.hpp>
#include <boost/system/error_code.hpp>
@@ -44,6 +46,9 @@ namespace ip {
class address_v4
{
public:
/// The type used to represent an address as an unsigned integer.
typedef uint_least32_t uint_type;
/// The type used to represent an address as an array of bytes.
/**
* @note This type is defined in terms of the C++0x template @c std::array
@@ -56,7 +61,7 @@ public:
#endif
/// Default constructor.
address_v4()
address_v4() BOOST_ASIO_NOEXCEPT
{
addr_.s_addr = 0;
}
@@ -64,25 +69,25 @@ public:
/// Construct an address from raw bytes.
BOOST_ASIO_DECL explicit address_v4(const bytes_type& bytes);
/// Construct an address from a unsigned long in host byte order.
BOOST_ASIO_DECL explicit address_v4(unsigned long addr);
/// Construct an address from an unsigned integer in host byte order.
BOOST_ASIO_DECL explicit address_v4(uint_type addr);
/// Copy constructor.
address_v4(const address_v4& other)
address_v4(const address_v4& other) BOOST_ASIO_NOEXCEPT
: addr_(other.addr_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
address_v4(address_v4&& other)
address_v4(address_v4&& other) BOOST_ASIO_NOEXCEPT
: addr_(other.addr_)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assign from another address.
address_v4& operator=(const address_v4& other)
address_v4& operator=(const address_v4& other) BOOST_ASIO_NOEXCEPT
{
addr_ = other.addr_;
return *this;
@@ -90,7 +95,7 @@ public:
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move-assign from another address.
address_v4& operator=(address_v4&& other)
address_v4& operator=(address_v4&& other) BOOST_ASIO_NOEXCEPT
{
addr_ = other.addr_;
return *this;
@@ -98,117 +103,206 @@ public:
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Get the address in bytes, in network byte order.
BOOST_ASIO_DECL bytes_type to_bytes() const;
BOOST_ASIO_DECL bytes_type to_bytes() const BOOST_ASIO_NOEXCEPT;
/// Get the address as an unsigned integer in host byte order
BOOST_ASIO_DECL uint_type to_uint() const BOOST_ASIO_NOEXCEPT;
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// Get the address as an unsigned long in host byte order
BOOST_ASIO_DECL unsigned long to_ulong() const;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Get the address as a string in dotted decimal format.
BOOST_ASIO_DECL std::string to_string() const;
/// Get the address as a string in dotted decimal format.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use other overload.) Get the address as a string in dotted
/// decimal format.
BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
/// Create an address from an IP address string in dotted decimal form.
BOOST_ASIO_DECL static address_v4 from_string(const char* str);
/// (Deprecated: Use make_address_v4().) Create an address from an IP address
/// string in dotted decimal form.
static address_v4 from_string(const char* str);
/// Create an address from an IP address string in dotted decimal form.
BOOST_ASIO_DECL static address_v4 from_string(
/// (Deprecated: Use make_address_v4().) Create an address from an IP address
/// string in dotted decimal form.
static address_v4 from_string(
const char* str, boost::system::error_code& ec);
/// Create an address from an IP address string in dotted decimal form.
BOOST_ASIO_DECL static address_v4 from_string(const std::string& str);
/// (Deprecated: Use make_address_v4().) Create an address from an IP address
/// string in dotted decimal form.
static address_v4 from_string(const std::string& str);
/// Create an address from an IP address string in dotted decimal form.
BOOST_ASIO_DECL static address_v4 from_string(
/// (Deprecated: Use make_address_v4().) Create an address from an IP address
/// string in dotted decimal form.
static address_v4 from_string(
const std::string& str, boost::system::error_code& ec);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a loopback address.
BOOST_ASIO_DECL bool is_loopback() const;
BOOST_ASIO_DECL bool is_loopback() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is unspecified.
BOOST_ASIO_DECL bool is_unspecified() const;
BOOST_ASIO_DECL bool is_unspecified() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a class A address.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use network_v4 class.) Determine whether the address is a
/// class A address.
BOOST_ASIO_DECL bool is_class_a() const;
/// Determine whether the address is a class B address.
/// (Deprecated: Use network_v4 class.) Determine whether the address is a
/// class B address.
BOOST_ASIO_DECL bool is_class_b() const;
/// Determine whether the address is a class C address.
/// (Deprecated: Use network_v4 class.) Determine whether the address is a
/// class C address.
BOOST_ASIO_DECL bool is_class_c() const;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a multicast address.
BOOST_ASIO_DECL bool is_multicast() const;
BOOST_ASIO_DECL bool is_multicast() const BOOST_ASIO_NOEXCEPT;
/// Compare two addresses for equality.
friend bool operator==(const address_v4& a1, const address_v4& a2)
friend bool operator==(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
return a1.addr_.s_addr == a2.addr_.s_addr;
}
/// Compare two addresses for inequality.
friend bool operator!=(const address_v4& a1, const address_v4& a2)
friend bool operator!=(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
return a1.addr_.s_addr != a2.addr_.s_addr;
}
/// Compare addresses for ordering.
friend bool operator<(const address_v4& a1, const address_v4& a2)
friend bool operator<(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
return a1.to_ulong() < a2.to_ulong();
return a1.to_uint() < a2.to_uint();
}
/// Compare addresses for ordering.
friend bool operator>(const address_v4& a1, const address_v4& a2)
friend bool operator>(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
return a1.to_ulong() > a2.to_ulong();
return a1.to_uint() > a2.to_uint();
}
/// Compare addresses for ordering.
friend bool operator<=(const address_v4& a1, const address_v4& a2)
friend bool operator<=(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
return a1.to_ulong() <= a2.to_ulong();
return a1.to_uint() <= a2.to_uint();
}
/// Compare addresses for ordering.
friend bool operator>=(const address_v4& a1, const address_v4& a2)
friend bool operator>=(const address_v4& a1,
const address_v4& a2) BOOST_ASIO_NOEXCEPT
{
return a1.to_ulong() >= a2.to_ulong();
return a1.to_uint() >= a2.to_uint();
}
/// Obtain an address object that represents any address.
static address_v4 any()
static address_v4 any() BOOST_ASIO_NOEXCEPT
{
return address_v4();
}
/// Obtain an address object that represents the loopback address.
static address_v4 loopback()
static address_v4 loopback() BOOST_ASIO_NOEXCEPT
{
return address_v4(0x7F000001);
}
/// Obtain an address object that represents the broadcast address.
static address_v4 broadcast()
static address_v4 broadcast() BOOST_ASIO_NOEXCEPT
{
return address_v4(0xFFFFFFFF);
}
/// Obtain an address object that represents the broadcast address that
/// corresponds to the specified address and netmask.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use network_v4 class.) Obtain an address object that
/// represents the broadcast address that corresponds to the specified
/// address and netmask.
BOOST_ASIO_DECL static address_v4 broadcast(
const address_v4& addr, const address_v4& mask);
/// Obtain the netmask that corresponds to the address, based on its address
/// class.
/// (Deprecated: Use network_v4 class.) Obtain the netmask that corresponds
/// to the address, based on its address class.
BOOST_ASIO_DECL static address_v4 netmask(const address_v4& addr);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
private:
// The underlying IPv4 address.
boost::asio::detail::in4_addr_type addr_;
};
/// Create an IPv4 address from raw bytes in network order.
/**
* @relates address_v4
*/
inline address_v4 make_address_v4(const address_v4::bytes_type& bytes)
{
return address_v4(bytes);
}
/// Create an IPv4 address from an unsigned integer in host byte order.
/**
* @relates address_v4
*/
inline address_v4 make_address_v4(address_v4::uint_type addr)
{
return address_v4(addr);
}
/// Create an IPv4 address from an IP address string in dotted decimal form.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(const char* str);
/// Create an IPv4 address from an IP address string in dotted decimal form.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(const char* str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
/// Create an IPv4 address from an IP address string in dotted decimal form.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(const std::string& str);
/// Create an IPv4 address from an IP address string in dotted decimal form.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(const std::string& str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_STRING_VIEW) \
|| defined(GENERATING_DOCUMENTATION)
/// Create an IPv4 address from an IP address string in dotted decimal form.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(string_view str);
/// Create an IPv4 address from an IP address string in dotted decimal form.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(string_view str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
// || defined(GENERATING_DOCUMENTATION)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// Output an address as a string.

View File

@@ -0,0 +1,164 @@
//
// ip/address_v4_iterator.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_ADDRESS_V4_ITERATOR_HPP
#define BOOST_ASIO_IP_ADDRESS_V4_ITERATOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ip/address_v4.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
template <typename> class basic_address_iterator;
/// An input iterator that can be used for traversing IPv4 addresses.
/**
* In addition to satisfying the input iterator requirements, this iterator
* also supports decrement.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <> class basic_address_iterator<address_v4>
{
public:
/// The type of the elements pointed to by the iterator.
typedef address_v4 value_type;
/// Distance between two iterators.
typedef std::ptrdiff_t difference_type;
/// The type of a pointer to an element pointed to by the iterator.
typedef const address_v4* pointer;
/// The type of a reference to an element pointed to by the iterator.
typedef const address_v4& reference;
/// Denotes that the iterator satisfies the input iterator requirements.
typedef std::input_iterator_tag iterator_category;
/// Construct an iterator that points to the specified address.
basic_address_iterator(const address_v4& addr) BOOST_ASIO_NOEXCEPT
: address_(addr)
{
}
/// Copy constructor.
basic_address_iterator(
const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
: address_(other.address_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
basic_address_iterator(basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
: address_(BOOST_ASIO_MOVE_CAST(address_v4)(other.address_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assignment operator.
basic_address_iterator& operator=(
const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
{
address_ = other.address_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move assignment operator.
basic_address_iterator& operator=(
basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
{
address_ = BOOST_ASIO_MOVE_CAST(address_v4)(other.address_);
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Dereference the iterator.
const address_v4& operator*() const BOOST_ASIO_NOEXCEPT
{
return address_;
}
/// Dereference the iterator.
const address_v4* operator->() const BOOST_ASIO_NOEXCEPT
{
return &address_;
}
/// Pre-increment operator.
basic_address_iterator& operator++() BOOST_ASIO_NOEXCEPT
{
address_ = address_v4((address_.to_uint() + 1) & 0xFFFFFFFF);
return *this;
}
/// Post-increment operator.
basic_address_iterator operator++(int) BOOST_ASIO_NOEXCEPT
{
basic_address_iterator tmp(*this);
++*this;
return tmp;
}
/// Pre-decrement operator.
basic_address_iterator& operator--() BOOST_ASIO_NOEXCEPT
{
address_ = address_v4((address_.to_uint() - 1) & 0xFFFFFFFF);
return *this;
}
/// Post-decrement operator.
basic_address_iterator operator--(int)
{
basic_address_iterator tmp(*this);
--*this;
return tmp;
}
/// Compare two addresses for equality.
friend bool operator==(const basic_address_iterator& a,
const basic_address_iterator& b)
{
return a.address_ == b.address_;
}
/// Compare two addresses for inequality.
friend bool operator!=(const basic_address_iterator& a,
const basic_address_iterator& b)
{
return a.address_ != b.address_;
}
private:
address_v4 address_;
};
/// An input iterator that can be used for traversing IPv4 addresses.
typedef basic_address_iterator<address_v4> address_v4_iterator;
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_ADDRESS_V4_ITERATOR_HPP

View File

@@ -0,0 +1,136 @@
//
// ip/address_v4_range.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP
#define BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ip/address_v4_iterator.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
template <typename> class basic_address_range;
/// Represents a range of IPv4 addresses.
/**
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <> class basic_address_range<address_v4>
{
public:
/// The type of an iterator that points into the range.
typedef basic_address_iterator<address_v4> iterator;
/// Construct an empty range.
basic_address_range() BOOST_ASIO_NOEXCEPT
: begin_(address_v4()),
end_(address_v4())
{
}
/// Construct an range that represents the given range of addresses.
explicit basic_address_range(const iterator& first,
const iterator& last) BOOST_ASIO_NOEXCEPT
: begin_(first),
end_(last)
{
}
/// Copy constructor.
basic_address_range(const basic_address_range& other) BOOST_ASIO_NOEXCEPT
: begin_(other.begin_),
end_(other.end_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
basic_address_range(basic_address_range&& other) BOOST_ASIO_NOEXCEPT
: begin_(BOOST_ASIO_MOVE_CAST(iterator)(other.begin_)),
end_(BOOST_ASIO_MOVE_CAST(iterator)(other.end_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assignment operator.
basic_address_range& operator=(
const basic_address_range& other) BOOST_ASIO_NOEXCEPT
{
begin_ = other.begin_;
end_ = other.end_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move assignment operator.
basic_address_range& operator=(
basic_address_range&& other) BOOST_ASIO_NOEXCEPT
{
begin_ = BOOST_ASIO_MOVE_CAST(iterator)(other.begin_);
end_ = BOOST_ASIO_MOVE_CAST(iterator)(other.end_);
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Obtain an iterator that points to the start of the range.
iterator begin() const BOOST_ASIO_NOEXCEPT
{
return begin_;
}
/// Obtain an iterator that points to the end of the range.
iterator end() const BOOST_ASIO_NOEXCEPT
{
return end_;
}
/// Determine whether the range is empty.
bool empty() const BOOST_ASIO_NOEXCEPT
{
return size() == 0;
}
/// Return the size of the range.
std::size_t size() const BOOST_ASIO_NOEXCEPT
{
return end_->to_uint() - begin_->to_uint();
}
/// Find an address in the range.
iterator find(const address_v4& addr) const BOOST_ASIO_NOEXCEPT
{
return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
}
private:
iterator begin_;
iterator end_;
};
/// Represents a range of IPv4 addresses.
typedef basic_address_range<address_v4> address_v4_range;
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_ADDRESS_V4_RANGE_HPP

View File

@@ -2,7 +2,7 @@
// ip/address_v6.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -19,6 +19,7 @@
#include <string>
#include <boost/asio/detail/array.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/string_view.hpp>
#include <boost/asio/detail/winsock_init.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/ip/address_v4.hpp>
@@ -33,6 +34,8 @@ namespace boost {
namespace asio {
namespace ip {
template <typename> class basic_address_iterator;
/// Implements IP version 6 style addresses.
/**
* The boost::asio::ip::address_v6 class provides the ability to use and
@@ -57,33 +60,34 @@ public:
#endif
/// Default constructor.
BOOST_ASIO_DECL address_v6();
BOOST_ASIO_DECL address_v6() BOOST_ASIO_NOEXCEPT;
/// Construct an address from raw bytes and scope ID.
BOOST_ASIO_DECL explicit address_v6(const bytes_type& bytes,
unsigned long scope_id = 0);
/// Copy constructor.
BOOST_ASIO_DECL address_v6(const address_v6& other);
BOOST_ASIO_DECL address_v6(const address_v6& other) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
BOOST_ASIO_DECL address_v6(address_v6&& other);
BOOST_ASIO_DECL address_v6(address_v6&& other) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assign from another address.
BOOST_ASIO_DECL address_v6& operator=(const address_v6& other);
BOOST_ASIO_DECL address_v6& operator=(
const address_v6& other) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move-assign from another address.
BOOST_ASIO_DECL address_v6& operator=(address_v6&& other);
BOOST_ASIO_DECL address_v6& operator=(address_v6&& other) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// The scope ID of the address.
/**
* Returns the scope ID associated with the IPv6 address.
*/
unsigned long scope_id() const
unsigned long scope_id() const BOOST_ASIO_NOEXCEPT
{
return scope_id_;
}
@@ -92,121 +96,139 @@ public:
/**
* Modifies the scope ID associated with the IPv6 address.
*/
void scope_id(unsigned long id)
void scope_id(unsigned long id) BOOST_ASIO_NOEXCEPT
{
scope_id_ = id;
}
/// Get the address in bytes, in network byte order.
BOOST_ASIO_DECL bytes_type to_bytes() const;
BOOST_ASIO_DECL bytes_type to_bytes() const BOOST_ASIO_NOEXCEPT;
/// Get the address as a string.
BOOST_ASIO_DECL std::string to_string() const;
/// Get the address as a string.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use other overload.) Get the address as a string.
BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
/// Create an address from an IP address string.
BOOST_ASIO_DECL static address_v6 from_string(const char* str);
/// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
/// address string.
static address_v6 from_string(const char* str);
/// Create an address from an IP address string.
BOOST_ASIO_DECL static address_v6 from_string(
/// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
/// address string.
static address_v6 from_string(
const char* str, boost::system::error_code& ec);
/// Create an address from an IP address string.
BOOST_ASIO_DECL static address_v6 from_string(const std::string& str);
/// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
/// address string.
static address_v6 from_string(const std::string& str);
/// Create an address from an IP address string.
BOOST_ASIO_DECL static address_v6 from_string(
/// (Deprecated: Use make_address_v6().) Create an IPv6 address from an IP
/// address string.
static address_v6 from_string(
const std::string& str, boost::system::error_code& ec);
/// Converts an IPv4-mapped or IPv4-compatible address to an IPv4 address.
/// (Deprecated: Use make_address_v4().) Converts an IPv4-mapped or
/// IPv4-compatible address to an IPv4 address.
BOOST_ASIO_DECL address_v4 to_v4() const;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a loopback address.
BOOST_ASIO_DECL bool is_loopback() const;
BOOST_ASIO_DECL bool is_loopback() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is unspecified.
BOOST_ASIO_DECL bool is_unspecified() const;
BOOST_ASIO_DECL bool is_unspecified() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is link local.
BOOST_ASIO_DECL bool is_link_local() const;
BOOST_ASIO_DECL bool is_link_local() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is site local.
BOOST_ASIO_DECL bool is_site_local() const;
BOOST_ASIO_DECL bool is_site_local() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a mapped IPv4 address.
BOOST_ASIO_DECL bool is_v4_mapped() const;
BOOST_ASIO_DECL bool is_v4_mapped() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is an IPv4-compatible address.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: No replacement.) Determine whether the address is an
/// IPv4-compatible address.
BOOST_ASIO_DECL bool is_v4_compatible() const;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Determine whether the address is a multicast address.
BOOST_ASIO_DECL bool is_multicast() const;
BOOST_ASIO_DECL bool is_multicast() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a global multicast address.
BOOST_ASIO_DECL bool is_multicast_global() const;
BOOST_ASIO_DECL bool is_multicast_global() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a link-local multicast address.
BOOST_ASIO_DECL bool is_multicast_link_local() const;
BOOST_ASIO_DECL bool is_multicast_link_local() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a node-local multicast address.
BOOST_ASIO_DECL bool is_multicast_node_local() const;
BOOST_ASIO_DECL bool is_multicast_node_local() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a org-local multicast address.
BOOST_ASIO_DECL bool is_multicast_org_local() const;
BOOST_ASIO_DECL bool is_multicast_org_local() const BOOST_ASIO_NOEXCEPT;
/// Determine whether the address is a site-local multicast address.
BOOST_ASIO_DECL bool is_multicast_site_local() const;
BOOST_ASIO_DECL bool is_multicast_site_local() const BOOST_ASIO_NOEXCEPT;
/// Compare two addresses for equality.
BOOST_ASIO_DECL friend bool operator==(
const address_v6& a1, const address_v6& a2);
BOOST_ASIO_DECL friend bool operator==(const address_v6& a1,
const address_v6& a2) BOOST_ASIO_NOEXCEPT;
/// Compare two addresses for inequality.
friend bool operator!=(const address_v6& a1, const address_v6& a2)
friend bool operator!=(const address_v6& a1,
const address_v6& a2) BOOST_ASIO_NOEXCEPT
{
return !(a1 == a2);
}
/// Compare addresses for ordering.
BOOST_ASIO_DECL friend bool operator<(
const address_v6& a1, const address_v6& a2);
BOOST_ASIO_DECL friend bool operator<(const address_v6& a1,
const address_v6& a2) BOOST_ASIO_NOEXCEPT;
/// Compare addresses for ordering.
friend bool operator>(const address_v6& a1, const address_v6& a2)
friend bool operator>(const address_v6& a1,
const address_v6& a2) BOOST_ASIO_NOEXCEPT
{
return a2 < a1;
}
/// Compare addresses for ordering.
friend bool operator<=(const address_v6& a1, const address_v6& a2)
friend bool operator<=(const address_v6& a1,
const address_v6& a2) BOOST_ASIO_NOEXCEPT
{
return !(a2 < a1);
}
/// Compare addresses for ordering.
friend bool operator>=(const address_v6& a1, const address_v6& a2)
friend bool operator>=(const address_v6& a1,
const address_v6& a2) BOOST_ASIO_NOEXCEPT
{
return !(a1 < a2);
}
/// Obtain an address object that represents any address.
static address_v6 any()
static address_v6 any() BOOST_ASIO_NOEXCEPT
{
return address_v6();
}
/// Obtain an address object that represents the loopback address.
BOOST_ASIO_DECL static address_v6 loopback();
BOOST_ASIO_DECL static address_v6 loopback() BOOST_ASIO_NOEXCEPT;
/// Create an IPv4-mapped IPv6 address.
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use make_address_v6().) Create an IPv4-mapped IPv6 address.
BOOST_ASIO_DECL static address_v6 v4_mapped(const address_v4& addr);
/// Create an IPv4-compatible IPv6 address.
/// (Deprecated: No replacement.) Create an IPv4-compatible IPv6 address.
BOOST_ASIO_DECL static address_v6 v4_compatible(const address_v4& addr);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
private:
friend class basic_address_iterator<address_v6>;
// The underlying IPv6 address.
boost::asio::detail::in6_addr_type addr_;
@@ -214,6 +236,79 @@ private:
unsigned long scope_id_;
};
/// Create an IPv6 address from raw bytes and scope ID.
/**
* @relates address_v6
*/
inline address_v6 make_address_v6(const address_v6::bytes_type& bytes,
unsigned long scope_id = 0)
{
return address_v6(bytes, scope_id);
}
/// Create an IPv6 address from an IP address string.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(const char* str);
/// Create an IPv6 address from an IP address string.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(const char* str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
/// Createan IPv6 address from an IP address string.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(const std::string& str);
/// Create an IPv6 address from an IP address string.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(const std::string& str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
#if defined(BOOST_ASIO_HAS_STRING_VIEW) \
|| defined(GENERATING_DOCUMENTATION)
/// Create an IPv6 address from an IP address string.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(string_view str);
/// Create an IPv6 address from an IP address string.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(string_view str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT;
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
// || defined(GENERATING_DOCUMENTATION)
/// Tag type used for distinguishing overloads that deal in IPv4-mapped IPv6
/// addresses.
enum v4_mapped_t { v4_mapped };
/// Create an IPv4 address from a IPv4-mapped IPv6 address.
/**
* @relates address_v4
*/
BOOST_ASIO_DECL address_v4 make_address_v4(
v4_mapped_t, const address_v6& v6_addr);
/// Create an IPv4-mapped IPv6 address from an IPv4 address.
/**
* @relates address_v6
*/
BOOST_ASIO_DECL address_v6 make_address_v6(
v4_mapped_t, const address_v4& v4_addr);
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// Output an address as a string.

View File

@@ -0,0 +1,185 @@
//
// ip/address_v6_iterator.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP
#define BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ip/address_v6.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
template <typename> class basic_address_iterator;
/// An input iterator that can be used for traversing IPv6 addresses.
/**
* In addition to satisfying the input iterator requirements, this iterator
* also supports decrement.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <> class basic_address_iterator<address_v6>
{
public:
/// The type of the elements pointed to by the iterator.
typedef address_v6 value_type;
/// Distance between two iterators.
typedef std::ptrdiff_t difference_type;
/// The type of a pointer to an element pointed to by the iterator.
typedef const address_v6* pointer;
/// The type of a reference to an element pointed to by the iterator.
typedef const address_v6& reference;
/// Denotes that the iterator satisfies the input iterator requirements.
typedef std::input_iterator_tag iterator_category;
/// Construct an iterator that points to the specified address.
basic_address_iterator(const address_v6& addr) BOOST_ASIO_NOEXCEPT
: address_(addr)
{
}
/// Copy constructor.
basic_address_iterator(
const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
: address_(other.address_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
basic_address_iterator(basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
: address_(BOOST_ASIO_MOVE_CAST(address_v6)(other.address_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assignment operator.
basic_address_iterator& operator=(
const basic_address_iterator& other) BOOST_ASIO_NOEXCEPT
{
address_ = other.address_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move assignment operator.
basic_address_iterator& operator=(
basic_address_iterator&& other) BOOST_ASIO_NOEXCEPT
{
address_ = BOOST_ASIO_MOVE_CAST(address_v6)(other.address_);
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Dereference the iterator.
const address_v6& operator*() const BOOST_ASIO_NOEXCEPT
{
return address_;
}
/// Dereference the iterator.
const address_v6* operator->() const BOOST_ASIO_NOEXCEPT
{
return &address_;
}
/// Pre-increment operator.
basic_address_iterator& operator++() BOOST_ASIO_NOEXCEPT
{
for (int i = 15; i >= 0; --i)
{
if (address_.addr_.s6_addr[i] < 0xFF)
{
++address_.addr_.s6_addr[i];
break;
}
address_.addr_.s6_addr[i] = 0;
}
return *this;
}
/// Post-increment operator.
basic_address_iterator operator++(int) BOOST_ASIO_NOEXCEPT
{
basic_address_iterator tmp(*this);
++*this;
return tmp;
}
/// Pre-decrement operator.
basic_address_iterator& operator--() BOOST_ASIO_NOEXCEPT
{
for (int i = 15; i >= 0; --i)
{
if (address_.addr_.s6_addr[i] > 0)
{
--address_.addr_.s6_addr[i];
break;
}
address_.addr_.s6_addr[i] = 0xFF;
}
return *this;
}
/// Post-decrement operator.
basic_address_iterator operator--(int)
{
basic_address_iterator tmp(*this);
--*this;
return tmp;
}
/// Compare two addresses for equality.
friend bool operator==(const basic_address_iterator& a,
const basic_address_iterator& b)
{
return a.address_ == b.address_;
}
/// Compare two addresses for inequality.
friend bool operator!=(const basic_address_iterator& a,
const basic_address_iterator& b)
{
return a.address_ != b.address_;
}
private:
address_v6 address_;
};
/// An input iterator that can be used for traversing IPv6 addresses.
typedef basic_address_iterator<address_v6> address_v6_iterator;
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_ADDRESS_V6_ITERATOR_HPP

View File

@@ -0,0 +1,131 @@
//
// ip/address_v6_range.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
#define BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ip/address_v6_iterator.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
template <typename> class basic_address_range;
/// Represents a range of IPv6 addresses.
/**
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <> class basic_address_range<address_v6>
{
public:
/// The type of an iterator that points into the range.
typedef basic_address_iterator<address_v6> iterator;
/// Construct an empty range.
basic_address_range() BOOST_ASIO_NOEXCEPT
: begin_(address_v6()),
end_(address_v6())
{
}
/// Construct an range that represents the given range of addresses.
explicit basic_address_range(const iterator& first,
const iterator& last) BOOST_ASIO_NOEXCEPT
: begin_(first),
end_(last)
{
}
/// Copy constructor.
basic_address_range(const basic_address_range& other) BOOST_ASIO_NOEXCEPT
: begin_(other.begin_),
end_(other.end_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
basic_address_range(basic_address_range&& other) BOOST_ASIO_NOEXCEPT
: begin_(BOOST_ASIO_MOVE_CAST(iterator)(other.begin_)),
end_(BOOST_ASIO_MOVE_CAST(iterator)(other.end_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assignment operator.
basic_address_range& operator=(
const basic_address_range& other) BOOST_ASIO_NOEXCEPT
{
begin_ = other.begin_;
end_ = other.end_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move assignment operator.
basic_address_range& operator=(
basic_address_range&& other) BOOST_ASIO_NOEXCEPT
{
begin_ = BOOST_ASIO_MOVE_CAST(iterator)(other.begin_);
end_ = BOOST_ASIO_MOVE_CAST(iterator)(other.end_);
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Obtain an iterator that points to the start of the range.
iterator begin() const BOOST_ASIO_NOEXCEPT
{
return begin_;
}
/// Obtain an iterator that points to the end of the range.
iterator end() const BOOST_ASIO_NOEXCEPT
{
return end_;
}
/// Determine whether the range is empty.
bool empty() const BOOST_ASIO_NOEXCEPT
{
return begin_ == end_;
}
/// Find an address in the range.
iterator find(const address_v6& addr) const BOOST_ASIO_NOEXCEPT
{
return addr >= *begin_ && addr < *end_ ? iterator(addr) : end_;
}
private:
iterator begin_;
iterator end_;
};
/// Represents a range of IPv6 addresses.
typedef basic_address_range<address_v6> address_v6_range;
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_ADDRESS_V6_RANGE_HPP

View File

@@ -0,0 +1,55 @@
//
// ip/bad_address_cast.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_BAD_ADDRESS_CAST_HPP
#define BOOST_ASIO_IP_BAD_ADDRESS_CAST_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <typeinfo>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
/// Thrown to indicate a failed address conversion.
class bad_address_cast :
#if defined(BOOST_ASIO_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
public std::exception
#else
public std::bad_cast
#endif
{
public:
/// Default constructor.
bad_address_cast() {}
/// Destructor.
virtual ~bad_address_cast() BOOST_ASIO_NOEXCEPT_OR_NOTHROW {}
/// Get the message associated with the exception.
virtual const char* what() const BOOST_ASIO_NOEXCEPT_OR_NOTHROW
{
return "bad address cast";
}
};
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_ADDRESS_HPP

View File

@@ -2,7 +2,7 @@
// ip/basic_endpoint.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -57,7 +57,7 @@ public:
#endif
/// Default constructor.
basic_endpoint()
basic_endpoint() BOOST_ASIO_NOEXCEPT
: impl_()
{
}
@@ -79,7 +79,7 @@ public:
* @endcode
*/
basic_endpoint(const InternetProtocol& internet_protocol,
unsigned short port_num)
unsigned short port_num) BOOST_ASIO_NOEXCEPT
: impl_(internet_protocol.family(), port_num)
{
}
@@ -87,43 +87,44 @@ public:
/// Construct an endpoint using a port number and an IP address. This
/// constructor may be used for accepting connections on a specific interface
/// or for making a connection to a remote endpoint.
basic_endpoint(const boost::asio::ip::address& addr, unsigned short port_num)
basic_endpoint(const boost::asio::ip::address& addr,
unsigned short port_num) BOOST_ASIO_NOEXCEPT
: impl_(addr, port_num)
{
}
/// Copy constructor.
basic_endpoint(const basic_endpoint& other)
basic_endpoint(const basic_endpoint& other) BOOST_ASIO_NOEXCEPT
: impl_(other.impl_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move constructor.
basic_endpoint(basic_endpoint&& other)
basic_endpoint(basic_endpoint&& other) BOOST_ASIO_NOEXCEPT
: impl_(other.impl_)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Assign from another endpoint.
basic_endpoint& operator=(const basic_endpoint& other)
basic_endpoint& operator=(const basic_endpoint& other) BOOST_ASIO_NOEXCEPT
{
impl_ = other.impl_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move-assign from another endpoint.
basic_endpoint& operator=(basic_endpoint&& other)
basic_endpoint& operator=(basic_endpoint&& other) BOOST_ASIO_NOEXCEPT
{
impl_ = other.impl_;
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// The protocol associated with the endpoint.
protocol_type protocol() const
protocol_type protocol() const BOOST_ASIO_NOEXCEPT
{
if (impl_.is_v4())
return InternetProtocol::v4();
@@ -131,19 +132,19 @@ public:
}
/// Get the underlying endpoint in the native type.
data_type* data()
data_type* data() BOOST_ASIO_NOEXCEPT
{
return impl_.data();
}
/// Get the underlying endpoint in the native type.
const data_type* data() const
const data_type* data() const BOOST_ASIO_NOEXCEPT
{
return impl_.data();
}
/// Get the underlying size of the endpoint in the native type.
std::size_t size() const
std::size_t size() const BOOST_ASIO_NOEXCEPT
{
return impl_.size();
}
@@ -155,75 +156,75 @@ public:
}
/// Get the capacity of the endpoint in the native type.
std::size_t capacity() const
std::size_t capacity() const BOOST_ASIO_NOEXCEPT
{
return impl_.capacity();
}
/// Get the port associated with the endpoint. The port number is always in
/// the host's byte order.
unsigned short port() const
unsigned short port() const BOOST_ASIO_NOEXCEPT
{
return impl_.port();
}
/// Set the port associated with the endpoint. The port number is always in
/// the host's byte order.
void port(unsigned short port_num)
void port(unsigned short port_num) BOOST_ASIO_NOEXCEPT
{
impl_.port(port_num);
}
/// Get the IP address associated with the endpoint.
boost::asio::ip::address address() const
boost::asio::ip::address address() const BOOST_ASIO_NOEXCEPT
{
return impl_.address();
}
/// Set the IP address associated with the endpoint.
void address(const boost::asio::ip::address& addr)
void address(const boost::asio::ip::address& addr) BOOST_ASIO_NOEXCEPT
{
impl_.address(addr);
}
/// Compare two endpoints for equality.
friend bool operator==(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2)
const basic_endpoint<InternetProtocol>& e2) BOOST_ASIO_NOEXCEPT
{
return e1.impl_ == e2.impl_;
}
/// Compare two endpoints for inequality.
friend bool operator!=(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2)
const basic_endpoint<InternetProtocol>& e2) BOOST_ASIO_NOEXCEPT
{
return !(e1 == e2);
}
/// Compare endpoints for ordering.
friend bool operator<(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2)
const basic_endpoint<InternetProtocol>& e2) BOOST_ASIO_NOEXCEPT
{
return e1.impl_ < e2.impl_;
}
/// Compare endpoints for ordering.
friend bool operator>(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2)
const basic_endpoint<InternetProtocol>& e2) BOOST_ASIO_NOEXCEPT
{
return e2.impl_ < e1.impl_;
}
/// Compare endpoints for ordering.
friend bool operator<=(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2)
const basic_endpoint<InternetProtocol>& e2) BOOST_ASIO_NOEXCEPT
{
return !(e2 < e1);
}
/// Compare endpoints for ordering.
friend bool operator>=(const basic_endpoint<InternetProtocol>& e1,
const basic_endpoint<InternetProtocol>& e2)
const basic_endpoint<InternetProtocol>& e2) BOOST_ASIO_NOEXCEPT
{
return !(e1 < e2);
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
// ip/basic_resolver_entry.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,6 +17,7 @@
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/detail/string_view.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -50,10 +51,10 @@ public:
/// Construct with specified endpoint, host name and service name.
basic_resolver_entry(const endpoint_type& ep,
const std::string& host, const std::string& service)
BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service)
: endpoint_(ep),
host_name_(host),
service_name_(service)
host_name_(static_cast<std::string>(host)),
service_name_(static_cast<std::string>(service))
{
}
@@ -75,12 +76,30 @@ public:
return host_name_;
}
/// Get the host name associated with the entry.
template <class Allocator>
std::basic_string<char, std::char_traits<char>, Allocator> host_name(
const Allocator& alloc = Allocator()) const
{
return std::basic_string<char, std::char_traits<char>, Allocator>(
host_name_.c_str(), alloc);
}
/// Get the service name associated with the entry.
std::string service_name() const
{
return service_name_;
}
/// Get the service name associated with the entry.
template <class Allocator>
std::basic_string<char, std::char_traits<char>, Allocator> service_name(
const Allocator& alloc = Allocator()) const
{
return std::basic_string<char, std::char_traits<char>, Allocator>(
service_name_.c_str(), alloc);
}
private:
endpoint_type endpoint_;
std::string host_name_;

View File

@@ -2,7 +2,7 @@
// ip/basic_resolver_iterator.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -21,7 +21,7 @@
#include <iterator>
#include <string>
#include <vector>
#include <boost/asio/detail/shared_ptr.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/ip/basic_resolver_entry.hpp>
@@ -73,114 +73,45 @@ public:
{
}
/// Create an iterator from an addrinfo list returned by getaddrinfo.
static basic_resolver_iterator create(
boost::asio::detail::addrinfo_type* address_info,
const std::string& host_name, const std::string& service_name)
/// Copy constructor.
basic_resolver_iterator(const basic_resolver_iterator& other)
: values_(other.values_),
index_(other.index_)
{
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;
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move constructor.
basic_resolver_iterator(basic_resolver_iterator&& other)
: values_(BOOST_ASIO_MOVE_CAST(values_ptr_type)(other.values_)),
index_(other.index_)
{
other.index_ = 0;
}
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
iter.values_.reset(new values_type);
/// Assignment operator.
basic_resolver_iterator& operator=(const basic_resolver_iterator& other)
{
values_ = other.values_;
index_ = other.index_;
return *this;
}
while (address_info)
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move-assignment operator.
basic_resolver_iterator& operator=(basic_resolver_iterator&& other)
{
if (this != &other)
{
if (address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
|| address_info->ai_family == BOOST_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;
values_ = BOOST_ASIO_MOVE_CAST(values_ptr_type)(other.values_);
index_ = other.index_;
other.index_ = 0;
}
return iter;
return *this;
}
/// Create an iterator from an endpoint, host name and service name.
static basic_resolver_iterator create(
const typename InternetProtocol::endpoint& endpoint,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_iterator iter;
iter.values_.reset(new values_type);
iter.values_->push_back(
basic_resolver_entry<InternetProtocol>(
endpoint, host_name, service_name));
return iter;
}
/// Create an iterator from a sequence of endpoints, host and service name.
template <typename EndpointIterator>
static basic_resolver_iterator create(
EndpointIterator begin, EndpointIterator end,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_iterator iter;
if (begin != end)
{
iter.values_.reset(new values_type);
for (EndpointIterator ep_iter = begin; ep_iter != end; ++ep_iter)
{
iter.values_->push_back(
basic_resolver_entry<InternetProtocol>(
*ep_iter, host_name, service_name));
}
}
return iter;
}
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
/// Create an iterator from a Windows Runtime list of EndpointPair objects.
static basic_resolver_iterator create(
Windows::Foundation::Collections::IVectorView<
Windows::Networking::EndpointPair^>^ endpoints,
const boost::asio::detail::addrinfo_type& hints,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_iterator iter;
if (endpoints->Size)
{
iter.values_.reset(new values_type);
for (unsigned int i = 0; i < endpoints->Size; ++i)
{
auto pair = endpoints->GetAt(i);
if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET)
&& pair->RemoteHostName->Type
!= Windows::Networking::HostNameType::Ipv4)
continue;
if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET6)
&& pair->RemoteHostName->Type
!= Windows::Networking::HostNameType::Ipv6)
continue;
iter.values_->push_back(
basic_resolver_entry<InternetProtocol>(
typename InternetProtocol::endpoint(
ip::address::from_string(
boost::asio::detail::winrt_utils::string(
pair->RemoteHostName->CanonicalName)),
boost::asio::detail::winrt_utils::integer(
pair->RemoteServiceName)),
host_name, service_name));
}
}
return iter;
}
#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Dereference an iterator.
const basic_resolver_entry<InternetProtocol>& operator*() const
@@ -223,7 +154,7 @@ public:
return !a.equal(b);
}
private:
protected:
void increment()
{
if (++index_ == values_->size())
@@ -249,7 +180,8 @@ private:
}
typedef std::vector<basic_resolver_entry<InternetProtocol> > values_type;
boost::asio::detail::shared_ptr<values_type> values_;
typedef boost::asio::detail::shared_ptr<values_type> values_ptr_type;
values_ptr_type values_;
std::size_t index_;
};

View File

@@ -2,7 +2,7 @@
// ip/basic_resolver_query.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -0,0 +1,313 @@
//
// ip/basic_resolver_results.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_BASIC_RESOLVER_RESULTS_HPP
#define BOOST_ASIO_IP_BASIC_RESOLVER_RESULTS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <cstring>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/ip/basic_resolver_iterator.hpp>
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
# include <boost/asio/detail/winrt_utils.hpp>
#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
/// A range of entries produced by a resolver.
/**
* The boost::asio::ip::basic_resolver_results class template is used to define
* a range over the results returned by a resolver.
*
* The iterator's value_type, obtained when a results iterator is dereferenced,
* is: @code const basic_resolver_entry<InternetProtocol> @endcode
*
* @note For backward compatibility, basic_resolver_results is derived from
* basic_resolver_iterator. This derivation is deprecated.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <typename InternetProtocol>
class basic_resolver_results
#if !defined(BOOST_ASIO_NO_DEPRECATED)
: public basic_resolver_iterator<InternetProtocol>
#else // !defined(BOOST_ASIO_NO_DEPRECATED)
: private basic_resolver_iterator<InternetProtocol>
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
{
public:
/// The protocol type associated with the results.
typedef InternetProtocol protocol_type;
/// The endpoint type associated with the results.
typedef typename protocol_type::endpoint endpoint_type;
/// The type of a value in the results range.
typedef basic_resolver_entry<protocol_type> value_type;
/// The type of a const reference to a value in the range.
typedef const value_type& const_reference;
/// The type of a non-const reference to a value in the range.
typedef value_type& reference;
/// The type of an iterator into the range.
typedef basic_resolver_iterator<protocol_type> const_iterator;
/// The type of an iterator into the range.
typedef const_iterator iterator;
/// Type used to represent the distance between two iterators in the range.
typedef std::ptrdiff_t difference_type;
/// Type used to represent a count of the elements in the range.
typedef std::size_t size_type;
/// Default constructor creates an empty range.
basic_resolver_results()
{
}
/// Copy constructor.
basic_resolver_results(const basic_resolver_results& other)
: basic_resolver_iterator<InternetProtocol>(other)
{
}
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move constructor.
basic_resolver_results(basic_resolver_results&& other)
: basic_resolver_iterator<InternetProtocol>(
BOOST_ASIO_MOVE_CAST(basic_resolver_results)(other))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Assignment operator.
basic_resolver_results& operator=(const basic_resolver_results& other)
{
basic_resolver_iterator<InternetProtocol>::operator=(other);
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
/// Move-assignment operator.
basic_resolver_results& operator=(basic_resolver_results&& other)
{
basic_resolver_iterator<InternetProtocol>::operator=(
BOOST_ASIO_MOVE_CAST(basic_resolver_results)(other));
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
#if !defined(GENERATING_DOCUMENTATION)
// Create results from an addrinfo list returned by getaddrinfo.
static basic_resolver_results create(
boost::asio::detail::addrinfo_type* address_info,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_results results;
if (!address_info)
return results;
std::string actual_host_name = host_name;
if (address_info->ai_canonname)
actual_host_name = address_info->ai_canonname;
results.values_.reset(new values_type);
while (address_info)
{
if (address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
|| address_info->ai_family == BOOST_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);
results.values_->push_back(
basic_resolver_entry<InternetProtocol>(endpoint,
actual_host_name, service_name));
}
address_info = address_info->ai_next;
}
return results;
}
// Create results from an endpoint, host name and service name.
static basic_resolver_results create(const endpoint_type& endpoint,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_results results;
results.values_.reset(new values_type);
results.values_->push_back(
basic_resolver_entry<InternetProtocol>(
endpoint, host_name, service_name));
return results;
}
// Create results from a sequence of endpoints, host and service name.
template <typename EndpointIterator>
static basic_resolver_results create(
EndpointIterator begin, EndpointIterator end,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_results results;
if (begin != end)
{
results.values_.reset(new values_type);
for (EndpointIterator ep_iter = begin; ep_iter != end; ++ep_iter)
{
results.values_->push_back(
basic_resolver_entry<InternetProtocol>(
*ep_iter, host_name, service_name));
}
}
return results;
}
# if defined(BOOST_ASIO_WINDOWS_RUNTIME)
// Create results from a Windows Runtime list of EndpointPair objects.
static basic_resolver_results create(
Windows::Foundation::Collections::IVectorView<
Windows::Networking::EndpointPair^>^ endpoints,
const boost::asio::detail::addrinfo_type& hints,
const std::string& host_name, const std::string& service_name)
{
basic_resolver_results results;
if (endpoints->Size)
{
results.values_.reset(new values_type);
for (unsigned int i = 0; i < endpoints->Size; ++i)
{
auto pair = endpoints->GetAt(i);
if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET)
&& pair->RemoteHostName->Type
!= Windows::Networking::HostNameType::Ipv4)
continue;
if (hints.ai_family == BOOST_ASIO_OS_DEF(AF_INET6)
&& pair->RemoteHostName->Type
!= Windows::Networking::HostNameType::Ipv6)
continue;
results.values_->push_back(
basic_resolver_entry<InternetProtocol>(
typename InternetProtocol::endpoint(
ip::make_address(
boost::asio::detail::winrt_utils::string(
pair->RemoteHostName->CanonicalName)),
boost::asio::detail::winrt_utils::integer(
pair->RemoteServiceName)),
host_name, service_name));
}
}
return results;
}
# endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
#endif // !defined(GENERATING_DOCUMENTATION)
/// Get the number of entries in the results range.
size_type size() const BOOST_ASIO_NOEXCEPT
{
return this->values_ ? this->values_->size() : 0;
}
/// Get the maximum number of entries permitted in a results range.
size_type max_size() const BOOST_ASIO_NOEXCEPT
{
return this->values_ ? this->values_->max_size() : values_type().max_size();
}
/// Determine whether the results range is empty.
bool empty() const BOOST_ASIO_NOEXCEPT
{
return this->values_ ? this->values_->empty() : true;
}
/// Obtain a begin iterator for the results range.
const_iterator begin() const
{
basic_resolver_results tmp(*this);
tmp.index_ = 0;
return BOOST_ASIO_MOVE_CAST(basic_resolver_results)(tmp);
}
/// Obtain an end iterator for the results range.
const_iterator end() const
{
return const_iterator();
}
/// Obtain a begin iterator for the results range.
const_iterator cbegin() const
{
return begin();
}
/// Obtain an end iterator for the results range.
const_iterator cend() const
{
return end();
}
/// Swap the results range with another.
void swap(basic_resolver_results& that) BOOST_ASIO_NOEXCEPT
{
if (this != &that)
{
this->values_.swap(that.values_);
std::size_t index = this->index_;
this->index_ = that.index_;
that.index_ = index;
}
}
/// Test two iterators for equality.
friend bool operator==(const basic_resolver_results& a,
const basic_resolver_results& b)
{
return a.equal(b);
}
/// Test two iterators for inequality.
friend bool operator!=(const basic_resolver_results& a,
const basic_resolver_results& b)
{
return !a.equal(b);
}
private:
typedef std::vector<basic_resolver_entry<InternetProtocol> > values_type;
};
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_BASIC_RESOLVER_RESULTS_HPP

View File

@@ -2,7 +2,7 @@
// ip/detail/endpoint.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -34,42 +34,43 @@ class endpoint
{
public:
// Default constructor.
BOOST_ASIO_DECL endpoint();
BOOST_ASIO_DECL endpoint() BOOST_ASIO_NOEXCEPT;
// Construct an endpoint using a family and port number.
BOOST_ASIO_DECL endpoint(int family, unsigned short port_num);
BOOST_ASIO_DECL endpoint(int family,
unsigned short port_num) BOOST_ASIO_NOEXCEPT;
// Construct an endpoint using an address and port number.
BOOST_ASIO_DECL endpoint(const boost::asio::ip::address& addr,
unsigned short port_num);
unsigned short port_num) BOOST_ASIO_NOEXCEPT;
// Copy constructor.
endpoint(const endpoint& other)
endpoint(const endpoint& other) BOOST_ASIO_NOEXCEPT
: data_(other.data_)
{
}
// Assign from another endpoint.
endpoint& operator=(const endpoint& other)
endpoint& operator=(const endpoint& other) BOOST_ASIO_NOEXCEPT
{
data_ = other.data_;
return *this;
}
// Get the underlying endpoint in the native type.
boost::asio::detail::socket_addr_type* data()
boost::asio::detail::socket_addr_type* data() BOOST_ASIO_NOEXCEPT
{
return &data_.base;
}
// Get the underlying endpoint in the native type.
const boost::asio::detail::socket_addr_type* data() const
const boost::asio::detail::socket_addr_type* data() const BOOST_ASIO_NOEXCEPT
{
return &data_.base;
}
// Get the underlying size of the endpoint in the native type.
std::size_t size() const
std::size_t size() const BOOST_ASIO_NOEXCEPT
{
if (is_v4())
return sizeof(boost::asio::detail::sockaddr_in4_type);
@@ -81,40 +82,41 @@ public:
BOOST_ASIO_DECL void resize(std::size_t new_size);
// Get the capacity of the endpoint in the native type.
std::size_t capacity() const
std::size_t capacity() const BOOST_ASIO_NOEXCEPT
{
return sizeof(data_);
}
// Get the port associated with the endpoint.
BOOST_ASIO_DECL unsigned short port() const;
BOOST_ASIO_DECL unsigned short port() const BOOST_ASIO_NOEXCEPT;
// Set the port associated with the endpoint.
BOOST_ASIO_DECL void port(unsigned short port_num);
BOOST_ASIO_DECL void port(unsigned short port_num) BOOST_ASIO_NOEXCEPT;
// Get the IP address associated with the endpoint.
BOOST_ASIO_DECL boost::asio::ip::address address() const;
BOOST_ASIO_DECL boost::asio::ip::address address() const BOOST_ASIO_NOEXCEPT;
// Set the IP address associated with the endpoint.
BOOST_ASIO_DECL void address(const boost::asio::ip::address& addr);
BOOST_ASIO_DECL void address(
const boost::asio::ip::address& addr) BOOST_ASIO_NOEXCEPT;
// Compare two endpoints for equality.
BOOST_ASIO_DECL friend bool operator==(
const endpoint& e1, const endpoint& e2);
BOOST_ASIO_DECL friend bool operator==(const endpoint& e1,
const endpoint& e2) BOOST_ASIO_NOEXCEPT;
// Compare endpoints for ordering.
BOOST_ASIO_DECL friend bool operator<(
const endpoint& e1, const endpoint& e2);
BOOST_ASIO_DECL friend bool operator<(const endpoint& e1,
const endpoint& e2) BOOST_ASIO_NOEXCEPT;
// Determine whether the endpoint is IPv4.
bool is_v4() const
bool is_v4() const BOOST_ASIO_NOEXCEPT
{
return data_.base.sa_family == BOOST_ASIO_OS_DEF(AF_INET);
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
// Convert to a string.
BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
BOOST_ASIO_DECL std::string to_string() const;
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
private:

View File

@@ -2,7 +2,7 @@
// ip/detail/impl/endpoint.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -32,7 +32,7 @@ namespace asio {
namespace ip {
namespace detail {
endpoint::endpoint()
endpoint::endpoint() BOOST_ASIO_NOEXCEPT
: data_()
{
data_.v4.sin_family = BOOST_ASIO_OS_DEF(AF_INET);
@@ -40,7 +40,7 @@ endpoint::endpoint()
data_.v4.sin_addr.s_addr = BOOST_ASIO_OS_DEF(INADDR_ANY);
}
endpoint::endpoint(int family, unsigned short port_num)
endpoint::endpoint(int family, unsigned short port_num) BOOST_ASIO_NOEXCEPT
: data_()
{
using namespace std; // For memcpy.
@@ -70,7 +70,7 @@ endpoint::endpoint(int family, unsigned short port_num)
}
endpoint::endpoint(const boost::asio::ip::address& addr,
unsigned short port_num)
unsigned short port_num) BOOST_ASIO_NOEXCEPT
: data_()
{
using namespace std; // For memcpy.
@@ -81,8 +81,7 @@ endpoint::endpoint(const boost::asio::ip::address& addr,
boost::asio::detail::socket_ops::host_to_network_short(port_num);
data_.v4.sin_addr.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
static_cast<boost::asio::detail::u_long_type>(
addr.to_v4().to_ulong()));
addr.to_v4().to_uint());
}
else
{
@@ -108,7 +107,7 @@ void endpoint::resize(std::size_t new_size)
}
}
unsigned short endpoint::port() const
unsigned short endpoint::port() const BOOST_ASIO_NOEXCEPT
{
if (is_v4())
{
@@ -122,7 +121,7 @@ unsigned short endpoint::port() const
}
}
void endpoint::port(unsigned short port_num)
void endpoint::port(unsigned short port_num) BOOST_ASIO_NOEXCEPT
{
if (is_v4())
{
@@ -136,7 +135,7 @@ void endpoint::port(unsigned short port_num)
}
}
boost::asio::ip::address endpoint::address() const
boost::asio::ip::address endpoint::address() const BOOST_ASIO_NOEXCEPT
{
using namespace std; // For memcpy.
if (is_v4())
@@ -157,18 +156,18 @@ boost::asio::ip::address endpoint::address() const
}
}
void endpoint::address(const boost::asio::ip::address& addr)
void endpoint::address(const boost::asio::ip::address& addr) BOOST_ASIO_NOEXCEPT
{
endpoint tmp_endpoint(addr, port());
data_ = tmp_endpoint.data_;
}
bool operator==(const endpoint& e1, const endpoint& e2)
bool operator==(const endpoint& e1, const endpoint& e2) BOOST_ASIO_NOEXCEPT
{
return e1.address() == e2.address() && e1.port() == e2.port();
}
bool operator<(const endpoint& e1, const endpoint& e2)
bool operator<(const endpoint& e1, const endpoint& e2) BOOST_ASIO_NOEXCEPT
{
if (e1.address() < e2.address())
return true;
@@ -178,18 +177,14 @@ bool operator<(const endpoint& e1, const endpoint& e2)
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
std::string endpoint::to_string(boost::system::error_code& ec) const
std::string endpoint::to_string() const
{
std::string a = address().to_string(ec);
if (ec)
return std::string();
std::ostringstream tmp_os;
tmp_os.imbue(std::locale::classic());
if (is_v4())
tmp_os << a;
tmp_os << address();
else
tmp_os << '[' << a << ']';
tmp_os << '[' << address() << ']';
tmp_os << ':' << port();
return tmp_os.str();

View File

@@ -2,7 +2,7 @@
// detail/socket_option.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -392,15 +392,15 @@ public:
}
// Construct with multicast address only.
explicit multicast_request(const boost::asio::ip::address& multicast_address)
explicit multicast_request(const address& multicast_address)
: ipv4_value_(), // Zero-initialisation gives the "any" address.
ipv6_value_() // Zero-initialisation gives the "any" address.
{
if (multicast_address.is_v6())
{
using namespace std; // For memcpy.
boost::asio::ip::address_v6 ipv6_address = multicast_address.to_v6();
boost::asio::ip::address_v6::bytes_type bytes = ipv6_address.to_bytes();
address_v6 ipv6_address = multicast_address.to_v6();
address_v6::bytes_type bytes = ipv6_address.to_bytes();
memcpy(ipv6_value_.ipv6mr_multiaddr.s6_addr, bytes.data(), 16);
ipv6_value_.ipv6mr_interface = ipv6_address.scope_id();
}
@@ -408,37 +408,34 @@ public:
{
ipv4_value_.imr_multiaddr.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
multicast_address.to_v4().to_ulong());
multicast_address.to_v4().to_uint());
ipv4_value_.imr_interface.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
boost::asio::ip::address_v4::any().to_ulong());
address_v4::any().to_uint());
}
}
// Construct with multicast address and IPv4 address specifying an interface.
explicit multicast_request(
const boost::asio::ip::address_v4& multicast_address,
const boost::asio::ip::address_v4& network_interface
= boost::asio::ip::address_v4::any())
explicit multicast_request(const address_v4& multicast_address,
const address_v4& network_interface = address_v4::any())
: ipv6_value_() // Zero-initialisation gives the "any" address.
{
ipv4_value_.imr_multiaddr.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
multicast_address.to_ulong());
multicast_address.to_uint());
ipv4_value_.imr_interface.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
network_interface.to_ulong());
network_interface.to_uint());
}
// Construct with multicast address and IPv6 network interface index.
explicit multicast_request(
const boost::asio::ip::address_v6& multicast_address,
const address_v6& multicast_address,
unsigned long network_interface = 0)
: ipv4_value_() // Zero-initialisation gives the "any" address.
{
using namespace std; // For memcpy.
boost::asio::ip::address_v6::bytes_type bytes =
multicast_address.to_bytes();
address_v6::bytes_type bytes = multicast_address.to_bytes();
memcpy(ipv6_value_.ipv6mr_multiaddr.s6_addr, bytes.data(), 16);
if (network_interface)
ipv6_value_.ipv6mr_interface = network_interface;
@@ -497,16 +494,16 @@ public:
{
ipv4_value_.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
boost::asio::ip::address_v4::any().to_ulong());
address_v4::any().to_uint());
ipv6_value_ = 0;
}
// Construct with IPv4 interface.
explicit network_interface(const boost::asio::ip::address_v4& ipv4_interface)
explicit network_interface(const address_v4& ipv4_interface)
{
ipv4_value_.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
ipv4_interface.to_ulong());
ipv4_interface.to_uint());
ipv6_value_ = 0;
}
@@ -515,7 +512,7 @@ public:
{
ipv4_value_.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
boost::asio::ip::address_v4::any().to_ulong());
address_v4::any().to_uint());
ipv6_value_ = ipv6_interface;
}

View File

@@ -2,7 +2,7 @@
// ip/host_name.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -2,7 +2,7 @@
// ip/icmp.hpp
// ~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -2,7 +2,7 @@
// ip/impl/address.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -25,23 +25,37 @@ namespace boost {
namespace asio {
namespace ip {
#if !defined(BOOST_ASIO_NO_DEPRECATED)
inline address address::from_string(const char* str)
{
return boost::asio::ip::make_address(str);
}
inline address address::from_string(
const char* str, boost::system::error_code& ec)
{
return boost::asio::ip::make_address(str, ec);
}
inline address address::from_string(const std::string& str)
{
return boost::asio::ip::make_address(str);
}
inline address address::from_string(
const std::string& str, boost::system::error_code& ec)
{
return boost::asio::ip::make_address(str, ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const address& addr)
{
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::basic_ostream<Elem, Traits>::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);
return os;
return os << addr.to_string().c_str();
}
} // namespace ip

View File

@@ -2,7 +2,7 @@
// ip/impl/address.ipp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -21,6 +21,7 @@
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/bad_address_cast.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -29,28 +30,30 @@ namespace boost {
namespace asio {
namespace ip {
address::address()
address::address() BOOST_ASIO_NOEXCEPT
: type_(ipv4),
ipv4_address_(),
ipv6_address_()
{
}
address::address(const boost::asio::ip::address_v4& ipv4_address)
address::address(
const boost::asio::ip::address_v4& ipv4_address) BOOST_ASIO_NOEXCEPT
: type_(ipv4),
ipv4_address_(ipv4_address),
ipv6_address_()
{
}
address::address(const boost::asio::ip::address_v6& ipv6_address)
address::address(
const boost::asio::ip::address_v6& ipv6_address) BOOST_ASIO_NOEXCEPT
: type_(ipv6),
ipv4_address_(),
ipv6_address_(ipv6_address)
{
}
address::address(const address& other)
address::address(const address& other) BOOST_ASIO_NOEXCEPT
: type_(other.type_),
ipv4_address_(other.ipv4_address_),
ipv6_address_(other.ipv6_address_)
@@ -58,7 +61,7 @@ address::address(const address& other)
}
#if defined(BOOST_ASIO_HAS_MOVE)
address::address(address&& other)
address::address(address&& other) BOOST_ASIO_NOEXCEPT
: type_(other.type_),
ipv4_address_(other.ipv4_address_),
ipv6_address_(other.ipv6_address_)
@@ -66,7 +69,7 @@ address::address(address&& other)
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
address& address::operator=(const address& other)
address& address::operator=(const address& other) BOOST_ASIO_NOEXCEPT
{
type_ = other.type_;
ipv4_address_ = other.ipv4_address_;
@@ -75,7 +78,7 @@ address& address::operator=(const address& other)
}
#if defined(BOOST_ASIO_HAS_MOVE)
address& address::operator=(address&& other)
address& address::operator=(address&& other) BOOST_ASIO_NOEXCEPT
{
type_ = other.type_;
ipv4_address_ = other.ipv4_address_;
@@ -84,7 +87,8 @@ address& address::operator=(address&& other)
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
address& address::operator=(const boost::asio::ip::address_v4& ipv4_address)
address& address::operator=(
const boost::asio::ip::address_v4& ipv4_address) BOOST_ASIO_NOEXCEPT
{
type_ = ipv4;
ipv4_address_ = ipv4_address;
@@ -92,7 +96,8 @@ address& address::operator=(const boost::asio::ip::address_v4& ipv4_address)
return *this;
}
address& address::operator=(const boost::asio::ip::address_v6& ipv6_address)
address& address::operator=(
const boost::asio::ip::address_v6& ipv6_address) BOOST_ASIO_NOEXCEPT
{
type_ = ipv6;
ipv4_address_ = boost::asio::ip::address_v4();
@@ -100,11 +105,61 @@ address& address::operator=(const boost::asio::ip::address_v6& ipv6_address)
return *this;
}
address make_address(const char* str)
{
boost::system::error_code ec;
address addr = make_address(str, ec);
boost::asio::detail::throw_error(ec);
return addr;
}
address make_address(const char* str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
boost::asio::ip::address_v6 ipv6_address =
boost::asio::ip::make_address_v6(str, ec);
if (!ec)
return address(ipv6_address);
boost::asio::ip::address_v4 ipv4_address =
boost::asio::ip::make_address_v4(str, ec);
if (!ec)
return address(ipv4_address);
return address();
}
address make_address(const std::string& str)
{
return make_address(str.c_str());
}
address make_address(const std::string& str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
return make_address(str.c_str(), ec);
}
#if defined(BOOST_ASIO_HAS_STRING_VIEW)
address make_address(string_view str)
{
return make_address(static_cast<std::string>(str));
}
address make_address(string_view str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
return make_address(static_cast<std::string>(str), ec);
}
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
boost::asio::ip::address_v4 address::to_v4() const
{
if (type_ != ipv4)
{
std::bad_cast ex;
bad_address_cast ex;
boost::asio::detail::throw_exception(ex);
}
return ipv4_address_;
@@ -114,7 +169,7 @@ boost::asio::ip::address_v6 address::to_v6() const
{
if (type_ != ipv6)
{
std::bad_cast ex;
bad_address_cast ex;
boost::asio::detail::throw_exception(ex);
}
return ipv6_address_;
@@ -127,79 +182,37 @@ std::string address::to_string() const
return ipv4_address_.to_string();
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
std::string address::to_string(boost::system::error_code& ec) const
{
if (type_ == ipv6)
return ipv6_address_.to_string(ec);
return ipv4_address_.to_string(ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address address::from_string(const char* str)
{
boost::system::error_code ec;
address addr = from_string(str, ec);
boost::asio::detail::throw_error(ec);
return addr;
}
address address::from_string(const char* str, boost::system::error_code& ec)
{
boost::asio::ip::address_v6 ipv6_address =
boost::asio::ip::address_v6::from_string(str, ec);
if (!ec)
{
address tmp;
tmp.type_ = ipv6;
tmp.ipv6_address_ = ipv6_address;
return tmp;
}
boost::asio::ip::address_v4 ipv4_address =
boost::asio::ip::address_v4::from_string(str, ec);
if (!ec)
{
address tmp;
tmp.type_ = ipv4;
tmp.ipv4_address_ = ipv4_address;
return tmp;
}
return address();
}
address address::from_string(const std::string& str)
{
return from_string(str.c_str());
}
address address::from_string(const std::string& str,
boost::system::error_code& ec)
{
return from_string(str.c_str(), ec);
}
bool address::is_loopback() const
bool address::is_loopback() const BOOST_ASIO_NOEXCEPT
{
return (type_ == ipv4)
? ipv4_address_.is_loopback()
: ipv6_address_.is_loopback();
}
bool address::is_unspecified() const
bool address::is_unspecified() const BOOST_ASIO_NOEXCEPT
{
return (type_ == ipv4)
? ipv4_address_.is_unspecified()
: ipv6_address_.is_unspecified();
}
bool address::is_multicast() const
bool address::is_multicast() const BOOST_ASIO_NOEXCEPT
{
return (type_ == ipv4)
? ipv4_address_.is_multicast()
: ipv6_address_.is_multicast();
}
bool operator==(const address& a1, const address& a2)
bool operator==(const address& a1, const address& a2) BOOST_ASIO_NOEXCEPT
{
if (a1.type_ != a2.type_)
return false;
@@ -208,7 +221,7 @@ bool operator==(const address& a1, const address& a2)
return a1.ipv4_address_ == a2.ipv4_address_;
}
bool operator<(const address& a1, const address& a2)
bool operator<(const address& a1, const address& a2) BOOST_ASIO_NOEXCEPT
{
if (a1.type_ < a2.type_)
return true;

View File

@@ -2,7 +2,7 @@
// ip/impl/address_v4.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -25,23 +25,37 @@ namespace boost {
namespace asio {
namespace ip {
#if !defined(BOOST_ASIO_NO_DEPRECATED)
inline address_v4 address_v4::from_string(const char* str)
{
return boost::asio::ip::make_address_v4(str);
}
inline address_v4 address_v4::from_string(
const char* str, boost::system::error_code& ec)
{
return boost::asio::ip::make_address_v4(str, ec);
}
inline address_v4 address_v4::from_string(const std::string& str)
{
return boost::asio::ip::make_address_v4(str);
}
inline address_v4 address_v4::from_string(
const std::string& str, boost::system::error_code& ec)
{
return boost::asio::ip::make_address_v4(str, ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const address_v4& addr)
{
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::basic_ostream<Elem, Traits>::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);
return os;
return os << addr.to_string().c_str();
}
} // namespace ip

View File

@@ -2,7 +2,7 @@
// ip/impl/address_v4.ipp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,6 +17,7 @@
#include <boost/asio/detail/config.hpp>
#include <climits>
#include <limits>
#include <stdexcept>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/socket_ops.hpp>
@@ -45,21 +46,19 @@ address_v4::address_v4(const address_v4::bytes_type& bytes)
memcpy(&addr_.s_addr, bytes.data(), 4);
}
address_v4::address_v4(unsigned long addr)
address_v4::address_v4(address_v4::uint_type addr)
{
#if ULONG_MAX > 0xFFFFFFFF
if (addr > 0xFFFFFFFF)
if ((std::numeric_limits<uint_type>::max)() > 0xFFFFFFFF)
{
std::out_of_range ex("address_v4 from unsigned long");
std::out_of_range ex("address_v4 from unsigned integer");
boost::asio::detail::throw_exception(ex);
}
#endif // ULONG_MAX > 0xFFFFFFFF
addr_.s_addr = boost::asio::detail::socket_ops::host_to_network_long(
static_cast<boost::asio::detail::u_long_type>(addr));
}
address_v4::bytes_type address_v4::to_bytes() const
address_v4::bytes_type address_v4::to_bytes() const BOOST_ASIO_NOEXCEPT
{
using namespace std; // For memcpy.
bytes_type bytes;
@@ -71,19 +70,32 @@ address_v4::bytes_type address_v4::to_bytes() const
return bytes;
}
unsigned long address_v4::to_ulong() const
address_v4::uint_type address_v4::to_uint() const BOOST_ASIO_NOEXCEPT
{
return boost::asio::detail::socket_ops::network_to_host_long(addr_.s_addr);
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
unsigned long address_v4::to_ulong() const
{
return boost::asio::detail::socket_ops::network_to_host_long(addr_.s_addr);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
std::string address_v4::to_string() const
{
boost::system::error_code ec;
std::string addr = to_string(ec);
boost::asio::detail::throw_error(ec);
char addr_str[boost::asio::detail::max_addr_v4_str_len];
const char* addr =
boost::asio::detail::socket_ops::inet_ntop(
BOOST_ASIO_OS_DEF(AF_INET), &addr_, addr_str,
boost::asio::detail::max_addr_v4_str_len, 0, ec);
if (addr == 0)
boost::asio::detail::throw_error(ec);
return addr;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
std::string address_v4::to_string(boost::system::error_code& ec) const
{
char addr_str[boost::asio::detail::max_addr_v4_str_len];
@@ -95,69 +107,44 @@ std::string address_v4::to_string(boost::system::error_code& ec) const
return std::string();
return addr;
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 address_v4::from_string(const char* str)
bool address_v4::is_loopback() const BOOST_ASIO_NOEXCEPT
{
boost::system::error_code ec;
address_v4 addr = from_string(str, ec);
boost::asio::detail::throw_error(ec);
return addr;
return (to_uint() & 0xFF000000) == 0x7F000000;
}
address_v4 address_v4::from_string(
const char* str, boost::system::error_code& ec)
bool address_v4::is_unspecified() const BOOST_ASIO_NOEXCEPT
{
address_v4 tmp;
if (boost::asio::detail::socket_ops::inet_pton(
BOOST_ASIO_OS_DEF(AF_INET), str, &tmp.addr_, 0, ec) <= 0)
return address_v4();
return tmp;
}
address_v4 address_v4::from_string(const std::string& str)
{
return from_string(str.c_str());
}
address_v4 address_v4::from_string(
const std::string& str, boost::system::error_code& ec)
{
return from_string(str.c_str(), ec);
}
bool address_v4::is_loopback() const
{
return (to_ulong() & 0xFF000000) == 0x7F000000;
}
bool address_v4::is_unspecified() const
{
return to_ulong() == 0;
return to_uint() == 0;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
bool address_v4::is_class_a() const
{
return (to_ulong() & 0x80000000) == 0;
return (to_uint() & 0x80000000) == 0;
}
bool address_v4::is_class_b() const
{
return (to_ulong() & 0xC0000000) == 0x80000000;
return (to_uint() & 0xC0000000) == 0x80000000;
}
bool address_v4::is_class_c() const
{
return (to_ulong() & 0xE0000000) == 0xC0000000;
return (to_uint() & 0xE0000000) == 0xC0000000;
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
bool address_v4::is_multicast() const
bool address_v4::is_multicast() const BOOST_ASIO_NOEXCEPT
{
return (to_ulong() & 0xF0000000) == 0xE0000000;
return (to_uint() & 0xF0000000) == 0xE0000000;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 address_v4::broadcast(const address_v4& addr, const address_v4& mask)
{
return address_v4(addr.to_ulong() | (mask.to_ulong() ^ 0xFFFFFFFF));
return address_v4(addr.to_uint() | (mask.to_uint() ^ 0xFFFFFFFF));
}
address_v4 address_v4::netmask(const address_v4& addr)
@@ -170,6 +157,51 @@ address_v4 address_v4::netmask(const address_v4& addr)
return address_v4(0xFFFFFF00);
return address_v4(0xFFFFFFFF);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v4 make_address_v4(const char* str)
{
boost::system::error_code ec;
address_v4 addr = make_address_v4(str, ec);
boost::asio::detail::throw_error(ec);
return addr;
}
address_v4 make_address_v4(const char* str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
address_v4::bytes_type bytes;
if (boost::asio::detail::socket_ops::inet_pton(
BOOST_ASIO_OS_DEF(AF_INET), str, &bytes, 0, ec) <= 0)
return address_v4();
return address_v4(bytes);
}
address_v4 make_address_v4(const std::string& str)
{
return make_address_v4(str.c_str());
}
address_v4 make_address_v4(const std::string& str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
return make_address_v4(str.c_str(), ec);
}
#if defined(BOOST_ASIO_HAS_STRING_VIEW)
address_v4 make_address_v4(string_view str)
{
return make_address_v4(static_cast<std::string>(str));
}
address_v4 make_address_v4(string_view str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
return make_address_v4(static_cast<std::string>(str), ec);
}
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
} // namespace ip
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ip/impl/address_v6.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -25,23 +25,37 @@ namespace boost {
namespace asio {
namespace ip {
#if !defined(BOOST_ASIO_NO_DEPRECATED)
inline address_v6 address_v6::from_string(const char* str)
{
return boost::asio::ip::make_address_v6(str);
}
inline address_v6 address_v6::from_string(
const char* str, boost::system::error_code& ec)
{
return boost::asio::ip::make_address_v6(str, ec);
}
inline address_v6 address_v6::from_string(const std::string& str)
{
return boost::asio::ip::make_address_v6(str);
}
inline address_v6 address_v6::from_string(
const std::string& str, boost::system::error_code& ec)
{
return boost::asio::ip::make_address_v6(str, ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const address_v6& addr)
{
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::basic_ostream<Elem, Traits>::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);
return os;
return os << addr.to_string().c_str();
}
} // namespace ip

View File

@@ -2,7 +2,7 @@
// ip/impl/address_v6.ipp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -24,6 +24,7 @@
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/ip/address_v6.hpp>
#include <boost/asio/ip/bad_address_cast.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -31,7 +32,7 @@ namespace boost {
namespace asio {
namespace ip {
address_v6::address_v6()
address_v6::address_v6() BOOST_ASIO_NOEXCEPT
: addr_(),
scope_id_(0)
{
@@ -56,21 +57,21 @@ address_v6::address_v6(const address_v6::bytes_type& bytes,
memcpy(addr_.s6_addr, bytes.data(), 16);
}
address_v6::address_v6(const address_v6& other)
address_v6::address_v6(const address_v6& other) BOOST_ASIO_NOEXCEPT
: addr_(other.addr_),
scope_id_(other.scope_id_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
address_v6::address_v6(address_v6&& other)
address_v6::address_v6(address_v6&& other) BOOST_ASIO_NOEXCEPT
: addr_(other.addr_),
scope_id_(other.scope_id_)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
address_v6& address_v6::operator=(const address_v6& other)
address_v6& address_v6::operator=(const address_v6& other) BOOST_ASIO_NOEXCEPT
{
addr_ = other.addr_;
scope_id_ = other.scope_id_;
@@ -78,7 +79,7 @@ address_v6& address_v6::operator=(const address_v6& other)
}
#if defined(BOOST_ASIO_HAS_MOVE)
address_v6& address_v6::operator=(address_v6&& other)
address_v6& address_v6::operator=(address_v6&& other) BOOST_ASIO_NOEXCEPT
{
addr_ = other.addr_;
scope_id_ = other.scope_id_;
@@ -86,7 +87,7 @@ address_v6& address_v6::operator=(address_v6&& other)
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
address_v6::bytes_type address_v6::to_bytes() const
address_v6::bytes_type address_v6::to_bytes() const BOOST_ASIO_NOEXCEPT
{
using namespace std; // For memcpy.
bytes_type bytes;
@@ -101,11 +102,17 @@ address_v6::bytes_type address_v6::to_bytes() const
std::string address_v6::to_string() const
{
boost::system::error_code ec;
std::string addr = to_string(ec);
boost::asio::detail::throw_error(ec);
char addr_str[boost::asio::detail::max_addr_v6_str_len];
const char* addr =
boost::asio::detail::socket_ops::inet_ntop(
BOOST_ASIO_OS_DEF(AF_INET6), &addr_, addr_str,
boost::asio::detail::max_addr_v6_str_len, scope_id_, ec);
if (addr == 0)
boost::asio::detail::throw_error(ec);
return addr;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
std::string address_v6::to_string(boost::system::error_code& ec) const
{
char addr_str[boost::asio::detail::max_addr_v6_str_len];
@@ -118,40 +125,11 @@ std::string address_v6::to_string(boost::system::error_code& ec) const
return addr;
}
address_v6 address_v6::from_string(const char* str)
{
boost::system::error_code ec;
address_v6 addr = from_string(str, ec);
boost::asio::detail::throw_error(ec);
return addr;
}
address_v6 address_v6::from_string(
const char* str, boost::system::error_code& ec)
{
address_v6 tmp;
if (boost::asio::detail::socket_ops::inet_pton(
BOOST_ASIO_OS_DEF(AF_INET6), str, &tmp.addr_, &tmp.scope_id_, ec) <= 0)
return address_v6();
return tmp;
}
address_v6 address_v6::from_string(const std::string& str)
{
return from_string(str.c_str());
}
address_v6 address_v6::from_string(
const std::string& str, boost::system::error_code& ec)
{
return from_string(str.c_str(), ec);
}
address_v4 address_v6::to_v4() const
{
if (!is_v4_mapped() && !is_v4_compatible())
{
std::bad_cast ex;
bad_address_cast ex;
boost::asio::detail::throw_exception(ex);
}
@@ -159,8 +137,9 @@ address_v4 address_v6::to_v4() const
addr_.s6_addr[13], addr_.s6_addr[14], addr_.s6_addr[15] } };
return address_v4(v4_bytes);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
bool address_v6::is_loopback() const
bool address_v6::is_loopback() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0) && (addr_.s6_addr[1] == 0)
&& (addr_.s6_addr[2] == 0) && (addr_.s6_addr[3] == 0)
@@ -172,7 +151,7 @@ bool address_v6::is_loopback() const
&& (addr_.s6_addr[14] == 0) && (addr_.s6_addr[15] == 1));
}
bool address_v6::is_unspecified() const
bool address_v6::is_unspecified() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0) && (addr_.s6_addr[1] == 0)
&& (addr_.s6_addr[2] == 0) && (addr_.s6_addr[3] == 0)
@@ -184,17 +163,17 @@ bool address_v6::is_unspecified() const
&& (addr_.s6_addr[14] == 0) && (addr_.s6_addr[15] == 0));
}
bool address_v6::is_link_local() const
bool address_v6::is_link_local() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xfe) && ((addr_.s6_addr[1] & 0xc0) == 0x80));
}
bool address_v6::is_site_local() const
bool address_v6::is_site_local() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xfe) && ((addr_.s6_addr[1] & 0xc0) == 0xc0));
}
bool address_v6::is_v4_mapped() const
bool address_v6::is_v4_mapped() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0) && (addr_.s6_addr[1] == 0)
&& (addr_.s6_addr[2] == 0) && (addr_.s6_addr[3] == 0)
@@ -204,6 +183,7 @@ bool address_v6::is_v4_mapped() const
&& (addr_.s6_addr[10] == 0xff) && (addr_.s6_addr[11] == 0xff));
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
bool address_v6::is_v4_compatible() const
{
return ((addr_.s6_addr[0] == 0) && (addr_.s6_addr[1] == 0)
@@ -217,38 +197,39 @@ bool address_v6::is_v4_compatible() const
&& (addr_.s6_addr[14] == 0)
&& ((addr_.s6_addr[15] == 0) || (addr_.s6_addr[15] == 1))));
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
bool address_v6::is_multicast() const
bool address_v6::is_multicast() const BOOST_ASIO_NOEXCEPT
{
return (addr_.s6_addr[0] == 0xff);
}
bool address_v6::is_multicast_global() const
bool address_v6::is_multicast_global() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xff) && ((addr_.s6_addr[1] & 0x0f) == 0x0e));
}
bool address_v6::is_multicast_link_local() const
bool address_v6::is_multicast_link_local() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xff) && ((addr_.s6_addr[1] & 0x0f) == 0x02));
}
bool address_v6::is_multicast_node_local() const
bool address_v6::is_multicast_node_local() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xff) && ((addr_.s6_addr[1] & 0x0f) == 0x01));
}
bool address_v6::is_multicast_org_local() const
bool address_v6::is_multicast_org_local() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xff) && ((addr_.s6_addr[1] & 0x0f) == 0x08));
}
bool address_v6::is_multicast_site_local() const
bool address_v6::is_multicast_site_local() const BOOST_ASIO_NOEXCEPT
{
return ((addr_.s6_addr[0] == 0xff) && ((addr_.s6_addr[1] & 0x0f) == 0x05));
}
bool operator==(const address_v6& a1, const address_v6& a2)
bool operator==(const address_v6& a1, const address_v6& a2) BOOST_ASIO_NOEXCEPT
{
using namespace std; // For memcmp.
return memcmp(&a1.addr_, &a2.addr_,
@@ -256,7 +237,7 @@ bool operator==(const address_v6& a1, const address_v6& a2)
&& a1.scope_id_ == a2.scope_id_;
}
bool operator<(const address_v6& a1, const address_v6& a2)
bool operator<(const address_v6& a1, const address_v6& a2) BOOST_ASIO_NOEXCEPT
{
using namespace std; // For memcmp.
int memcmp_result = memcmp(&a1.addr_, &a2.addr_,
@@ -268,13 +249,14 @@ bool operator<(const address_v6& a1, const address_v6& a2)
return a1.scope_id_ < a2.scope_id_;
}
address_v6 address_v6::loopback()
address_v6 address_v6::loopback() BOOST_ASIO_NOEXCEPT
{
address_v6 tmp;
tmp.addr_.s6_addr[15] = 1;
return tmp;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
address_v6 address_v6::v4_mapped(const address_v4& addr)
{
address_v4::bytes_type v4_bytes = addr.to_bytes();
@@ -290,6 +272,76 @@ address_v6 address_v6::v4_compatible(const address_v4& addr)
v4_bytes[0], v4_bytes[1], v4_bytes[2], v4_bytes[3] } };
return address_v6(v6_bytes);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
address_v6 make_address_v6(const char* str)
{
boost::system::error_code ec;
address_v6 addr = make_address_v6(str, ec);
boost::asio::detail::throw_error(ec);
return addr;
}
address_v6 make_address_v6(const char* str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
address_v6::bytes_type bytes;
unsigned long scope_id = 0;
if (boost::asio::detail::socket_ops::inet_pton(
BOOST_ASIO_OS_DEF(AF_INET6), str, &bytes[0], &scope_id, ec) <= 0)
return address_v6();
return address_v6(bytes, scope_id);
}
address_v6 make_address_v6(const std::string& str)
{
return make_address_v6(str.c_str());
}
address_v6 make_address_v6(const std::string& str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
return make_address_v6(str.c_str(), ec);
}
#if defined(BOOST_ASIO_HAS_STRING_VIEW)
address_v6 make_address_v6(string_view str)
{
return make_address_v6(static_cast<std::string>(str));
}
address_v6 make_address_v6(string_view str,
boost::system::error_code& ec) BOOST_ASIO_NOEXCEPT
{
return make_address_v6(static_cast<std::string>(str), ec);
}
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
address_v4 make_address_v4(
v4_mapped_t, const address_v6& v6_addr)
{
if (!v6_addr.is_v4_mapped())
{
bad_address_cast ex;
boost::asio::detail::throw_exception(ex);
}
address_v6::bytes_type v6_bytes = v6_addr.to_bytes();
address_v4::bytes_type v4_bytes = { { v6_bytes[12],
v6_bytes[13], v6_bytes[14], v6_bytes[15] } };
return address_v4(v4_bytes);
}
address_v6 make_address_v6(
v4_mapped_t, const address_v4& v4_addr)
{
address_v4::bytes_type v4_bytes = v4_addr.to_bytes();
address_v6::bytes_type v6_bytes = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0xFF, 0xFF, v4_bytes[0], v4_bytes[1], v4_bytes[2], v4_bytes[3] } };
return address_v6(v6_bytes);
}
} // namespace ip
} // namespace asio

View File

@@ -2,7 +2,7 @@
// ip/impl/basic_endpoint.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -31,19 +31,7 @@ std::basic_ostream<Elem, Traits>& operator<<(
const basic_endpoint<InternetProtocol>& endpoint)
{
boost::asio::ip::detail::endpoint tmp_ep(endpoint.address(), endpoint.port());
boost::system::error_code ec;
std::string s = tmp_ep.to_string(ec);
if (ec)
{
if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::basic_ostream<Elem, Traits>::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);
return os;
return os << tmp_ep.to_string().c_str();
}
} // namespace ip

View File

@@ -2,7 +2,7 @@
// ip/impl/host_name.ipp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -0,0 +1,56 @@
//
// ip/impl/network_v4.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_IMPL_NETWORK_V4_HPP
#define BOOST_ASIO_IP_IMPL_NETWORK_V4_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const network_v4& addr)
{
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::basic_ostream<Elem, Traits>::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);
return os;
}
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // BOOST_ASIO_IP_IMPL_NETWORK_V4_HPP

View File

@@ -0,0 +1,218 @@
//
// ip/impl/network_v4.ipp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_IMPL_NETWORK_V4_IPP
#define BOOST_ASIO_IP_IMPL_NETWORK_V4_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdexcept>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/ip/network_v4.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
network_v4::network_v4(const address_v4& addr, unsigned short prefix_len)
: address_(addr),
prefix_length_(prefix_len)
{
if (prefix_len > 32)
{
std::out_of_range ex("prefix length too large");
boost::asio::detail::throw_exception(ex);
}
}
network_v4::network_v4(const address_v4& addr, const address_v4& mask)
: address_(addr),
prefix_length_(0)
{
address_v4::bytes_type mask_bytes = mask.to_bytes();
bool finished = false;
for (std::size_t i = 0; i < mask_bytes.size(); ++i)
{
if (finished)
{
if (mask_bytes[i])
{
std::invalid_argument ex("non-contiguous netmask");
boost::asio::detail::throw_exception(ex);
}
continue;
}
else
{
switch (mask_bytes[i])
{
case 255:
prefix_length_ += 8;
break;
case 254: // prefix_length_ += 7
prefix_length_ += 1;
case 252: // prefix_length_ += 6
prefix_length_ += 1;
case 248: // prefix_length_ += 5
prefix_length_ += 1;
case 240: // prefix_length_ += 4
prefix_length_ += 1;
case 224: // prefix_length_ += 3
prefix_length_ += 1;
case 192: // prefix_length_ += 2
prefix_length_ += 1;
case 128: // prefix_length_ += 1
prefix_length_ += 1;
case 0: // nbits += 0
finished = true;
break;
default:
std::out_of_range ex("non-contiguous netmask");
boost::asio::detail::throw_exception(ex);
}
}
}
}
address_v4 network_v4::netmask() const BOOST_ASIO_NOEXCEPT
{
uint32_t nmbits = 0xffffffff;
if (prefix_length_ == 0)
nmbits = 0;
else
nmbits = nmbits << (32 - prefix_length_);
return address_v4(nmbits);
}
address_v4_range network_v4::hosts() const BOOST_ASIO_NOEXCEPT
{
return is_host()
? address_v4_range(address_, address_v4(address_.to_uint() + 1))
: address_v4_range(address_v4(network().to_uint() + 1), broadcast());
}
bool network_v4::is_subnet_of(const network_v4& other) const
{
if (other.prefix_length_ >= prefix_length_)
return false; // Only real subsets are allowed.
const network_v4 me(address_, other.prefix_length_);
return other.canonical() == me.canonical();
}
std::string network_v4::to_string() const
{
boost::system::error_code ec;
std::string addr = to_string(ec);
boost::asio::detail::throw_error(ec);
return addr;
}
std::string network_v4::to_string(boost::system::error_code& ec) const
{
using namespace std; // For sprintf.
ec = boost::system::error_code();
char prefix_len[16];
#if defined(BOOST_ASIO_HAS_SECURE_RTL)
sprintf_s(prefix_len, sizeof(prefix_len), "/%u", prefix_length_);
#else // defined(BOOST_ASIO_HAS_SECURE_RTL)
sprintf(prefix_len, "/%u", prefix_length_);
#endif // defined(BOOST_ASIO_HAS_SECURE_RTL)
return address_.to_string() + prefix_len;
}
network_v4 make_network_v4(const char* str)
{
return make_network_v4(std::string(str));
}
network_v4 make_network_v4(const char* str, boost::system::error_code& ec)
{
return make_network_v4(std::string(str), ec);
}
network_v4 make_network_v4(const std::string& str)
{
boost::system::error_code ec;
network_v4 net = make_network_v4(str, ec);
boost::asio::detail::throw_error(ec);
return net;
}
network_v4 make_network_v4(const std::string& str,
boost::system::error_code& ec)
{
std::string::size_type pos = str.find_first_of("/");
if (pos == std::string::npos)
{
ec = boost::asio::error::invalid_argument;
return network_v4();
}
if (pos == str.size() - 1)
{
ec = boost::asio::error::invalid_argument;
return network_v4();
}
std::string::size_type end = str.find_first_not_of("0123456789", pos + 1);
if (end != std::string::npos)
{
ec = boost::asio::error::invalid_argument;
return network_v4();
}
const address_v4 addr = make_address_v4(str.substr(0, pos), ec);
if (ec)
return network_v4();
const int prefix_len = std::atoi(str.substr(pos + 1).c_str());
if (prefix_len < 0 || prefix_len > 32)
{
ec = boost::asio::error::invalid_argument;
return network_v4();
}
return network_v4(addr, static_cast<unsigned short>(prefix_len));
}
#if defined(BOOST_ASIO_HAS_STRING_VIEW)
network_v4 make_network_v4(string_view str)
{
return make_network_v4(static_cast<std::string>(str));
}
network_v4 make_network_v4(string_view str,
boost::system::error_code& ec)
{
return make_network_v4(static_cast<std::string>(str), ec);
}
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_IMPL_NETWORK_V4_IPP

View File

@@ -0,0 +1,55 @@
//
// ip/impl/network_v6.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_IMPL_NETWORK_V6_HPP
#define BOOST_ASIO_IP_IMPL_NETWORK_V6_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const network_v6& addr)
{
boost::system::error_code ec;
std::string s = addr.to_string(ec);
if (ec)
{
if (os.exceptions() & std::basic_ostream<Elem, Traits>::failbit)
boost::asio::detail::throw_error(ec);
else
os.setstate(std::basic_ostream<Elem, Traits>::failbit);
}
else
for (std::string::iterator i = s.begin(); i != s.end(); ++i)
os << os.widen(*i);
return os;
}
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // BOOST_ASIO_IP_IMPL_NETWORK_V6_HPP

View File

@@ -0,0 +1,187 @@
//
// ip/impl/network_v6.ipp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_IMPL_NETWORK_V6_IPP
#define BOOST_ASIO_IP_IMPL_NETWORK_V6_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdexcept>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/ip/network_v6.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
network_v6::network_v6(const address_v6& addr, unsigned short prefix_len)
: address_(addr),
prefix_length_(prefix_len)
{
if (prefix_len > 128)
{
std::out_of_range ex("prefix length too large");
boost::asio::detail::throw_exception(ex);
}
}
BOOST_ASIO_DECL address_v6 network_v6::network() const BOOST_ASIO_NOEXCEPT
{
address_v6::bytes_type bytes(address_.to_bytes());
for (std::size_t i = 0; i < 16; ++i)
{
if (prefix_length_ <= i * 8)
bytes[i] = 0;
else if (prefix_length_ < (i + 1) * 8)
bytes[i] &= 0xFF00 >> (prefix_length_ % 8);
}
return address_v6(bytes, address_.scope_id());
}
address_v6_range network_v6::hosts() const BOOST_ASIO_NOEXCEPT
{
address_v6::bytes_type begin_bytes(address_.to_bytes());
address_v6::bytes_type end_bytes(address_.to_bytes());
for (std::size_t i = 0; i < 16; ++i)
{
if (prefix_length_ <= i * 8)
{
begin_bytes[i] = 0;
end_bytes[i] = 0xFF;
}
else if (prefix_length_ < (i + 1) * 8)
{
begin_bytes[i] &= 0xFF00 >> (prefix_length_ % 8);
end_bytes[i] |= 0xFF >> (prefix_length_ % 8);
}
}
return address_v6_range(
address_v6_iterator(address_v6(begin_bytes, address_.scope_id())),
++address_v6_iterator(address_v6(end_bytes, address_.scope_id())));
}
bool network_v6::is_subnet_of(const network_v6& other) const
{
if (other.prefix_length_ >= prefix_length_)
return false; // Only real subsets are allowed.
const network_v6 me(address_, other.prefix_length_);
return other.canonical() == me.canonical();
}
std::string network_v6::to_string() const
{
boost::system::error_code ec;
std::string addr = to_string(ec);
boost::asio::detail::throw_error(ec);
return addr;
}
std::string network_v6::to_string(boost::system::error_code& ec) const
{
using namespace std; // For sprintf.
ec = boost::system::error_code();
char prefix_len[16];
#if defined(BOOST_ASIO_HAS_SECURE_RTL)
sprintf_s(prefix_len, sizeof(prefix_len), "/%u", prefix_length_);
#else // defined(BOOST_ASIO_HAS_SECURE_RTL)
sprintf(prefix_len, "/%u", prefix_length_);
#endif // defined(BOOST_ASIO_HAS_SECURE_RTL)
return address_.to_string() + prefix_len;
}
network_v6 make_network_v6(const char* str)
{
return make_network_v6(std::string(str));
}
network_v6 make_network_v6(const char* str, boost::system::error_code& ec)
{
return make_network_v6(std::string(str), ec);
}
network_v6 make_network_v6(const std::string& str)
{
boost::system::error_code ec;
network_v6 net = make_network_v6(str, ec);
boost::asio::detail::throw_error(ec);
return net;
}
network_v6 make_network_v6(const std::string& str,
boost::system::error_code& ec)
{
std::string::size_type pos = str.find_first_of("/");
if (pos == std::string::npos)
{
ec = boost::asio::error::invalid_argument;
return network_v6();
}
if (pos == str.size() - 1)
{
ec = boost::asio::error::invalid_argument;
return network_v6();
}
std::string::size_type end = str.find_first_not_of("0123456789", pos + 1);
if (end != std::string::npos)
{
ec = boost::asio::error::invalid_argument;
return network_v6();
}
const address_v6 addr = make_address_v6(str.substr(0, pos), ec);
if (ec)
return network_v6();
const int prefix_len = std::atoi(str.substr(pos + 1).c_str());
if (prefix_len < 0 || prefix_len > 128)
{
ec = boost::asio::error::invalid_argument;
return network_v6();
}
return network_v6(addr, static_cast<unsigned short>(prefix_len));
}
#if defined(BOOST_ASIO_HAS_STRING_VIEW)
network_v6 make_network_v6(string_view str)
{
return make_network_v6(static_cast<std::string>(str));
}
network_v6 make_network_v6(string_view str,
boost::system::error_code& ec)
{
return make_network_v6(static_cast<std::string>(str), ec);
}
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_IMPL_NETWORK_V6_IPP

View File

@@ -2,7 +2,7 @@
// ip/multicast.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -33,7 +33,7 @@ namespace multicast {
* @par Examples
* Setting the option to join a multicast group:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::address multicast_address =
* boost::asio::ip::address::from_string("225.0.0.1");
@@ -61,7 +61,7 @@ typedef boost::asio::ip::detail::socket_option::multicast_request<
* @par Examples
* Setting the option to leave a multicast group:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::address multicast_address =
* boost::asio::ip::address::from_string("225.0.0.1");
@@ -89,7 +89,7 @@ typedef boost::asio::ip::detail::socket_option::multicast_request<
* @par Examples
* Setting the option:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::address_v4 local_interface =
* boost::asio::ip::address_v4::from_string("1.2.3.4");
@@ -117,7 +117,7 @@ typedef boost::asio::ip::detail::socket_option::network_interface<
* @par Examples
* Setting the option:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::multicast::hops option(4);
* socket.set_option(option);
@@ -126,7 +126,7 @@ typedef boost::asio::ip::detail::socket_option::network_interface<
* @par
* Getting the current option value:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::multicast::hops option;
* socket.get_option(option);
@@ -154,7 +154,7 @@ typedef boost::asio::ip::detail::socket_option::multicast_hops<
* @par Examples
* Setting the option:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::multicast::enable_loopback option(true);
* socket.set_option(option);
@@ -163,7 +163,7 @@ typedef boost::asio::ip::detail::socket_option::multicast_hops<
* @par
* Getting the current option value:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::multicast::enable_loopback option;
* socket.get_option(option);

View File

@@ -0,0 +1,263 @@
//
// ip/network_v4.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_NETWORK_V4_HPP
#define BOOST_ASIO_IP_NETWORK_V4_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/detail/string_view.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/ip/address_v4_range.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
/// Represents an IPv4 network.
/**
* The boost::asio::ip::network_v4 class provides the ability to use and
* manipulate IP version 4 networks.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
class network_v4
{
public:
/// Default constructor.
network_v4() BOOST_ASIO_NOEXCEPT
: address_(),
prefix_length_(0)
{
}
/// Construct a network based on the specified address and prefix length.
BOOST_ASIO_DECL network_v4(const address_v4& addr,
unsigned short prefix_len);
/// Construct network based on the specified address and netmask.
BOOST_ASIO_DECL network_v4(const address_v4& addr,
const address_v4& mask);
/// Copy constructor.
network_v4(const network_v4& other) BOOST_ASIO_NOEXCEPT
: address_(other.address_),
prefix_length_(other.prefix_length_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
network_v4(network_v4&& other) BOOST_ASIO_NOEXCEPT
: address_(BOOST_ASIO_MOVE_CAST(address_v4)(other.address_)),
prefix_length_(other.prefix_length_)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assign from another network.
network_v4& operator=(const network_v4& other) BOOST_ASIO_NOEXCEPT
{
address_ = other.address_;
prefix_length_ = other.prefix_length_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move-assign from another network.
network_v4& operator=(network_v4&& other) BOOST_ASIO_NOEXCEPT
{
address_ = BOOST_ASIO_MOVE_CAST(address_v4)(other.address_);
prefix_length_ = other.prefix_length_;
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Obtain the address object specified when the network object was created.
address_v4 address() const BOOST_ASIO_NOEXCEPT
{
return address_;
}
/// Obtain the prefix length that was specified when the network object was
/// created.
unsigned short prefix_length() const BOOST_ASIO_NOEXCEPT
{
return prefix_length_;
}
/// Obtain the netmask that was specified when the network object was created.
BOOST_ASIO_DECL address_v4 netmask() const BOOST_ASIO_NOEXCEPT;
/// Obtain an address object that represents the network address.
address_v4 network() const BOOST_ASIO_NOEXCEPT
{
return address_v4(address_.to_uint() & netmask().to_uint());
}
/// Obtain an address object that represents the network's broadcast address.
address_v4 broadcast() const BOOST_ASIO_NOEXCEPT
{
return address_v4(network().to_uint() | (netmask().to_uint() ^ 0xFFFFFFFF));
}
/// Obtain an address range corresponding to the hosts in the network.
BOOST_ASIO_DECL address_v4_range hosts() const BOOST_ASIO_NOEXCEPT;
/// Obtain the true network address, omitting any host bits.
network_v4 canonical() const BOOST_ASIO_NOEXCEPT
{
return network_v4(network(), netmask());
}
/// Test if network is a valid host address.
bool is_host() const BOOST_ASIO_NOEXCEPT
{
return prefix_length_ == 32;
}
/// Test if a network is a real subnet of another network.
BOOST_ASIO_DECL bool is_subnet_of(const network_v4& other) const;
/// Get the network as an address in dotted decimal format.
BOOST_ASIO_DECL std::string to_string() const;
/// Get the network as an address in dotted decimal format.
BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
/// Compare two networks for equality.
friend bool operator==(const network_v4& a, const network_v4& b)
{
return a.address_ == b.address_ && a.prefix_length_ == b.prefix_length_;
}
/// Compare two networks for inequality.
friend bool operator!=(const network_v4& a, const network_v4& b)
{
return !(a == b);
}
private:
address_v4 address_;
unsigned short prefix_length_;
};
/// Create an IPv4 network from an address and prefix length.
/**
* @relates address_v4
*/
inline network_v4 make_network_v4(
const address_v4& addr, unsigned short prefix_len)
{
return network_v4(addr, prefix_len);
}
/// Create an IPv4 network from an address and netmask.
/**
* @relates address_v4
*/
inline network_v4 make_network_v4(
const address_v4& addr, const address_v4& mask)
{
return network_v4(addr, mask);
}
/// Create an IPv4 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v4
*/
BOOST_ASIO_DECL network_v4 make_network_v4(const char* str);
/// Create an IPv4 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v4
*/
BOOST_ASIO_DECL network_v4 make_network_v4(
const char* str, boost::system::error_code& ec);
/// Create an IPv4 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v4
*/
BOOST_ASIO_DECL network_v4 make_network_v4(const std::string& str);
/// Create an IPv4 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v4
*/
BOOST_ASIO_DECL network_v4 make_network_v4(
const std::string& str, boost::system::error_code& ec);
#if defined(BOOST_ASIO_HAS_STRING_VIEW) \
|| defined(GENERATING_DOCUMENTATION)
/// Create an IPv4 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v4
*/
BOOST_ASIO_DECL network_v4 make_network_v4(string_view str);
/// Create an IPv4 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v4
*/
BOOST_ASIO_DECL network_v4 make_network_v4(
string_view str, boost::system::error_code& ec);
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
// || defined(GENERATING_DOCUMENTATION)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// Output a network as a string.
/**
* Used to output a human-readable string for a specified network.
*
* @param os The output stream to which the string will be written.
*
* @param net The network to be written.
*
* @return The output stream.
*
* @relates boost::asio::ip::address_v4
*/
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const network_v4& net);
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/ip/impl/network_v4.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ip/impl/network_v4.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_IP_NETWORK_V4_HPP

View File

@@ -0,0 +1,237 @@
//
// ip/network_v6.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_NETWORK_V6_HPP
#define BOOST_ASIO_IP_NETWORK_V6_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/detail/string_view.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/ip/address_v6_range.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
/// Represents an IPv6 network.
/**
* The boost::asio::ip::network_v6 class provides the ability to use and
* manipulate IP version 6 networks.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
class network_v6
{
public:
/// Default constructor.
network_v6() BOOST_ASIO_NOEXCEPT
: address_(),
prefix_length_(0)
{
}
/// Construct a network based on the specified address and prefix length.
BOOST_ASIO_DECL network_v6(const address_v6& addr,
unsigned short prefix_len);
/// Copy constructor.
network_v6(const network_v6& other) BOOST_ASIO_NOEXCEPT
: address_(other.address_),
prefix_length_(other.prefix_length_)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move constructor.
network_v6(network_v6&& other) BOOST_ASIO_NOEXCEPT
: address_(BOOST_ASIO_MOVE_CAST(address_v6)(other.address_)),
prefix_length_(other.prefix_length_)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Assign from another network.
network_v6& operator=(const network_v6& other) BOOST_ASIO_NOEXCEPT
{
address_ = other.address_;
prefix_length_ = other.prefix_length_;
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
/// Move-assign from another network.
network_v6& operator=(network_v6&& other) BOOST_ASIO_NOEXCEPT
{
address_ = BOOST_ASIO_MOVE_CAST(address_v6)(other.address_);
prefix_length_ = other.prefix_length_;
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
/// Obtain the address object specified when the network object was created.
address_v6 address() const BOOST_ASIO_NOEXCEPT
{
return address_;
}
/// Obtain the prefix length that was specified when the network object was
/// created.
unsigned short prefix_length() const BOOST_ASIO_NOEXCEPT
{
return prefix_length_;
}
/// Obtain an address object that represents the network address.
BOOST_ASIO_DECL address_v6 network() const BOOST_ASIO_NOEXCEPT;
/// Obtain an address range corresponding to the hosts in the network.
BOOST_ASIO_DECL address_v6_range hosts() const BOOST_ASIO_NOEXCEPT;
/// Obtain the true network address, omitting any host bits.
network_v6 canonical() const BOOST_ASIO_NOEXCEPT
{
return network_v6(network(), prefix_length());
}
/// Test if network is a valid host address.
bool is_host() const BOOST_ASIO_NOEXCEPT
{
return prefix_length_ == 128;
}
/// Test if a network is a real subnet of another network.
BOOST_ASIO_DECL bool is_subnet_of(const network_v6& other) const;
/// Get the network as an address in dotted decimal format.
BOOST_ASIO_DECL std::string to_string() const;
/// Get the network as an address in dotted decimal format.
BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
/// Compare two networks for equality.
friend bool operator==(const network_v6& a, const network_v6& b)
{
return a.address_ == b.address_ && a.prefix_length_ == b.prefix_length_;
}
/// Compare two networks for inequality.
friend bool operator!=(const network_v6& a, const network_v6& b)
{
return !(a == b);
}
private:
address_v6 address_;
unsigned short prefix_length_;
};
/// Create an IPv6 network from an address and prefix length.
/**
* @relates address_v6
*/
inline network_v6 make_network_v6(
const address_v6& addr, unsigned short prefix_len)
{
return network_v6(addr, prefix_len);
}
/// Create an IPv6 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v6
*/
BOOST_ASIO_DECL network_v6 make_network_v6(const char* str);
/// Create an IPv6 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v6
*/
BOOST_ASIO_DECL network_v6 make_network_v6(
const char* str, boost::system::error_code& ec);
/// Create an IPv6 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v6
*/
BOOST_ASIO_DECL network_v6 make_network_v6(const std::string& str);
/// Create an IPv6 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v6
*/
BOOST_ASIO_DECL network_v6 make_network_v6(
const std::string& str, boost::system::error_code& ec);
#if defined(BOOST_ASIO_HAS_STRING_VIEW) \
|| defined(GENERATING_DOCUMENTATION)
/// Create an IPv6 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v6
*/
BOOST_ASIO_DECL network_v6 make_network_v6(string_view str);
/// Create an IPv6 network from a string containing IP address and prefix
/// length.
/**
* @relates network_v6
*/
BOOST_ASIO_DECL network_v6 make_network_v6(
string_view str, boost::system::error_code& ec);
#endif // defined(BOOST_ASIO_HAS_STRING_VIEW)
// || defined(GENERATING_DOCUMENTATION)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// Output a network as a string.
/**
* Used to output a human-readable string for a specified network.
*
* @param os The output stream to which the string will be written.
*
* @param net The network to be written.
*
* @return The output stream.
*
* @relates boost::asio::ip::address_v6
*/
template <typename Elem, typename Traits>
std::basic_ostream<Elem, Traits>& operator<<(
std::basic_ostream<Elem, Traits>& os, const network_v6& net);
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/ip/impl/network_v6.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ip/impl/network_v6.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_IP_NETWORK_V6_HPP

View File

@@ -0,0 +1,131 @@
//
// ip/resolver_base.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_RESOLVER_BASE_HPP
#define BOOST_ASIO_IP_RESOLVER_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
/// The resolver_base class is used as a base for the basic_resolver class
/// templates to provide a common place to define the flag constants.
class resolver_base
{
public:
#if defined(GENERATING_DOCUMENTATION)
/// A bitmask type (C++ Std [lib.bitmask.types]).
typedef unspecified flags;
/// Determine the canonical name of the host specified in the query.
static const flags canonical_name = implementation_defined;
/// Indicate that returned endpoint is intended for use as a locally bound
/// socket endpoint.
static const flags passive = implementation_defined;
/// Host name should be treated as a numeric string defining an IPv4 or IPv6
/// address and no name resolution should be attempted.
static const flags numeric_host = implementation_defined;
/// Service name should be treated as a numeric string defining a port number
/// and no name resolution should be attempted.
static const flags numeric_service = implementation_defined;
/// If the query protocol family is specified as IPv6, return IPv4-mapped
/// IPv6 addresses on finding no IPv6 addresses.
static const flags v4_mapped = implementation_defined;
/// If used with v4_mapped, return all matching IPv6 and IPv4 addresses.
static const flags all_matching = implementation_defined;
/// 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.
static const flags address_configured = implementation_defined;
#else
enum flags
{
canonical_name = BOOST_ASIO_OS_DEF(AI_CANONNAME),
passive = BOOST_ASIO_OS_DEF(AI_PASSIVE),
numeric_host = BOOST_ASIO_OS_DEF(AI_NUMERICHOST),
numeric_service = BOOST_ASIO_OS_DEF(AI_NUMERICSERV),
v4_mapped = BOOST_ASIO_OS_DEF(AI_V4MAPPED),
all_matching = BOOST_ASIO_OS_DEF(AI_ALL),
address_configured = BOOST_ASIO_OS_DEF(AI_ADDRCONFIG)
};
// Implement bitmask operations as shown in C++ Std [lib.bitmask.types].
friend flags operator&(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
}
friend flags operator|(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
}
friend flags operator^(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
}
friend flags operator~(flags x)
{
return static_cast<flags>(~static_cast<unsigned int>(x));
}
friend flags& operator&=(flags& x, flags y)
{
x = x & y;
return x;
}
friend flags& operator|=(flags& x, flags y)
{
x = x | y;
return x;
}
friend flags& operator^=(flags& x, flags y)
{
x = x ^ y;
return x;
}
#endif
protected:
/// Protected destructor to prevent deletion through this type.
~resolver_base()
{
}
};
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_RESOLVER_BASE_HPP

View File

@@ -2,7 +2,7 @@
// ip/resolver_query_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -16,7 +16,7 @@
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/ip/resolver_base.hpp>
#include <boost/asio/detail/push_options.hpp>
@@ -27,95 +27,8 @@ namespace ip {
/// The resolver_query_base class is used as a base for the
/// basic_resolver_query class templates to provide a common place to define
/// the flag constants.
class resolver_query_base
class resolver_query_base : public resolver_base
{
public:
#if defined(GENERATING_DOCUMENTATION)
/// A bitmask type (C++ Std [lib.bitmask.types]).
typedef unspecified flags;
/// Determine the canonical name of the host specified in the query.
static const flags canonical_name = implementation_defined;
/// Indicate that returned endpoint is intended for use as a locally bound
/// socket endpoint.
static const flags passive = implementation_defined;
/// Host name should be treated as a numeric string defining an IPv4 or IPv6
/// address and no name resolution should be attempted.
static const flags numeric_host = implementation_defined;
/// Service name should be treated as a numeric string defining a port number
/// and no name resolution should be attempted.
static const flags numeric_service = implementation_defined;
/// If the query protocol family is specified as IPv6, return IPv4-mapped
/// IPv6 addresses on finding no IPv6 addresses.
static const flags v4_mapped = implementation_defined;
/// If used with v4_mapped, return all matching IPv6 and IPv4 addresses.
static const flags all_matching = implementation_defined;
/// 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.
static const flags address_configured = implementation_defined;
#else
enum flags
{
canonical_name = BOOST_ASIO_OS_DEF(AI_CANONNAME),
passive = BOOST_ASIO_OS_DEF(AI_PASSIVE),
numeric_host = BOOST_ASIO_OS_DEF(AI_NUMERICHOST),
numeric_service = BOOST_ASIO_OS_DEF(AI_NUMERICSERV),
v4_mapped = BOOST_ASIO_OS_DEF(AI_V4MAPPED),
all_matching = BOOST_ASIO_OS_DEF(AI_ALL),
address_configured = BOOST_ASIO_OS_DEF(AI_ADDRCONFIG)
};
// Implement bitmask operations as shown in C++ Std [lib.bitmask.types].
friend flags operator&(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
}
friend flags operator|(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
}
friend flags operator^(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
}
friend flags operator~(flags x)
{
return static_cast<flags>(~static_cast<unsigned int>(x));
}
friend flags& operator&=(flags& x, flags y)
{
x = x & y;
return x;
}
friend flags& operator|=(flags& x, flags y)
{
x = x | y;
return x;
}
friend flags& operator^=(flags& x, flags y)
{
x = x ^ y;
return x;
}
#endif
protected:
/// Protected destructor to prevent deletion through this type.
~resolver_query_base()

View File

@@ -1,178 +0,0 @@
//
// ip/resolver_service.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_IP_RESOLVER_SERVICE_HPP
#define BOOST_ASIO_IP_RESOLVER_SERVICE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/basic_resolver_iterator.hpp>
#include <boost/asio/ip/basic_resolver_query.hpp>
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
# include <boost/asio/detail/winrt_resolver_service.hpp>
#else
# include <boost/asio/detail/resolver_service.hpp>
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ip {
/// Default service implementation for a resolver.
template <typename InternetProtocol>
class resolver_service
#if defined(GENERATING_DOCUMENTATION)
: public boost::asio::io_service::service
#else
: public boost::asio::detail::service_base<
resolver_service<InternetProtocol> >
#endif
{
public:
#if defined(GENERATING_DOCUMENTATION)
/// The unique service identifier.
static boost::asio::io_service::id id;
#endif
/// The protocol type.
typedef InternetProtocol protocol_type;
/// The endpoint type.
typedef typename InternetProtocol::endpoint endpoint_type;
/// The query type.
typedef basic_resolver_query<InternetProtocol> query_type;
/// The iterator type.
typedef basic_resolver_iterator<InternetProtocol> iterator_type;
private:
// The type of the platform-specific implementation.
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
typedef boost::asio::detail::winrt_resolver_service<InternetProtocol>
service_impl_type;
#else
typedef boost::asio::detail::resolver_service<InternetProtocol>
service_impl_type;
#endif
public:
/// The type of a resolver implementation.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined implementation_type;
#else
typedef typename service_impl_type::implementation_type implementation_type;
#endif
/// Construct a new resolver service for the specified io_service.
explicit resolver_service(boost::asio::io_service& io_service)
: boost::asio::detail::service_base<
resolver_service<InternetProtocol> >(io_service),
service_impl_(io_service)
{
}
/// Construct a new resolver implementation.
void construct(implementation_type& impl)
{
service_impl_.construct(impl);
}
/// Destroy a resolver implementation.
void destroy(implementation_type& impl)
{
service_impl_.destroy(impl);
}
/// Cancel pending asynchronous operations.
void cancel(implementation_type& impl)
{
service_impl_.cancel(impl);
}
/// Resolve a query to a list of entries.
iterator_type resolve(implementation_type& impl, const query_type& query,
boost::system::error_code& ec)
{
return service_impl_.resolve(impl, query, ec);
}
/// Asynchronously resolve a query to a list of entries.
template <typename ResolveHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
void (boost::system::error_code, iterator_type))
async_resolve(implementation_type& impl, const query_type& query,
BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
{
boost::asio::detail::async_result_init<
ResolveHandler, void (boost::system::error_code, iterator_type)> init(
BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
service_impl_.async_resolve(impl, query, init.handler);
return init.result.get();
}
/// Resolve an endpoint to a list of entries.
iterator_type resolve(implementation_type& impl,
const endpoint_type& endpoint, boost::system::error_code& ec)
{
return service_impl_.resolve(impl, endpoint, ec);
}
/// Asynchronously resolve an endpoint to a list of entries.
template <typename ResolveHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
void (boost::system::error_code, iterator_type))
async_resolve(implementation_type& impl, const endpoint_type& endpoint,
BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
{
boost::asio::detail::async_result_init<
ResolveHandler, void (boost::system::error_code, iterator_type)> init(
BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
service_impl_.async_resolve(impl, endpoint, init.handler);
return init.result.get();
}
private:
// Destroy all user-defined handler objects owned by the service.
void shutdown_service()
{
service_impl_.shutdown_service();
}
// Perform any fork-related housekeeping.
void fork_service(boost::asio::io_service::fork_event event)
{
service_impl_.fork_service(event);
}
// The platform-specific implementation.
service_impl_type service_impl_;
};
} // namespace ip
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP

View File

@@ -2,7 +2,7 @@
// ip/tcp.hpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -100,7 +100,7 @@ public:
* @par Examples
* Setting the option:
* @code
* boost::asio::ip::tcp::socket socket(io_service);
* boost::asio::ip::tcp::socket socket(my_context);
* ...
* boost::asio::ip::tcp::no_delay option(true);
* socket.set_option(option);
@@ -109,7 +109,7 @@ public:
* @par
* Getting the current option value:
* @code
* boost::asio::ip::tcp::socket socket(io_service);
* boost::asio::ip::tcp::socket socket(my_context);
* ...
* boost::asio::ip::tcp::no_delay option;
* socket.get_option(option);

View File

@@ -2,7 +2,7 @@
// ip/udp.hpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -2,7 +2,7 @@
// ip/unicast.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -33,7 +33,7 @@ namespace unicast {
* @par Examples
* Setting the option:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::unicast::hops option(4);
* socket.set_option(option);
@@ -42,7 +42,7 @@ namespace unicast {
* @par
* Getting the current option value:
* @code
* boost::asio::ip::udp::socket socket(io_service);
* boost::asio::ip::udp::socket socket(my_context);
* ...
* boost::asio::ip::unicast::hops option;
* socket.get_option(option);

View File

@@ -2,7 +2,7 @@
// ip/v6_only.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -32,7 +32,7 @@ namespace ip {
* @par Examples
* Setting the option:
* @code
* boost::asio::ip::tcp::socket socket(io_service);
* boost::asio::ip::tcp::socket socket(my_context);
* ...
* boost::asio::ip::v6_only option(true);
* socket.set_option(option);
@@ -41,7 +41,7 @@ namespace ip {
* @par
* Getting the current option value:
* @code
* boost::asio::ip::tcp::socket socket(io_service);
* boost::asio::ip::tcp::socket socket(my_context);
* ...
* boost::asio::ip::v6_only option;
* socket.get_option(option);