aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_define.h6
-rw-r--r--src/include/ndpi_main.h9
-rw-r--r--src/include/ndpi_typedefs.h19
-rw-r--r--src/include/ndpi_win32.h2
-rw-r--r--src/lib/ndpi_main.c16
-rw-r--r--src/lib/protocols/dns.c10
-rw-r--r--src/lib/protocols/kakaotalk_voice.c2
7 files changed, 50 insertions, 14 deletions
diff --git a/src/include/ndpi_define.h b/src/include/ndpi_define.h
index 82a0ee739..a181d7e5e 100644
--- a/src/include/ndpi_define.h
+++ b/src/include/ndpi_define.h
@@ -54,8 +54,10 @@
#endif
#ifdef WIN32
+#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1
#endif
+#endif
#if !(defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__))
#if defined(__mips__)
@@ -286,4 +288,8 @@
/* define memory callback function */
#define match_first_bytes(payload,st) (memcmp((payload),(st),(sizeof(st)-1))==0)
+#ifdef WIN32
+#define snprintf(buf,len, format,...) _snprintf_s(buf, len,len, format, __VA_ARGS__)
+#endif
+
#endif /* __NDPI_DEFINE_INCLUDE_FILE__ */
diff --git a/src/include/ndpi_main.h b/src/include/ndpi_main.h
index 608f410ae..d5c15c7e4 100644
--- a/src/include/ndpi_main.h
+++ b/src/include/ndpi_main.h
@@ -34,12 +34,15 @@
#endif
#include <ctype.h>
#include <time.h>
-#include <arpa/inet.h>
-#ifndef WIN32
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#else
+#include <arpa/inet.h>
#include <sys/time.h>
-
+#include <sys/socket.h>
#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
#include <endian.h>
#include <byteswap.h>
diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h
index f7ce65288..c06d627f7 100644
--- a/src/include/ndpi_typedefs.h
+++ b/src/include/ndpi_typedefs.h
@@ -56,6 +56,18 @@ typedef struct node_t
struct node_t *left, *right;
} ndpi_node;
+#ifdef WIN32
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int uint;
+typedef unsigned long u_long;
+typedef u_char u_int8_t;
+typedef u_short u_int16_t;
+typedef uint u_int32_t;
+typedef uint u_int;
+typedef unsigned __int64 u_int64_t;
+#endif
+
/* NDPI_MASK_SIZE */
typedef u_int32_t ndpi_ndpi_mask;
@@ -93,7 +105,7 @@ struct ndpi_chdlc
u_int8_t addr; /* 0x0F (Unicast) - 0x8F (Broadcast) */
u_int8_t ctrl; /* always 0x00 */
u_int16_t proto_code; /* protocol type (e.g. 0x0800 IP) */
-} PACK_OFF;
+}; PACK_OFF
/* SLARP - Serial Line ARP http://tinyurl.com/qa54e95 */
PACK_ON
@@ -269,6 +281,11 @@ struct ndpi_udphdr
u_int16_t check;
} PACK_OFF;
+PACK_ON
+struct ndpi_dns_packet_header {
+ u_int16_t transaction_id, flags, num_queries, answer_rrs, authority_rrs, additional_rrs;
+} PACK_OFF;
+
typedef union
{
u_int32_t ipv4;
diff --git a/src/include/ndpi_win32.h b/src/include/ndpi_win32.h
index 3b568beb9..f653caa51 100644
--- a/src/include/ndpi_win32.h
+++ b/src/include/ndpi_win32.h
@@ -62,7 +62,7 @@ typedef unsigned __int64 u_int64_t;
#define pthread_rwlock_unlock pthread_mutex_unlock
#define pthread_rwlock_destroy pthread_mutex_destroy
-#define gmtime_r(a, b) gmtime(a) /* Already thread safe on windows */
+#define gmtime_r(a, b) memcpy(b, gmtime(a), sizeof(struct tm))
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index bdcac35e0..51a2c66b0 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -1833,6 +1833,22 @@ u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi
/* ******************************************************************** */
+#ifdef WIN32
+char * strsep(char **sp, char *sep)
+{
+ char *p, *s;
+ if (sp == NULL || *sp == NULL || **sp == '\0') return(NULL);
+ s = *sp;
+ p = s + strcspn(s, sep);
+ if (*p != '\0') *p++ = '\0';
+ *sp = p;
+ return(s);
+}
+#endif
+
+/* ******************************************************************** */
+
+
int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule, u_int8_t do_add) {
char *at, *proto, *elem;
ndpi_proto_defaults_t *def;
diff --git a/src/lib/protocols/dns.c b/src/lib/protocols/dns.c
index a1f813603..3b4322823 100644
--- a/src/lib/protocols/dns.c
+++ b/src/lib/protocols/dns.c
@@ -85,10 +85,6 @@ static u_int16_t get16(int *i, const u_int8_t *payload) {
/* *********************************************** */
-struct dns_packet_header {
- u_int16_t transaction_id, flags, num_queries, answer_rrs, authority_rrs, additional_rrs;
-} __attribute__((packed));
-
void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
@@ -107,9 +103,9 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
}
if(((dport == 53) || (sport == 53) || (dport == 5355))
- && (packet->payload_packet_len > sizeof(struct dns_packet_header))) {
+ && (packet->payload_packet_len > sizeof(struct ndpi_dns_packet_header))) {
int i = packet->tcp ? 2 : 0;
- struct dns_packet_header header, *dns = (struct dns_packet_header*)&packet->payload[i];
+ struct ndpi_dns_packet_header header, *dns = (struct ndpi_dns_packet_header*)&packet->payload[i];
u_int8_t is_query, ret_code, is_dns = 0;
u_int32_t a_record[NDPI_MAX_DNS_REQUESTS] = { 0 }, query_offset, num_a_records = 0;
@@ -121,7 +117,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
header.additional_rrs = ntohs(dns->additional_rrs);
is_query = (header.flags & 0x8000) ? 0 : 1;
ret_code = is_query ? 0 : (header.flags & 0x0F);
- i += sizeof(struct dns_packet_header);
+ i += sizeof(struct ndpi_dns_packet_header);
query_offset = i;
if(is_query) {
diff --git a/src/lib/protocols/kakaotalk_voice.c b/src/lib/protocols/kakaotalk_voice.c
index daa97cc36..c6972c7a1 100644
--- a/src/lib/protocols/kakaotalk_voice.c
+++ b/src/lib/protocols/kakaotalk_voice.c
@@ -30,8 +30,6 @@
#ifdef NDPI_SERVICE_KAKAOTALK_VOICE
void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
- unsigned char *vers;
- int ver_offs;
if(packet->iph
&& packet->udp