Minor fixes
This commit is contained in:
+34
-33
@@ -271,18 +271,18 @@ ndpi_merge_splt_arrays (const uint16_t *pkt_len, const struct timeval *pkt_time,
|
|||||||
struct timeval tmp, tmp_r;
|
struct timeval tmp, tmp_r;
|
||||||
struct timeval start_m;
|
struct timeval start_m;
|
||||||
|
|
||||||
if (r_idx + s_idx == 0) {
|
if(r_idx + s_idx == 0) {
|
||||||
return ;
|
return ;
|
||||||
} else if (r_idx == 0) {
|
} else if(r_idx == 0) {
|
||||||
ts_start = pkt_time[0];
|
ts_start = pkt_time[0];
|
||||||
tmp = pkt_time[0];
|
tmp = pkt_time[0];
|
||||||
ndpi_timer_sub(&tmp, &start_time, &start_m);
|
ndpi_timer_sub(&tmp, &start_time, &start_m);
|
||||||
} else if (s_idx == 0) {
|
} else if(s_idx == 0) {
|
||||||
ts_start = pkt_time_twin[0];
|
ts_start = pkt_time_twin[0];
|
||||||
tmp = pkt_time_twin[0];
|
tmp = pkt_time_twin[0];
|
||||||
ndpi_timer_sub(&tmp, &start_time_twin, &start_m);
|
ndpi_timer_sub(&tmp, &start_time_twin, &start_m);
|
||||||
} else {
|
} else {
|
||||||
if (ndpi_timer_lt(&start_time, &start_time_twin)) {
|
if(ndpi_timer_lt(&start_time, &start_time_twin)) {
|
||||||
ts_start = pkt_time[0];
|
ts_start = pkt_time[0];
|
||||||
tmp = pkt_time[0];
|
tmp = pkt_time[0];
|
||||||
ndpi_timer_sub(&tmp, &start_time, &start_m);
|
ndpi_timer_sub(&tmp, &start_time, &start_m);
|
||||||
@@ -294,31 +294,31 @@ ndpi_merge_splt_arrays (const uint16_t *pkt_len, const struct timeval *pkt_time,
|
|||||||
}
|
}
|
||||||
s = r = 0;
|
s = r = 0;
|
||||||
while ((s < s_idx) || (r < r_idx)) {
|
while ((s < s_idx) || (r < r_idx)) {
|
||||||
if (s >= s_idx) {
|
if(s >= s_idx) {
|
||||||
merged_lens[s+r] = pkt_len_twin[r];
|
merged_lens[s+r] = pkt_len_twin[r];
|
||||||
tmp = pkt_time_twin[r];
|
tmp = pkt_time_twin[r];
|
||||||
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
||||||
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
||||||
if (merged_times[s+r] == 0)
|
if(merged_times[s+r] == 0)
|
||||||
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
||||||
ts_start = tmp;
|
ts_start = tmp;
|
||||||
r++;
|
r++;
|
||||||
} else if (r >= r_idx) {
|
} else if(r >= r_idx) {
|
||||||
merged_lens[s+r] = pkt_len[s];
|
merged_lens[s+r] = pkt_len[s];
|
||||||
tmp = pkt_time[s];
|
tmp = pkt_time[s];
|
||||||
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
||||||
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
||||||
if (merged_times[s+r] == 0)
|
if(merged_times[s+r] == 0)
|
||||||
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
||||||
ts_start = tmp;
|
ts_start = tmp;
|
||||||
s++;
|
s++;
|
||||||
} else {
|
} else {
|
||||||
if (ndpi_timer_lt(&pkt_time[s], &pkt_time_twin[r])) {
|
if(ndpi_timer_lt(&pkt_time[s], &pkt_time_twin[r])) {
|
||||||
merged_lens[s+r] = pkt_len[s];
|
merged_lens[s+r] = pkt_len[s];
|
||||||
tmp = pkt_time[s];
|
tmp = pkt_time[s];
|
||||||
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
||||||
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
||||||
if (merged_times[s+r] == 0)
|
if(merged_times[s+r] == 0)
|
||||||
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
||||||
ts_start = tmp;
|
ts_start = tmp;
|
||||||
s++;
|
s++;
|
||||||
@@ -327,7 +327,7 @@ ndpi_merge_splt_arrays (const uint16_t *pkt_len, const struct timeval *pkt_time,
|
|||||||
tmp = pkt_time_twin[r];
|
tmp = pkt_time_twin[r];
|
||||||
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
ndpi_timer_sub(&tmp, &ts_start, &tmp_r);
|
||||||
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_milliseconds(tmp_r);
|
||||||
if (merged_times[s+r] == 0)
|
if(merged_times[s+r] == 0)
|
||||||
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
merged_times[s+r] = ndpi_timeval_to_microseconds(tmp_r);
|
||||||
ts_start = tmp;
|
ts_start = tmp;
|
||||||
r++;
|
r++;
|
||||||
@@ -335,7 +335,7 @@ ndpi_merge_splt_arrays (const uint16_t *pkt_len, const struct timeval *pkt_time,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
merged_times[0] = ndpi_timeval_to_milliseconds(start_m);
|
merged_times[0] = ndpi_timeval_to_milliseconds(start_m);
|
||||||
if (merged_times[0] == 0)
|
if(merged_times[0] == 0)
|
||||||
merged_times[0] = ndpi_timeval_to_microseconds(start_m);
|
merged_times[0] = ndpi_timeval_to_microseconds(start_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,9 +352,9 @@ ndpi_get_mc_rep_lens (uint16_t *lens, float *length_mc, uint16_t num_packets)
|
|||||||
length_mc[i] = 0.0;
|
length_mc[i] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_packets == 0) {
|
if(num_packets == 0) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else if (num_packets == 1) {
|
} else if(num_packets == 1) {
|
||||||
cur_packet_size = (int)min(lens[0]/(float)MC_BIN_SIZE_LEN,(uint16_t)MC_BINS_LEN-1);
|
cur_packet_size = (int)min(lens[0]/(float)MC_BIN_SIZE_LEN,(uint16_t)MC_BINS_LEN-1);
|
||||||
length_mc[cur_packet_size + cur_packet_size*MC_BINS_LEN] = 1.0;
|
length_mc[cur_packet_size + cur_packet_size*MC_BINS_LEN] = 1.0;
|
||||||
} else {
|
} else {
|
||||||
@@ -370,7 +370,7 @@ ndpi_get_mc_rep_lens (uint16_t *lens, float *length_mc, uint16_t num_packets)
|
|||||||
for (j = 0; j < MC_BINS_LEN; j++) {
|
for (j = 0; j < MC_BINS_LEN; j++) {
|
||||||
row_sum += length_mc[i*MC_BINS_LEN+j];
|
row_sum += length_mc[i*MC_BINS_LEN+j];
|
||||||
}
|
}
|
||||||
if (row_sum != 0.0) {
|
if(row_sum != 0.0) {
|
||||||
for (j = 0; j < MC_BINS_LEN; j++) {
|
for (j = 0; j < MC_BINS_LEN; j++) {
|
||||||
length_mc[i*MC_BINS_LEN+j] /= row_sum;
|
length_mc[i*MC_BINS_LEN+j] /= row_sum;
|
||||||
}
|
}
|
||||||
@@ -391,9 +391,9 @@ ndpi_get_mc_rep_times (uint16_t *times, float *time_mc, uint16_t num_packets)
|
|||||||
for (i = 0; i < MC_BINS_TIME*MC_BINS_TIME; i++) { // init to 0
|
for (i = 0; i < MC_BINS_TIME*MC_BINS_TIME; i++) { // init to 0
|
||||||
time_mc[i] = 0.0;
|
time_mc[i] = 0.0;
|
||||||
}
|
}
|
||||||
if (num_packets == 0) {
|
if(num_packets == 0) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else if (num_packets == 1) {
|
} else if(num_packets == 1) {
|
||||||
cur_packet_time = (int)min(times[0]/(float)MC_BIN_SIZE_TIME,(uint16_t)MC_BINS_TIME-1);
|
cur_packet_time = (int)min(times[0]/(float)MC_BIN_SIZE_TIME,(uint16_t)MC_BINS_TIME-1);
|
||||||
time_mc[cur_packet_time + cur_packet_time*MC_BINS_TIME] = 1.0;
|
time_mc[cur_packet_time + cur_packet_time*MC_BINS_TIME] = 1.0;
|
||||||
} else {
|
} else {
|
||||||
@@ -409,7 +409,7 @@ ndpi_get_mc_rep_times (uint16_t *times, float *time_mc, uint16_t num_packets)
|
|||||||
for (j = 0; j < MC_BINS_TIME; j++) {
|
for (j = 0; j < MC_BINS_TIME; j++) {
|
||||||
row_sum += time_mc[i*MC_BINS_TIME+j];
|
row_sum += time_mc[i*MC_BINS_TIME+j];
|
||||||
}
|
}
|
||||||
if (row_sum != 0.0) {
|
if(row_sum != 0.0) {
|
||||||
for (j = 0; j < MC_BINS_TIME; j++) {
|
for (j = 0; j < MC_BINS_TIME; j++) {
|
||||||
time_mc[i*MC_BINS_TIME+j] /= row_sum;
|
time_mc[i*MC_BINS_TIME+j] /= row_sum;
|
||||||
}
|
}
|
||||||
@@ -467,11 +467,12 @@ ndpi_classify (const unsigned short *pkt_len, const struct timeval *pkt_time,
|
|||||||
features[i] = 0.0;
|
features[i] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
merged_lens = calloc(1, sizeof(uint16_t)*(op_n + ip_n));
|
merged_lens = ndpi_calloc(1, sizeof(uint16_t)*(op_n + ip_n));
|
||||||
merged_times = calloc(1, sizeof(uint16_t)*(op_n + ip_n));
|
merged_times = ndpi_calloc(1, sizeof(uint16_t)*(op_n + ip_n));
|
||||||
if (!merged_lens || !merged_times) {
|
|
||||||
free(merged_lens);
|
if(!merged_lens || !merged_times) {
|
||||||
free(merged_times);
|
ndpi_free(merged_lens);
|
||||||
|
ndpi_free(merged_times);
|
||||||
return(score);
|
return(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,9 +509,9 @@ ndpi_classify (const unsigned short *pkt_len, const struct timeval *pkt_time,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fill out byte distribution features
|
// fill out byte distribution features
|
||||||
if (ob+ib > 100 && use_bd) {
|
if(ob+ib > 100 && use_bd) {
|
||||||
for (i = 0; i < NUM_BD_VALUES; i++) {
|
for (i = 0; i < NUM_BD_VALUES; i++) {
|
||||||
if (pkt_len_twin != NULL) {
|
if(pkt_len_twin != NULL) {
|
||||||
features[i+8+MC_BINS_LEN*MC_BINS_LEN+MC_BINS_TIME*MC_BINS_TIME] = (bd[i]+bd_t[i])/((float)(ob+ib));
|
features[i+8+MC_BINS_LEN*MC_BINS_LEN+MC_BINS_TIME*MC_BINS_TIME] = (bd[i]+bd_t[i])/((float)(ob+ib));
|
||||||
} else {
|
} else {
|
||||||
features[i+8+MC_BINS_LEN*MC_BINS_LEN+MC_BINS_TIME*MC_BINS_TIME] = bd[i]/((float)(ob));
|
features[i+8+MC_BINS_LEN*MC_BINS_LEN+MC_BINS_TIME*MC_BINS_TIME] = bd[i]/((float)(ob));
|
||||||
@@ -529,8 +530,8 @@ ndpi_classify (const unsigned short *pkt_len, const struct timeval *pkt_time,
|
|||||||
|
|
||||||
score = min(-score,500.0); // check b/c overflow
|
score = min(-score,500.0); // check b/c overflow
|
||||||
|
|
||||||
free(merged_lens);
|
ndpi_free(merged_lens);
|
||||||
free(merged_times);
|
ndpi_free(merged_times);
|
||||||
|
|
||||||
return 1.0/(1.0+exp(score));
|
return 1.0/(1.0+exp(score));
|
||||||
}
|
}
|
||||||
@@ -553,11 +554,11 @@ ndpi_update_params (classifier_type_codes_t param_type, const char *param_file)
|
|||||||
case (SPLT_PARAM_TYPE):
|
case (SPLT_PARAM_TYPE):
|
||||||
count = 0;
|
count = 0;
|
||||||
fp = fopen(param_file,"r");
|
fp = fopen(param_file,"r");
|
||||||
if (fp != NULL) {
|
if(fp != NULL) {
|
||||||
while (fscanf(fp, "%f", ¶m) != EOF) {
|
while (fscanf(fp, "%f", ¶m) != EOF) {
|
||||||
ndpi_parameters_splt[count] = param;
|
ndpi_parameters_splt[count] = param;
|
||||||
count++;
|
count++;
|
||||||
if (count >= NUM_PARAMETERS_SPLT_LOGREG) {
|
if(count >= NUM_PARAMETERS_SPLT_LOGREG) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -568,11 +569,11 @@ ndpi_update_params (classifier_type_codes_t param_type, const char *param_file)
|
|||||||
case (BD_PARAM_TYPE):
|
case (BD_PARAM_TYPE):
|
||||||
count = 0;
|
count = 0;
|
||||||
fp = fopen(param_file,"r");
|
fp = fopen(param_file,"r");
|
||||||
if (fp != NULL) {
|
if(fp != NULL) {
|
||||||
while (fscanf(fp, "%f", ¶m) != EOF) {
|
while (fscanf(fp, "%f", ¶m) != EOF) {
|
||||||
ndpi_parameters_bd[count] = param;
|
ndpi_parameters_bd[count] = param;
|
||||||
count++;
|
count++;
|
||||||
if (count >= NUM_PARAMETERS_BD_LOGREG) {
|
if(count >= NUM_PARAMETERS_BD_LOGREG) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -606,7 +607,7 @@ unsigned int
|
|||||||
ndpi_timer_eq(const struct timeval *a,
|
ndpi_timer_eq(const struct timeval *a,
|
||||||
const struct timeval *b)
|
const struct timeval *b)
|
||||||
{
|
{
|
||||||
if (a->tv_sec == b->tv_sec && a->tv_usec == b->tv_usec) {
|
if(a->tv_sec == b->tv_sec && a->tv_usec == b->tv_usec) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,7 +636,7 @@ ndpi_timer_sub(const struct timeval *a,
|
|||||||
{
|
{
|
||||||
result->tv_sec = a->tv_sec - b->tv_sec;
|
result->tv_sec = a->tv_sec - b->tv_sec;
|
||||||
result->tv_usec = a->tv_usec - b->tv_usec;
|
result->tv_usec = a->tv_usec - b->tv_usec;
|
||||||
if (result->tv_usec < 0) {
|
if(result->tv_usec < 0) {
|
||||||
--result->tv_sec;
|
--result->tv_sec;
|
||||||
result->tv_usec += 1000000;
|
result->tv_usec += 1000000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -322,7 +322,7 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
|
|
||||||
/* We set the protocol in the response */
|
/* We set the protocol in the response */
|
||||||
if(flow->kerberos_buf.pktbuf != NULL) {
|
if(flow->kerberos_buf.pktbuf != NULL) {
|
||||||
free(flow->kerberos_buf.pktbuf);
|
ndpi_free(flow->kerberos_buf.pktbuf);
|
||||||
flow->kerberos_buf.pktbuf = NULL;
|
flow->kerberos_buf.pktbuf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ static void ndpi_search_ssh_tcp(struct ndpi_detection_module_struct *ndpi_struct
|
|||||||
flow->protos.ssh.hassh_server[32] = '\0';
|
flow->protos.ssh.hassh_server[32] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
free(hassh_buf);
|
ndpi_free(hassh_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndpi_int_ssh_add_connection(ndpi_struct, flow);
|
ndpi_int_ssh_add_connection(ndpi_struct, flow);
|
||||||
|
|||||||
Reference in New Issue
Block a user