Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

#75 Fixed Ip range issue

Sourav Kalalb68cea4cecce
diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.c
index 676f6ab..7a21d5d 100644
--- a/Windows/src/ProxyBridge.c
+++ b/Windows/src/ProxyBridge.c
@@ -826,6 +826,40 @@ static BOOL match_ip_pattern(const char *pattern, UINT32 ip)
if (pattern == NULL || strcmp(pattern, "*") == 0)
return TRUE;
+ // check for IP range
+ char *dash = strchr(pattern, '-');
+ if (dash != NULL)
+ {
+ char start_ip_str[64], end_ip_str[64];
+ size_t start_len = dash - pattern;
+ if (start_len >= sizeof(start_ip_str))
+ return FALSE;
+
+ strncpy_s(start_ip_str, sizeof(start_ip_str), pattern, start_len);
+ start_ip_str[start_len] = '\0';
+ strncpy_s(end_ip_str, sizeof(end_ip_str), dash + 1, _TRUNCATE);
+
+ // parse start and end IPs
+ UINT32 start_ip = 0, end_ip = 0;
+ int s1, s2, s3, s4, e1, e2, e3, e4;
+
+ if (sscanf_s(start_ip_str, "%d.%d.%d.%d", &s1, &s2, &s3, &s4) == 4 &&
+ sscanf_s(end_ip_str, "%d.%d.%d.%d", &e1, &e2, &e3, &e4) == 4)
+ {
+ start_ip = (s1 << 0) | (s2 << 8) | (s3 << 16) | (s4 << 24);
+ end_ip = (e1 << 0) | (e2 << 8) | (e3 << 16) | (e4 << 24);
+
+ // checking as network byte order would be wrong, compare as little-endian UINT32
+ // change to big-endian for proper comparison
+ UINT32 ip_be = ((ip & 0xFF) << 24) | ((ip & 0xFF00) << 8) | ((ip & 0xFF0000) >> 8) | ((ip & 0xFF000000) >> 24);
+ UINT32 start_be = ((start_ip & 0xFF) << 24) | ((start_ip & 0xFF00) << 8) | ((start_ip & 0xFF0000) >> 8) | ((start_ip & 0xFF000000) >> 24);
+ UINT32 end_be = ((end_ip & 0xFF) << 24) | ((end_ip & 0xFF00) << 8) | ((end_ip & 0xFF0000) >> 8) | ((end_ip & 0xFF000000) >> 24);
+
+ return (ip_be >= start_be && ip_be <= end_be);
+ }
+ return FALSE;
+ }
+
// Extract 4 octets from IP (little-endian)
unsigned char ip_octets[4];
ip_octets[0] = (ip >> 0) & 0xFF;