#ifndef NETWORK_IPADDRESS_H_ #define NETWORK_IPADDRESS_H_ #include #include #include #include namespace td { namespace network { /* IPv4 address */ class IPAddress { private: std::uint32_t m_Address; bool m_Valid; public: /* Create an invalid address */ IPAddress() noexcept; /* Initialize by string IP */ IPAddress(const std::string& str); /* Initialize by string IP */ IPAddress(const std::wstring& str); /* Initialize by octets */ IPAddress(std::uint8_t octet1, std::uint8_t octet2, std::uint8_t octet3, std::uint8_t octet4) noexcept; /* Get the specific octet. 1-4 */ std::uint8_t GetOctet(std::uint8_t num) const; /* Set the specific octet. 1-4 */ void SetOctet(std::uint8_t num, std::uint8_t value); /* Make sure the IP is valid. It will be invalid if the host wasn't found. */ bool IsValid() const noexcept { return m_Valid; } std::string ToString() const; static IPAddress LocalAddress(); bool operator==(const IPAddress& right); bool operator!=(const IPAddress& right); bool operator==(bool b); }; typedef std::vector IPAddresses; std::ostream& operator<<(std::ostream& os, const IPAddress& addr); std::wostream& operator<<(std::wostream& os, const IPAddress& addr); } // ns network } // ns td #endif