Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added printf/fprintf replacement for some internal modules. #1974

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions example/ndpiReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#else
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <sys/socket.h>
#include <sys/mman.h>
#endif
Expand Down Expand Up @@ -612,10 +613,10 @@ static void help(u_int long_help) {
NDPI_BITMASK_SET_ALL(all);
ndpi_set_protocol_detection_bitmask2(ndpi_info_mod, &all);

ndpi_dump_protocols(ndpi_info_mod);
ndpi_dump_protocols(ndpi_info_mod, stdout);

printf("\n\nnDPI supported risks:\n");
ndpi_dump_risks_score();
ndpi_dump_risks_score(stdout);

ndpi_exit_detection_module(ndpi_info_mod);
}
Expand Down Expand Up @@ -977,7 +978,7 @@ static void parseOptions(int argc, char **argv) {

switch (opt) {
case 'a':
ndpi_generate_options(atoi(optarg));
ndpi_generate_options(atoi(optarg), stdout);
exit(0);

case 'A':
Expand Down
1 change: 1 addition & 0 deletions example/reader_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#else
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#endif

#include "reader_util.h"
Expand Down
9 changes: 5 additions & 4 deletions src/include/ndpi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,21 +728,22 @@ extern "C" {
*
* @par ndpi_mod = the detection module
*/
void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod);
void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod, FILE *dump_out);

/**
* Generate Options list used in OPNsense firewall plugin
*
* @par opt = The Option list to generate
* @par dump_out = Output stream for generated options
*/
void ndpi_generate_options(u_int opt);
void ndpi_generate_options(u_int opt, FILE *dump_out);

/**
* Write the list of the scores and their associated risks
*
* @par ndpi_mod = the detection module
* @par dump_out = Output stream for dumped risk scores
*/
void ndpi_dump_risks_score(void);
void ndpi_dump_risks_score(FILE *dump_out);

/**
* Read a file and load the protocols
Expand Down
3 changes: 3 additions & 0 deletions src/include/ndpi_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
#include <sys/param.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifndef __APPLE__
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#endif

#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
#include <endian.h>
Expand Down
4 changes: 4 additions & 0 deletions src/include/ndpi_patricia_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#ifndef _NDPI_PATRICIA_TYPEDEF_H_
#define _NDPI_PATRICIA_TYPEDEF_H_

#ifndef NDPI_CFFI_PREPROCESSING
#include "ndpi_includes.h"
#endif

#define UV16_MAX_USER_VALUES 2

struct patricia_uv16 {
Expand Down
9 changes: 9 additions & 0 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ E * ndpi_typedefs.h
#define __NDPI_TYPEDEFS_H__

#include "ndpi_define.h"
#ifndef NDPI_CFFI_PREPROCESSING
#include "ndpi_includes.h"
#endif
#include "ndpi_protocol_ids.h"
#include "ndpi_utils.h"

Expand All @@ -47,6 +50,12 @@ typedef unsigned int u_int;
#endif
#endif

#ifdef __APPLE__
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
#endif

/* NDPI_LOG_LEVEL */
typedef enum {
NDPI_LOG_ERROR,
Expand Down
7 changes: 6 additions & 1 deletion src/include/ndpi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
#define __NDPI_UTILS_H__

#include "ndpi_define.h"
#ifndef NDPI_CFFI_PREPROCESSING
#include "ndpi_includes.h"
#endif

#ifndef NDPI_CFFI_PREPROCESSING
extern u_int8_t ndpi_ends_with(char *str, char *ends);
struct ndpi_detection_module_struct;
extern u_int8_t ndpi_ends_with(struct ndpi_detection_module_struct *ndpi_struct,
char *str, char *ends);
#endif // NDPI_CFFI_PREPROCESSING
/* **************************************** */

Expand Down
4 changes: 2 additions & 2 deletions src/lib/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ includedir = @includedir@/ndpi
ifneq ($(OS),Windows_NT)
CFLAGS += -fPIC -DPIC
endif
CFLAGS += -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION @NDPI_CFLAGS@ @GPROF_CFLAGS@ @CUSTOM_NDPI@ @ADDITIONAL_INCS@
CFLAGS += -I. -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION @NDPI_CFLAGS@ @GPROF_CFLAGS@ @CUSTOM_NDPI@ @ADDITIONAL_INCS@
LDFLAGS += @NDPI_LDFLAGS@
LIBS = @ADDITIONAL_LIBS@ @LIBS@ @GPROF_LIBS@

OBJECTS = $(patsubst protocols/%.c, protocols/%.o, $(wildcard protocols/*.c)) $(patsubst third_party/src/%.c, third_party/src/%.o, $(wildcard third_party/src/*.c)) $(patsubst third_party/src/hll/%.c, third_party/src/hll/%.o, $(wildcard third_party/src/hll/*.c)) $(patsubst ./%.c, ./%.o, $(wildcard ./*.c))
HEADERS = $(wildcard ../include/*.h)
HEADERS = $(wildcard ../include/*.h) $(wildcard ../include/*.h)
NDPI_VERSION_MAJOR = @NDPI_MAJOR@
NDPI_LIB_STATIC = libndpi.a
NDPI_LIB_SHARED_BASE = libndpi.so
Expand Down
3 changes: 3 additions & 0 deletions src/lib/ndpi_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "ndpi_config.h"
#include "third_party/include/hll.h"

#include "ndpi_replace_printf.h"

/* ********************************************************************************* */

void ndpi_init_data_analysis(struct ndpi_analyze_struct *ret, u_int16_t _max_series_len) {
Expand Down Expand Up @@ -726,6 +728,7 @@ int ndpi_cluster_bins(struct ndpi_bin *bins, u_int16_t num_bins,
float *bin_score;
u_int16_t num_cluster_elems[MAX_NUM_CLUSTERS] = { 0 };

(void)out_buf;
srand(time(NULL));

if(!bins || num_bins == 0 || !cluster_ids || num_clusters == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ndpi_binary_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ bool ndpi_binary_bitmap_set(ndpi_binary_bitmap *b, u_int64_t value, u_int8_t cat
b->entries = rc, b->num_allocated_entries = new_len;
}

#ifdef PRINT_DUPLICATED_HASHS
if(value == 0)
printf("[add] ZERO hash !!!\n");
#endif

b->entries[b->num_used_entries].value = value,
b->entries[b->num_used_entries].category = category;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ndpi_classify.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "ndpi_classify.h"
#include "ndpi_includes.h"

#include "ndpi_replace_printf.h"

/** finds the minimum value between to inputs */
#ifndef min
#define min(a,b) \
Expand Down
Loading
Loading