프로그래밍/boost

asio.address

MAKGA 2023. 5. 14. 13:52
320x100
class address
{
public:
  ASIO_DECL address() ASIO_NOEXCEPT;
  ASIO_DECL address(const asio::ip::address_v4& ipv4_address) ASIO_NOEXCEPT;
  ASIO_DECL address(const asio::ip::address_v6& ipv6_address) ASIO_NOEXCEPT;
  ASIO_DECL address(const address& other) ASIO_NOEXCEPT;
  ASIO_DECL address(address&& other) ASIO_NOEXCEPT;
  ASIO_DECL address& operator=(const address& other) ASIO_NOEXCEPT;
  ASIO_DECL address& operator=(address&& other) ASIO_NOEXCEPT;
  ASIO_DECL address& operator=(const asio::ip::address_v4& ipv4_address) ASIO_NOEXCEPT;
  ASIO_DECL address& operator=(const asio::ip::address_v6& ipv6_address) ASIO_NOEXCEPT;

  bool is_v4() const ASIO_NOEXCEPT
  {
    return type_ == ipv4;
  }

  bool is_v6() const ASIO_NOEXCEPT
  {
    return type_ == ipv6;
  }

  ASIO_DECL asio::ip::address_v4 to_v4() const;
  ASIO_DECL asio::ip::address_v6 to_v6() const;

  ASIO_DECL std::string to_string() const;
  ASIO_DECL std::string to_string(asio::error_code& ec) const;

  static address from_string(const char* str);
  static address from_string(const char* str, asio::error_code& ec);
  static address from_string(const std::string& str);
  static address from_string(const std::string& str, asio::error_code& ec);

  ASIO_DECL bool is_loopback() const ASIO_NOEXCEPT;
  ASIO_DECL bool is_unspecified() const ASIO_NOEXCEPT;
  ASIO_DECL bool is_multicast() const ASIO_NOEXCEPT;

  ASIO_DECL friend bool operator==(const address& a1, const address& a2) ASIO_NOEXCEPT;
  friend bool operator!=(const address& a1, const address& a2) ASIO_NOEXCEPT
  {
    return !(a1 == a2);
  }

  ASIO_DECL friend bool operator<(const address& a1, const address& a2) ASIO_NOEXCEPT;

  friend bool operator>(const address& a1, const address& a2) ASIO_NOEXCEPT
  {
    return a2 < a1;
  }

  friend bool operator<=(const address& a1, const address& a2) ASIO_NOEXCEPT
  {
    return !(a2 < a1);
  }

  friend bool operator>=(const address& a1, const address& a2) ASIO_NOEXCEPT
  {
    return !(a1 < a2);
  }

private:
  enum { ipv4, ipv6 } type_;
  asio::ip::address_v4 ipv4_address_;
  asio::ip::address_v6 ipv6_address_;
};

 

주소의 정보를 가지고 있으며, ipv4와 ipv6을 구분하는 정보를 추가로 가지고 있다.

address_v4는 in_addr를

address_v6은 in6_addr을 랩핑한 클래스다.

320x100