blob: a0fad75e2170964575aa71a44f58834e9d5403c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
};
}
|