diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_api.h.in | 3 | ||||
-rw-r--r-- | src/lib/ndpi_analyze.c | 43 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index 26d7d2f66..ed94c5bf3 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -1071,7 +1071,10 @@ extern "C" { void ndpi_free_bin(struct ndpi_bin *b); void ndpi_inc_bin(struct ndpi_bin *b, u_int8_t slot_id); 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); float ndpi_bin_similarity(struct ndpi_bin *b1, struct ndpi_bin *b2, u_int8_t normalize_first); + + #ifdef __cplusplus } #endif diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index 5c3460eaf..eaa0d30c2 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -324,6 +324,49 @@ 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) { + u_int8_t i; + u_int len = 0; + + if(!out_buf) return(out_buf); else out_buf[0] = '\0'; + + if(normalize_first) + ndpi_normalize_bin(b); + + switch(b->family) { + case ndpi_bin_family8: + for(i=0; i<b->num_bins; i++) { + int rc = snprintf(&out_buf[len], out_buf_len-len, "%s%u", (i > 0) ? "," : "", b->u.bins8[i]); + + if(rc < 0) break; + len += rc; + } + break; + + case ndpi_bin_family16: + for(i=0; i<b->num_bins; i++) { + int rc = snprintf(&out_buf[len], out_buf_len-len, "%s%u", (i > 0) ? "," : "", b->u.bins16[i]); + + if(rc < 0) break; + len += rc; + } + break; + + case ndpi_bin_family32: + for(i=0; i<b->num_bins; i++) { + int rc = snprintf(&out_buf[len], out_buf_len-len, "%s%u", (i > 0) ? "," : "", b->u.bins32[i]); + + if(rc < 0) break; + len += rc; + } + break; + } + + return(out_buf); +} + +/* ********************************************************************************* */ + /* Determines how similar are two bins |