Skip to content

Commit b9fca3e

Browse files
committed
Make ndpi_finalize_initialization() returns an error code
We should check if the initialization was fine or not
1 parent 1a801c4 commit b9fca3e

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

example/ndpiReader.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,7 @@ static void on_protocol_discovered(struct ndpi_workflow * workflow,
28172817
static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
28182818
NDPI_PROTOCOL_BITMASK enabled_bitmask;
28192819
struct ndpi_workflow_prefs prefs;
2820-
int i;
2820+
int i, ret;
28212821
ndpi_cfg_error rc;
28222822

28232823
memset(&prefs, 0, sizeof(prefs));
@@ -2917,8 +2917,11 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
29172917
cfgs[i].proto, cfgs[i].param, cfgs[i].value, rc);
29182918
}
29192919

2920-
2921-
ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct);
2920+
ret = ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct);
2921+
if(ret != 0) {
2922+
fprintf(stderr, "Error ndpi_finalize_initialization: %d\n", ret);
2923+
exit(-1);
2924+
}
29222925

29232926
if(enable_doh_dot_detection)
29242927
ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_pref_enable_tls_block_dissection, 1);

src/include/ndpi_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ extern "C" {
222222
*
223223
* @par ndpi_str = the struct created for the protocol detection
224224
*
225+
* @return 0 on success
226+
*
225227
*/
226-
void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str);
228+
int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str);
227229

228230
/**
229231
* Frees the dynamic memory allocated members in the specified flow

src/lib/ndpi_main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,13 +3510,13 @@ static void ndpi_add_domain_risk_exceptions(struct ndpi_detection_module_struct
35103510

35113511
/* *********************************************** */
35123512

3513-
void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) {
3513+
int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str) {
35143514
u_int i;
35153515

35163516
if(!ndpi_str)
3517-
return;
3517+
return -1;
35183518
if(ndpi_str->finalized) /* Already finalized */
3519-
return;
3519+
return 0;
35203520

35213521
ndpi_add_domain_risk_exceptions(ndpi_str);
35223522

@@ -3585,7 +3585,7 @@ void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)
35853585
}
35863586
}
35873587

3588-
if(ndpi_str->ac_automa_finalized) return;
3588+
if(ndpi_str->ac_automa_finalized) return -1;
35893589

35903590
ndpi_automa * const automa[] = { &ndpi_str->host_automa,
35913591
&ndpi_str->tls_cert_subject_automa,
@@ -3603,7 +3603,7 @@ void ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)
36033603

36043604
ndpi_str->finalized = 1;
36053605

3606-
return;
3606+
return 0;
36073607
}
36083608

36093609
/* *********************************************** */

0 commit comments

Comments
 (0)