diff options
-rw-r--r-- | example/ndpiReader.c | 3 | ||||
-rw-r--r-- | src/include/ndpi_api.h.in | 6 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 4 | ||||
-rw-r--r-- | src/lib/ndpi_analyze.c | 52 |
4 files changed, 58 insertions, 7 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index d7d720fff..f8e55c484 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -1232,6 +1232,9 @@ void print_bin(FILE *fout, const char *label, struct ndpi_bin *b) { case ndpi_bin_family32: fprintf(fout, "%s%u", (i > 0) ? sep : "", b->u.bins32[i]); break; + case ndpi_bin_family64: + fprintf(fout, "%s%llu", (i > 0) ? sep : "", (unsigned long long)b->u.bins64[i]); + break; } } diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index ed1016aea..2695c2400 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -1661,9 +1661,9 @@ extern "C" { 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); 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_set_bin(struct ndpi_bin *b, u_int16_t slot_id, u_int32_t value); - u_int32_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id); + 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_int64_t value); + 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_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); diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 19fc04759..727bf41f7 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -1602,7 +1602,8 @@ struct ndpi_hll { enum ndpi_bin_family { ndpi_bin_family8, ndpi_bin_family16, - ndpi_bin_family32 + ndpi_bin_family32, + ndpi_bin_family64, }; struct ndpi_bin { @@ -1614,6 +1615,7 @@ struct ndpi_bin { u_int8_t *bins8; /* num_bins bins */ u_int16_t *bins16; /* num_bins bins */ u_int32_t *bins32; /* num_bins bins */ + u_int64_t *bins64; /* num_bins bins */ } u; }; diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index b9c9815dc..a3c518051 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -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) return(-1); 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); @@ -341,6 +346,9 @@ void ndpi_free_bin(struct ndpi_bin *b) { case ndpi_bin_family32: ndpi_free(b->u.bins32); 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 memcpy(out->u.bins32, b->u.bins32, out->num_bins*sizeof(u_int32_t)); 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); @@ -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; 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: b->u.bins32[slot_id] = (u_int32_t)val; 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; 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: b->u.bins32[slot_id] += (u_int32_t)val; 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; 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: return(b->u.bins32[slot_id]); break; + case ndpi_bin_family64: + return(b->u.bins64[slot_id]); + break; } return(0); @@ -455,6 +480,9 @@ void ndpi_reset_bin(struct ndpi_bin *b) { case ndpi_bin_family32: memset(b->u.bins32, 0, sizeof(u_int32_t)*b->num_bins); 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; } 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; } 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); |