#pragma once #include #include #include #ifndef WIN32 #include #include #else #include #include #endif namespace sibs { class InvalidAddressException : public std::runtime_error { public: InvalidAddressException(const std::string &errMsg) : std::runtime_error(errMsg) {} }; class Ipv4 { public: Ipv4(); // If @ip is nullptr, then bind to all available sockets (typical for servers) // Throws InvalidAddressException on error. Ipv4(const char *ip, unsigned short port); Ipv4(const Ipv4 &other); Ipv4& operator = (const Ipv4 &other); std::string getAddress() const; unsigned short getPort() const; bool operator == (const Ipv4 &other) const; bool operator != (const Ipv4 &other) const; struct sockaddr_in address; }; struct Ipv4Hasher { size_t operator()(const Ipv4 &address) const { return address.address.sin_addr.s_addr ^ address.address.sin_port; } }; template using Ipv4Map = std::unordered_map; }