Fixed warning

Reworked protocol initialization
This commit is contained in:
Luca Deri
2016-02-27 09:00:02 +01:00
parent 6df31099c2
commit 20374b542d
5 changed files with 47 additions and 35 deletions
+6
View File
@@ -67,6 +67,12 @@ extern "C" {
*/
u_int16_t ndpi_host_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t host);
/**
* Init single protocol match
*/
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_match *match);
/**
* This function returns a new initialized detection module.
* @param ticks_per_second the timestamp resolution per second (like 1000 for millisecond resolution)
+12
View File
@@ -1015,4 +1015,16 @@ struct ndpi_flow_struct {
struct ndpi_id_struct *dst;
};
typedef struct {
char *string_to_match, *proto_name;
int protocol_id;
ndpi_protocol_breed_t protocol_breed;
} ndpi_protocol_match;
typedef struct {
u_int32_t network;
u_int8_t cidr;
u_int8_t value;
} ndpi_network;
#endif/* __NDPI_TYPEDEFS_H__ */
-12
View File
@@ -18,18 +18,6 @@
*
*/
typedef struct {
char *string_to_match, *proto_name;
int protocol_id;
ndpi_protocol_breed_t protocol_breed;
} ndpi_protocol_match;
typedef struct {
u_int32_t network;
u_int8_t cidr;
u_int8_t value;
} ndpi_network;
/* ****************************************************** */
static ndpi_network host_protocol_list[] = {
+28 -22
View File
@@ -577,30 +577,36 @@ static int ndpi_remove_host_url_subprotocol(struct ndpi_detection_module_struct
/* ******************************************************************** */
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_match *match) {
u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO };
ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
ndpi_add_host_url_subprotocol(ndpi_mod, match->string_to_match,
match->protocol_id, match->protocol_breed);
if(ndpi_mod->proto_defaults[match->protocol_id].protoName == NULL) {
ndpi_mod->proto_defaults[match->protocol_id].protoName = ndpi_strdup(match->proto_name);
ndpi_mod->proto_defaults[match->protocol_id].protoId = match->protocol_id;
ndpi_mod->proto_defaults[match->protocol_id].protoBreed = match->protocol_breed;
}
ndpi_set_proto_defaults(ndpi_mod,
ndpi_mod->proto_defaults[match->protocol_id].protoBreed,
ndpi_mod->proto_defaults[match->protocol_id].protoId,
no_master, no_master,
ndpi_mod->proto_defaults[match->protocol_id].protoName,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
}
/* ******************************************************************** */
static void init_string_based_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
int i;
for(i=0; host_match[i].string_to_match != NULL; i++) {
u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO };
ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
ndpi_add_host_url_subprotocol(ndpi_mod, host_match[i].string_to_match,
host_match[i].protocol_id, host_match[i].protocol_breed);
if(ndpi_mod->proto_defaults[host_match[i].protocol_id].protoName == NULL) {
ndpi_mod->proto_defaults[host_match[i].protocol_id].protoName = ndpi_strdup(host_match[i].proto_name);
ndpi_mod->proto_defaults[host_match[i].protocol_id].protoId = host_match[i].protocol_id;
ndpi_mod->proto_defaults[host_match[i].protocol_id].protoBreed = host_match[i].protocol_breed;
}
ndpi_set_proto_defaults(ndpi_mod,
ndpi_mod->proto_defaults[host_match[i].protocol_id].protoBreed,
ndpi_mod->proto_defaults[host_match[i].protocol_id].protoId,
no_master, no_master,
ndpi_mod->proto_defaults[host_match[i].protocol_id].protoName,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
}
for(i=0; host_match[i].string_to_match != NULL; i++)
ndpi_init_protocol_match(ndpi_mod, &host_match[i]);
#ifdef DEBUG
ac_automata_display(ndpi_mod->host_automa.ac_automa, 'n');
+1 -1
View File
@@ -46,7 +46,7 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
if(bt_magic)
bt_hash = &bt_magic[19], peer_id = &bt_magic[39];
} else
bt_hash = &flow->packet.payload[28], peer_id = &flow->packet.payload[48];
bt_hash = (const char*)&flow->packet.payload[28], peer_id = (const char*)&flow->packet.payload[48];
if(bt_hash) memcpy(flow->bittorent_hash, bt_hash, 20);
}