bins: add support for 64bit bins (#1626)
This commit is contained in:
@@ -1232,6 +1232,9 @@ void print_bin(FILE *fout, const char *label, struct ndpi_bin *b) {
|
|||||||
case ndpi_bin_family32:
|
case ndpi_bin_family32:
|
||||||
fprintf(fout, "%s%u", (i > 0) ? sep : "", b->u.bins32[i]);
|
fprintf(fout, "%s%u", (i > 0) ? sep : "", b->u.bins32[i]);
|
||||||
break;
|
break;
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
fprintf(fout, "%s%llu", (i > 0) ? sep : "", (unsigned long long)b->u.bins64[i]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1661,9 +1661,9 @@ extern "C" {
|
|||||||
int ndpi_init_bin(struct ndpi_bin *b, enum ndpi_bin_family f, u_int16_t num_bins);
|
int ndpi_init_bin(struct ndpi_bin *b, enum ndpi_bin_family f, u_int16_t num_bins);
|
||||||
void ndpi_free_bin(struct ndpi_bin *b);
|
void ndpi_free_bin(struct ndpi_bin *b);
|
||||||
struct ndpi_bin* ndpi_clone_bin(struct ndpi_bin *b);
|
struct ndpi_bin* ndpi_clone_bin(struct ndpi_bin *b);
|
||||||
void ndpi_inc_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t val);
|
void ndpi_inc_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int64_t val);
|
||||||
void ndpi_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t value);
|
void ndpi_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int64_t value);
|
||||||
u_int32_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id);
|
u_int64_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id);
|
||||||
void ndpi_reset_bin(struct ndpi_bin *b);
|
void ndpi_reset_bin(struct ndpi_bin *b);
|
||||||
void ndpi_normalize_bin(struct ndpi_bin *b);
|
void ndpi_normalize_bin(struct ndpi_bin *b);
|
||||||
char* ndpi_print_bin(struct ndpi_bin *b, u_int8_t normalize_first, char *out_buf, u_int out_buf_len);
|
char* ndpi_print_bin(struct ndpi_bin *b, u_int8_t normalize_first, char *out_buf, u_int out_buf_len);
|
||||||
|
|||||||
@@ -1602,7 +1602,8 @@ struct ndpi_hll {
|
|||||||
enum ndpi_bin_family {
|
enum ndpi_bin_family {
|
||||||
ndpi_bin_family8,
|
ndpi_bin_family8,
|
||||||
ndpi_bin_family16,
|
ndpi_bin_family16,
|
||||||
ndpi_bin_family32
|
ndpi_bin_family32,
|
||||||
|
ndpi_bin_family64,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ndpi_bin {
|
struct ndpi_bin {
|
||||||
@@ -1614,6 +1615,7 @@ struct ndpi_bin {
|
|||||||
u_int8_t *bins8; /* num_bins bins */
|
u_int8_t *bins8; /* num_bins bins */
|
||||||
u_int16_t *bins16; /* num_bins bins */
|
u_int16_t *bins16; /* num_bins bins */
|
||||||
u_int32_t *bins32; /* num_bins bins */
|
u_int32_t *bins32; /* num_bins bins */
|
||||||
|
u_int64_t *bins64; /* num_bins bins */
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+49
-3
@@ -323,6 +323,11 @@ int ndpi_init_bin(struct ndpi_bin *b, enum ndpi_bin_family f, u_int16_t num_bins
|
|||||||
if((b->u.bins32 = (u_int32_t*)ndpi_calloc(num_bins, sizeof(u_int32_t))) == NULL)
|
if((b->u.bins32 = (u_int32_t*)ndpi_calloc(num_bins, sizeof(u_int32_t))) == NULL)
|
||||||
return(-1);
|
return(-1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
if((b->u.bins64 = (u_int64_t*)ndpi_calloc(num_bins, sizeof(u_int64_t))) == NULL)
|
||||||
|
return(-1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
@@ -341,6 +346,9 @@ void ndpi_free_bin(struct ndpi_bin *b) {
|
|||||||
case ndpi_bin_family32:
|
case ndpi_bin_family32:
|
||||||
ndpi_free(b->u.bins32);
|
ndpi_free(b->u.bins32);
|
||||||
break;
|
break;
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
ndpi_free(b->u.bins64);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,6 +385,14 @@ struct ndpi_bin* ndpi_clone_bin(struct ndpi_bin *b) {
|
|||||||
} else
|
} else
|
||||||
memcpy(out->u.bins32, b->u.bins32, out->num_bins*sizeof(u_int32_t));
|
memcpy(out->u.bins32, b->u.bins32, out->num_bins*sizeof(u_int32_t));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
if((out->u.bins64 = (u_int64_t*)ndpi_calloc(out->num_bins, sizeof(u_int64_t))) == NULL) {
|
||||||
|
ndpi_free(out);
|
||||||
|
return(NULL);
|
||||||
|
} else
|
||||||
|
memcpy(out->u.bins64, b->u.bins64, out->num_bins*sizeof(u_int64_t));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(out);
|
return(out);
|
||||||
@@ -384,7 +400,7 @@ struct ndpi_bin* ndpi_clone_bin(struct ndpi_bin *b) {
|
|||||||
|
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t val) {
|
void ndpi_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int64_t val) {
|
||||||
if(slot_id >= b->num_bins) slot_id = 0;
|
if(slot_id >= b->num_bins) slot_id = 0;
|
||||||
|
|
||||||
switch(b->family) {
|
switch(b->family) {
|
||||||
@@ -397,12 +413,15 @@ void ndpi_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t val) {
|
|||||||
case ndpi_bin_family32:
|
case ndpi_bin_family32:
|
||||||
b->u.bins32[slot_id] = (u_int32_t)val;
|
b->u.bins32[slot_id] = (u_int32_t)val;
|
||||||
break;
|
break;
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
b->u.bins64[slot_id] = (u_int64_t)val;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
void ndpi_inc_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t val) {
|
void ndpi_inc_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int64_t val) {
|
||||||
b->is_empty = 0;
|
b->is_empty = 0;
|
||||||
|
|
||||||
if(slot_id >= b->num_bins) slot_id = 0;
|
if(slot_id >= b->num_bins) slot_id = 0;
|
||||||
@@ -417,12 +436,15 @@ void ndpi_inc_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t val) {
|
|||||||
case ndpi_bin_family32:
|
case ndpi_bin_family32:
|
||||||
b->u.bins32[slot_id] += (u_int32_t)val;
|
b->u.bins32[slot_id] += (u_int32_t)val;
|
||||||
break;
|
break;
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
b->u.bins64[slot_id] += (u_int64_t)val;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
|
|
||||||
u_int32_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id) {
|
u_int64_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id) {
|
||||||
if(slot_id >= b->num_bins) slot_id = 0;
|
if(slot_id >= b->num_bins) slot_id = 0;
|
||||||
|
|
||||||
switch(b->family) {
|
switch(b->family) {
|
||||||
@@ -435,6 +457,9 @@ u_int32_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id) {
|
|||||||
case ndpi_bin_family32:
|
case ndpi_bin_family32:
|
||||||
return(b->u.bins32[slot_id]);
|
return(b->u.bins32[slot_id]);
|
||||||
break;
|
break;
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
return(b->u.bins64[slot_id]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
@@ -455,6 +480,9 @@ void ndpi_reset_bin(struct ndpi_bin *b) {
|
|||||||
case ndpi_bin_family32:
|
case ndpi_bin_family32:
|
||||||
memset(b->u.bins32, 0, sizeof(u_int32_t)*b->num_bins);
|
memset(b->u.bins32, 0, sizeof(u_int32_t)*b->num_bins);
|
||||||
break;
|
break;
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
memset(b->u.bins64, 0, sizeof(u_int64_t)*b->num_bins);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* ********************************************************************************* */
|
/* ********************************************************************************* */
|
||||||
@@ -495,6 +523,15 @@ void ndpi_normalize_bin(struct ndpi_bin *b) {
|
|||||||
b->u.bins32[i] = (b->u.bins32[i]*100) / tot;
|
b->u.bins32[i] = (b->u.bins32[i]*100) / tot;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
for(i=0; i<b->num_bins; i++) tot += b->u.bins64[i];
|
||||||
|
|
||||||
|
if(tot > 0) {
|
||||||
|
for(i=0; i<b->num_bins; i++)
|
||||||
|
b->u.bins64[i] = (b->u.bins64[i]*100) / tot;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,6 +573,15 @@ char* ndpi_print_bin(struct ndpi_bin *b, u_int8_t normalize_first, char *out_buf
|
|||||||
len += rc;
|
len += rc;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ndpi_bin_family64:
|
||||||
|
for(i=0; i<b->num_bins; i++) {
|
||||||
|
int rc = ndpi_snprintf(&out_buf[len], out_buf_len-len, "%s%llu", (i > 0) ? "," : "", (unsigned long long)b->u.bins64[i]);
|
||||||
|
|
||||||
|
if(rc < 0) break;
|
||||||
|
len += rc;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(out_buf);
|
return(out_buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user