diff --git a/src/AsyncSocket.h b/src/AsyncSocket.h index 12a3212..9ac49c0 100644 --- a/src/AsyncSocket.h +++ b/src/AsyncSocket.h @@ -100,6 +100,10 @@ protected: static thread_local char buf[64]; int ipLength = 0; + if (!binary.length()) { + return {}; + } + unsigned char *b = (unsigned char *) binary.data(); if (binary.length() == 4) { diff --git a/src/ProxyParser.h b/src/ProxyParser.h index 7709973..7bdf744 100644 --- a/src/ProxyParser.h +++ b/src/ProxyParser.h @@ -50,12 +50,20 @@ T _cond_byte_swap(T value) { struct ProxyParser { private: - union proxy_addr addr = {}; + union proxy_addr addr; + + // we should have "unset" where the return value is "" from proxied ip! uint8_t family = 0; public: /* Returns 4 or 16 bytes source address */ std::string_view getSourceAddress() { + + // UNSPEC family and protocol + if (family == 0) { + return {}; + } + if ((family & 0xf0) >> 4 == 1) { /* Family 1 is INET4 */ return {(char *) &addr.ipv4_addr.src_addr, 4};