38 IPAddress(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
50 std::memcpy(_addr.bytes, octets, 4);
69 std::memcpy(_addr.bytes, octets, 4);
84 uint8_t
operator[](
int i)
const {
return _addr.bytes[i]; }
87 operator uint32_t()
const {
return _addr.dword; }
90 explicit operator bool()
const {
return _addr.dword != 0; }
97 return _addr.dword == other._addr.
dword;
101 return !(*
this == other);
108 return std::memcmp(_addr.bytes, octets, 4) == 0;
114 std::snprintf(buf,
sizeof(buf),
"%u.%u.%u.%u",
115 _addr.bytes[0], _addr.bytes[1],
116 _addr.bytes[2], _addr.bytes[3]);
123 if (!str)
return false;
125 if (std::sscanf(str,
"%u.%u.%u.%u", &a, &b, &c, &d) != 4)
return false;
126 if (a > 255 || b > 255 || c > 255 || d > 255)
return false;
127 _addr.bytes[0] = (uint8_t)a;
128 _addr.bytes[1] = (uint8_t)b;
129 _addr.bytes[2] = (uint8_t)c;
130 _addr.bytes[3] = (uint8_t)d;
135 const uint8_t*
raw()
const {
return _addr.bytes; }
136 uint8_t*
raw() {
return _addr.bytes; }