Added ndpi_print_bin() API call
This commit is contained in:
@@ -3114,6 +3114,7 @@ static void binUnitTest() {
|
|||||||
struct ndpi_bin b1, b2;
|
struct ndpi_bin b1, b2;
|
||||||
u_int8_t num_bins = 32;
|
u_int8_t num_bins = 32;
|
||||||
u_int32_t i;
|
u_int32_t i;
|
||||||
|
char out_buf[128];
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
@@ -3122,8 +3123,12 @@ static void binUnitTest() {
|
|||||||
for(i=0; i<32; i++)
|
for(i=0; i<32; i++)
|
||||||
ndpi_inc_bin(&b1, rand() % num_bins), ndpi_inc_bin(&b2, rand() % num_bins);
|
ndpi_inc_bin(&b1, rand() % num_bins), ndpi_inc_bin(&b2, rand() % num_bins);
|
||||||
|
|
||||||
ndpi_bin_similarity(&b1, &b1, 0);
|
#if 0
|
||||||
ndpi_bin_similarity(&b1, &b2, 0);
|
printf("1) %s\n", ndpi_print_bin(&b1, 0, out_buf, sizeof(out_buf)));
|
||||||
|
printf("2) %s\n", ndpi_print_bin(&b2, 0, out_buf, sizeof(out_buf)));
|
||||||
|
|
||||||
|
printf("Similarity: %f\n\n", ndpi_bin_similarity(&b1, &b2, 1));
|
||||||
|
#endif
|
||||||
|
|
||||||
ndpi_free_bin(&b1), ndpi_free_bin(&b2);
|
ndpi_free_bin(&b1), ndpi_free_bin(&b2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1071,7 +1071,10 @@ extern "C" {
|
|||||||
void ndpi_free_bin(struct ndpi_bin *b);
|
void ndpi_free_bin(struct ndpi_bin *b);
|
||||||
void ndpi_inc_bin(struct ndpi_bin *b, u_int8_t slot_id);
|
void ndpi_inc_bin(struct ndpi_bin *b, u_int8_t slot_id);
|
||||||
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);
|
||||||
float ndpi_bin_similarity(struct ndpi_bin *b1, struct ndpi_bin *b2, u_int8_t normalize_first);
|
float ndpi_bin_similarity(struct ndpi_bin *b1, struct ndpi_bin *b2, u_int8_t normalize_first);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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
|
Determines how similar are two bins
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user