This commit is contained in:
Luca Deri
2019-09-23 18:04:55 +02:00
parent 3f56b2476a
commit 19dbcaa3a9
4 changed files with 188 additions and 183 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
CC=@CC@ CC=@CC@
CFLAGS=-I. -I../src/include -I./src/lib/third_party/include -shared -Wl, CFLAGS=-I. -I../src/include -I./src/lib/third_party/include -shared -Wl,
LIBNDPI=../src/lib/libndpi.so.@NDPI_VERSION_SHORT@ #LIBNDPI=../src/lib/libndpi.so.@NDPI_VERSION_SHORT@
LIBNDPI=../src/lib/libndpi.a
LDFLAGS=$(CFILE) $(LIBNDPI) -lpcap LDFLAGS=$(CFILE) $(LIBNDPI) -lpcap
SHARE = -soname,ndpi_wrap SHARE = -soname,ndpi_wrap
SO=ndpi_wrap.so SO=ndpi_wrap.so
@@ -17,9 +18,9 @@ endif
all: $(SO) all: $(SO)
$(SO): $(CFILE) $(LIBNDPI) $(SO): $(CFILE) $(LIBNDPI) Makefile
$(CC) $(CFLAGS)$(SHARE) -o $@ $(PIC) $(LDFLAGS) $(CC) $(CFLAGS)$(SHARE) -o $@ $(PIC) $(LDFLAGS)
ln -s $(LIBNDPI) . # ln -s $(LIBNDPI) .
clean: clean:
/bin/rm -f $(SO) /bin/rm -f $(SO)
+1 -1
View File
@@ -166,7 +166,7 @@ def packetcaptured(packet):
#filling pcap_pkthdr #filling pcap_pkthdr
h.len = h.caplen = len(packet) h.len = h.caplen = len(packet)
h.ts.tv_sec = int(packet["IP"].time/1000000) h.ts.tv_sec = int(packet["IP"].time/1000000)
h.ts.tv_usec = round(packet["IP"].time) h.ts.tv_usec = int(packet["IP"].time)
# real work # real work
if int(packet[1].frag) == 0: # not fragmented packet if int(packet[1].frag) == 0: # not fragmented packet
+17 -18
View File
@@ -1,7 +1,7 @@
# #
# ndpi_typestruct.h # ndpi_typestruct.h
# #
# Copyright (C) 2011-18 - ntop.org # Copyright (C) 2019 - ntop.org
# #
# nDPI is free software: you can redistribute it and/or modify # nDPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by # it under the terms of the GNU Lesser General Public License as published by
@@ -21,11 +21,10 @@
import os import os
from ctypes import * from ctypes import *
ndpi = CDLL(os.path.abspath("libndpi.so.2.9.0")) ndpi = CDLL('./ndpi_wrap.so')
ndpi = CDLL(os.path.abspath("ndpi_wrap.so"))
# NDPI_SELECTION_BITMASK_PROTOCOL_SIZE = c_uint32 # NDPI_SELECTION_BITMASK_PROTOCOL_SIZE = c_uint32
# ndpi_protocol_category_t, ndpi_protocol_breed_t e ndpi_log_level_t sono enumeratori e vengono impostati come c_int # ndpi_protocol_category_t, ndpi_protocol_breed_t e ndpi_log_level_t are enum and are imported as c_int
class ndpi_detection_module_struct(Structure): class ndpi_detection_module_struct(Structure):
pass pass
@@ -102,13 +101,13 @@ class ndpi_default_ports_tree_node_t(Structure):
# NDPI_PROTOCOL_BITTORRENT # NDPI_PROTOCOL_BITTORRENT
class spinlock_t(Structure): class spinlock_t(Structure):
_fields_ = [("val", c_int)] #volatile mancante _fields_ = [("val", c_int)] #missing volatile
class atomic_t(Structure): class atomic_t(Structure):
_fields_ = [("counter", c_int)] #volatile mancante _fields_ = [("counter", c_int)] #missing volatile
class time_t(Structure): class time_t(Structure):
_fields_ = [("counter", c_longlong)] #piattaforma dipendente, tuttavia è solo un intero _fields_ = [("counter", c_longlong)] # piattaform dependent
class hash_ip4p_node(Structure): class hash_ip4p_node(Structure):
pass pass
@@ -315,7 +314,7 @@ ndpi_detection_module_struct._fields_ = [
("enable_category_substring_match", c_uint8, 1), # Default is perfect match ("enable_category_substring_match", c_uint8, 1), # Default is perfect match
("hyperscan", c_void_p) # Intel Hyperscan ("hyperscan", c_void_p) # Intel Hyperscan
] ]
class u6_addr(Union): # 128-bit IP6 address class u6_addr(Union): # 128-bit IP6 address
_fields_ = [ _fields_ = [
@@ -333,7 +332,7 @@ class ndpi_ip_addr_t(Union):
('ipv4', c_uint32), ('ipv4', c_uint32),
('ipv4_u_int8_t', c_uint8 * 4), ('ipv4_u_int8_t', c_uint8 * 4),
('ipv6', ndpi_in6_addr), ('ipv6', ndpi_in6_addr),
] ]
class ndpi_id_struct(Structure): class ndpi_id_struct(Structure):
_fields_ = [ _fields_ = [
@@ -370,7 +369,7 @@ class ndpi_id_struct(Structure):
('yahoo_conf_logged_in', c_uint32, 1), ('yahoo_conf_logged_in', c_uint32, 1),
('yahoo_voice_conf_logged_in', c_uint32, 1), ('yahoo_voice_conf_logged_in', c_uint32, 1),
('rtsp_ts_set', c_uint32, 1), ('rtsp_ts_set', c_uint32, 1),
] ]
#struct flow #struct flow
class ndpi_flow_tcp_struct(Structure): class ndpi_flow_tcp_struct(Structure):
@@ -434,7 +433,7 @@ class ndpi_flow_tcp_struct(Structure):
('ppstream_stage', c_uint32, 3), ('ppstream_stage', c_uint32, 3),
('memcached_matches', c_uint8), ('memcached_matches', c_uint8),
('nest_log_sink_matches', c_uint8), ('nest_log_sink_matches', c_uint8),
] ]
class ndpi_flow_udp_struct(Structure): class ndpi_flow_udp_struct(Structure):
_fields_ = [ _fields_ = [
@@ -543,13 +542,13 @@ class tinc_cache_entry(Structure):
('src_address', c_uint32), ('src_address', c_uint32),
('dst_address', c_uint32), ('dst_address', c_uint32),
('dst_port', c_uint16), ('dst_port', c_uint16),
] ]
class struct_ndpi_int_one_line_struct(Structure): class struct_ndpi_int_one_line_struct(Structure):
_fields_ = [ _fields_ = [
('ptr', POINTER(c_uint8)), ('ptr', POINTER(c_uint8)),
('len', c_uint16), ('len', c_uint16),
] ]
class struct_ndpi_iphdr_little_end(Structure): class struct_ndpi_iphdr_little_end(Structure):
_fields_ = [ _fields_ = [
@@ -571,14 +570,14 @@ class struct_ndpi_ip6_hdrctl(Structure):
('ip6_un1_plen', c_uint16), ('ip6_un1_plen', c_uint16),
('ip6_un1_nxt', c_uint8), ('ip6_un1_nxt', c_uint8),
('ip6_un1_hlim', c_uint8), ('ip6_un1_hlim', c_uint8),
] ]
class struct_ndpi_ipv6hdr(Structure): class struct_ndpi_ipv6hdr(Structure):
_fields_ = [ _fields_ = [
('ip6_hdr', struct_ndpi_ip6_hdrctl), ('ip6_hdr', struct_ndpi_ip6_hdrctl),
('ip6_src', ndpi_in6_addr), ('ip6_src', ndpi_in6_addr),
('ip6_dst', ndpi_in6_addr), ('ip6_dst', ndpi_in6_addr),
] ]
class struct_ndpi_tcphdr(Structure): class struct_ndpi_tcphdr(Structure):
_fields_ = [ _fields_ = [
@@ -599,7 +598,7 @@ class struct_ndpi_tcphdr(Structure):
('window', c_uint16), ('window', c_uint16),
('check', c_uint16), ('check', c_uint16),
('urg_ptr', c_uint16), ('urg_ptr', c_uint16),
] ]
class struct_ndpi_udphdr(Structure): class struct_ndpi_udphdr(Structure):
_fields_ = [ _fields_ = [
@@ -607,7 +606,7 @@ class struct_ndpi_udphdr(Structure):
('dest', c_uint16), ('dest', c_uint16),
('len', c_uint16), ('len', c_uint16),
('check', c_uint16), ('check', c_uint16),
] ]
class ndpi_packet_struct(Structure): class ndpi_packet_struct(Structure):
_fields_ = [ _fields_ = [
@@ -655,7 +654,7 @@ class ndpi_packet_struct(Structure):
('packet_lines_parsed_complete', c_uint8, 1), ('packet_lines_parsed_complete', c_uint8, 1),
('packet_direction', c_uint8, 1), ('packet_direction', c_uint8, 1),
('empty_line_position_set', c_uint8, 1), ('empty_line_position_set', c_uint8, 1),
] ]
ndpi_flow_struct._fields_ = [ ndpi_flow_struct._fields_ = [
("detected_protocol_stack", c_uint16 * ndpi.ndpi_wrap_ndpi_procol_size()), ("detected_protocol_stack", c_uint16 * ndpi.ndpi_wrap_ndpi_procol_size()),
+5
View File
@@ -53,3 +53,8 @@ int ndpi_wrap_ndpi_procol_size(){
void ndpi_wrap_NDPI_BITMASK_SET_ALL(NDPI_PROTOCOL_BITMASK* bitmask){ void ndpi_wrap_NDPI_BITMASK_SET_ALL(NDPI_PROTOCOL_BITMASK* bitmask){
NDPI_ONE(bitmask); NDPI_ONE(bitmask);
} }
void dummy() {
/* Dummy call just to cause linker to include the ndpi library */
ndpi_tfind(NULL, NULL, NULL);
}