Custom rules: fixes for Windows (#2130)
Even after adding `WSAStartup()` call, the behavior with IPv6 addresses was different on Windows; it is the same issue reported on: https://stackoverflow.com/questions/66755681/getaddrinfo-c-on-windows-not-handling-ipv6-correctly-returning-error-code-1 Fix bitmasks.
This commit is contained in:
+13
-1
@@ -2770,7 +2770,7 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
||||
}
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = is_ipv6 ? AF_INET6 : AF_INET;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
|
||||
@@ -2793,6 +2793,7 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
||||
|
||||
memcpy(&pin, &(addr->sin_addr), sizeof(struct in_addr));
|
||||
value_ready = true;
|
||||
bits = 32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2819,6 +2820,7 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
||||
|
||||
memcpy(&pin6, &(addr->sin6_addr), sizeof(struct in6_addr));
|
||||
value_ready = true;
|
||||
bits = 128;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3058,6 +3060,12 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
/* Required to use getaddrinfo on Windows */
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
#endif
|
||||
|
||||
memset(ndpi_str, 0, sizeof(struct ndpi_detection_module_struct));
|
||||
|
||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
@@ -3943,6 +3951,10 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_str) {
|
||||
ndpi_free(ndpi_str->callback_buffer_tcp_payload);
|
||||
ndpi_free(ndpi_str);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
Reference in New Issue
Block a user