Added ndpi_serialize_raw_record() API call
This commit is contained in:
+16
-16
@@ -40,7 +40,7 @@ void ndpi_init_data_analysis(struct ndpi_analyze_struct *ret, u_int16_t _max_ser
|
||||
u_int32_t len;
|
||||
|
||||
memset(ret, 0, sizeof(struct ndpi_analyze_struct));
|
||||
|
||||
|
||||
if(_max_series_len > MAX_SERIES_LEN) _max_series_len = MAX_SERIES_LEN;
|
||||
ret->num_values_array_len = _max_series_len;
|
||||
|
||||
@@ -61,8 +61,8 @@ struct ndpi_analyze_struct* ndpi_alloc_data_analysis(u_int16_t _max_series_len)
|
||||
struct ndpi_analyze_struct *ret = ndpi_malloc(sizeof(struct ndpi_analyze_struct));
|
||||
|
||||
if(ret != NULL)
|
||||
ndpi_init_data_analysis(ret, _max_series_len);
|
||||
|
||||
ndpi_init_data_analysis(ret, _max_series_len);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@@ -89,18 +89,18 @@ void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int32_t value) {
|
||||
}
|
||||
|
||||
s->sum_total += value, s->num_data_entries++;
|
||||
|
||||
|
||||
if(s->num_values_array_len) {
|
||||
s->values[s->next_value_insert_index] = value;
|
||||
|
||||
if(++s->next_value_insert_index == s->num_values_array_len)
|
||||
s->next_value_insert_index = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Update stddev */
|
||||
tmp_mu = s->stddev.mu;
|
||||
s->stddev.mu = ((s->stddev.mu * (s->num_data_entries - 1)) + value) / s->num_data_entries;
|
||||
s->stddev.q = s->stddev.q + (value - tmp_mu)*(value - s->stddev.mu);
|
||||
s->stddev.q = s->stddev.q + (value - tmp_mu)*(value - s->stddev.mu);
|
||||
}
|
||||
|
||||
/* ********************************************************************************* */
|
||||
@@ -137,10 +137,10 @@ float ndpi_data_window_average(struct ndpi_analyze_struct *s) {
|
||||
if(s->num_values_array_len) {
|
||||
float sum = 0.0;
|
||||
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
|
||||
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
sum += s->values[i];
|
||||
|
||||
|
||||
return((float)sum / (float)n);
|
||||
} else
|
||||
return(0);
|
||||
@@ -155,17 +155,17 @@ float ndpi_data_entropy(struct ndpi_analyze_struct *s) {
|
||||
if(s->num_values_array_len) {
|
||||
int i;
|
||||
float sum = 0.0, total = 0.0;
|
||||
|
||||
|
||||
for(i=0; i<s->num_values_array_len; i++)
|
||||
total += s->values[i];
|
||||
|
||||
|
||||
for (i=0; i<s->num_values_array_len; i++) {
|
||||
float tmp = (float)s->values[i] / (float)total;
|
||||
|
||||
|
||||
if(tmp > FLT_EPSILON)
|
||||
sum -= tmp * logf(tmp);
|
||||
sum -= tmp * logf(tmp);
|
||||
}
|
||||
|
||||
|
||||
return(sum / logf(2.0));
|
||||
} else
|
||||
return(0);
|
||||
@@ -176,10 +176,10 @@ float ndpi_data_entropy(struct ndpi_analyze_struct *s) {
|
||||
void ndpi_data_print_window_values(struct ndpi_analyze_struct *s) {
|
||||
if(s->num_values_array_len) {
|
||||
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
|
||||
|
||||
|
||||
for(i=0; i<n; i++)
|
||||
printf("[%u: %u]", i, s->values[i]);
|
||||
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ void ndpi_data_print_window_values(struct ndpi_analyze_struct *s) {
|
||||
float ndpi_data_ratio(u_int32_t sent, u_int32_t rcvd) {
|
||||
float s = (float)((int64_t)sent + (int64_t)rcvd);
|
||||
float d = (float)((int64_t)sent - (int64_t)rcvd);
|
||||
|
||||
|
||||
return((s == 0) ? 0 : (d/s));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user