diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-06-06 20:06:14 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 22:56:48 +0200 |
commit | ed71e8adf36e3d0c3f6f2b54794fe069091d3376 (patch) | |
tree | e42eb457ea930a67d4e7352672e5d68082f3a2b4 /include/sibs/IpAddress.hpp | |
parent | c10dbcb7b59a5187061b1dcd162e8120c89a5973 (diff) |
Add bootstrap class (server)
Diffstat (limited to 'include/sibs/IpAddress.hpp')
-rw-r--r-- | include/sibs/IpAddress.hpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/sibs/IpAddress.hpp b/include/sibs/IpAddress.hpp new file mode 100644 index 0000000..a0fad75 --- /dev/null +++ b/include/sibs/IpAddress.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "../utils.hpp" +#include <stdexcept> +#include <string> +#ifndef WIN32 + #include <arpa/inet.h> + #include <netdb.h> +#else + #include <winsock2.h> + #include <ws2tcpip.h> +#endif + +namespace sibs +{ + class InvalidAddressException : public std::runtime_error + { + public: + InvalidAddressException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + class Ipv4 + { + DISABLE_COPY(Ipv4) + public: + // If @ip is nullptr, then bind to all available sockets (typical for servers) + // Throws InvalidAddressException on error. + Ipv4(const char *ip, unsigned short port); + + std::string getAddress() const; + unsigned short getPort() const; + + struct sockaddr_in address; + }; +} |