12 #define bswap_32(x) _byteswap_ulong(x) 13 using in_addr_t = in_addr;
15 #elif defined(__APPLE__) 18 #include <libkern/OSByteOrder.h> 19 #define bswap_32(x) OSSwapInt32(x) 20 #include <arpa/inet.h> 24 #include <arpa/inet.h> 42 IpAddress(uint32_t address_raw) : address_network_order_(address_raw) {}
49 uint32_t tmp = (a << 24) | (b << 16) | (c << 8) | (d);
71 if (inet_pton(AF_INET, ip_str.c_str(), &addr) != 1)
74 address_network_order_ = addr.S_un.S_addr;
76 address_network_order_ = addr;
86 res.resize(INET_ADDRSTRLEN);
87 inet_ntop(AF_INET, &address_network_order_, &res[0], INET_ADDRSTRLEN);
95 return bswap_32(address_network_order_);
102 return address_network_order_;
106 uint32_t address_network_order_{};
uint32_t getBigEndian() const
Returns the IP Address as a big endian (network order) uint32_t.
Definition: ip_address.hpp:101
static IpAddress fromLittleEndian(uint32_t raw)
Creates an IpAddress from a little endian uint32_t.
Definition: ip_address.hpp:56
bool setToString(const std::string &ip_str)
Sets the value of the current IpAddress to the value given in 'ip_str'.
Definition: ip_address.hpp:69
IpAddress(uint32_t address_raw)
Definition: ip_address.hpp:42
std::string toString() const
Returns a string representation of the IP address.
Definition: ip_address.hpp:84
static IpAddress fromBytes(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Creates an IpAddress from individual bytes.
Definition: ip_address.hpp:47
uint32_t getLittleEndian() const
Returns the IP Address as a little endian uint32_t.
Definition: ip_address.hpp:94
A simple wrapper class for IpAddress objects.
Definition: ip_address.hpp:34
IpAddress()=default
Creates IPv4 address 0.0.0.0.