diff options
author | Mark Jeffery <dandare100@users.noreply.github.com> | 2024-06-19 13:47:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-19 13:47:18 +0200 |
commit | aa1d7247d1dc6572a63c02fa5cd0ef5e8692c8c9 (patch) | |
tree | 78ec68b298f4fef721b21419f7d21e692c4de3ec | |
parent | 9feede9a14e6a9669a8c5f490d7cc22583779f32 (diff) |
Added default port mappings to ndpiReader help -H (#2477)
Close #2125
-rw-r--r-- | example/ndpiReader.c | 4 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 43 |
2 files changed, 42 insertions, 5 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index ddcea4fd7..93b9f7640 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -709,8 +709,8 @@ static void help(u_int long_help) { sizeof(((struct ndpi_flow_struct *)0)->protos)); printf("\n\nnDPI supported protocols:\n"); - printf("%3s %8s %-22s %-10s %-8s %-12s %s\n", - "Id", "Userd-id", "Protocol", "Layer_4", "Nw_Proto", "Breed", "Category"); + printf("%3s %8s %-22s %-10s %-8s %-12s %-18s %-31s %-31s \n", + "Id", "Userd-id", "Protocol", "Layer_4", "Nw_Proto", "Breed", "Category","Def UDP Port/s","Def TCP Port/s"); num_threads = 1; ndpi_dump_protocols(ndpi_str, stdout); diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index a08a20650..1d3058d9f 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -9547,19 +9547,56 @@ int ndpi_get_category_id(struct ndpi_detection_module_struct *ndpi_str, char *ca /* ****************************************************** */ + +static char *default_ports_string(char *ports_str,u_int16_t *default_ports){ + + //dont display zero ports on help screen + if (default_ports[0] == 0) + //- for readability + return "-"; + + int j=0; + do + { + //max port len 5(eg 65535) + comma + nul + char port[7]; + sprintf(port,"%d,",default_ports[j]); + strcat(ports_str,port); + j++; + } while (j < MAX_DEFAULT_PORTS && default_ports[j]!= 0); + + //remove last comma + ports_str[strlen(ports_str)-1] = '\0'; + + return ports_str; + +} + +/* ****************************************************** */ + + void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str, FILE *dump_out) { int i; if(!ndpi_str || !dump_out) return; - for(i = 0; i < (int) ndpi_str->ndpi_num_supported_protocols; i++) - fprintf(dump_out, "%3d %8d %-22s %-10s %-8s %-12s %s\n", + for(i = 0; i < (int) ndpi_str->ndpi_num_supported_protocols; i++) { + //max port size(eg 65535) * 5 + 4 commas + nul + char udp_ports[30] = ""; + char tcp_ports[30] = ""; + + fprintf(dump_out, "%3d %8d %-22s %-10s %-8s %-12s %-18s %-31s %-31s\n", i, ndpi_map_ndpi_id_to_user_proto_id(ndpi_str, i), ndpi_str->proto_defaults[i].protoName, ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_str, i)), ndpi_str->proto_defaults[i].isAppProtocol ? "" : "X", ndpi_get_proto_breed_name(ndpi_str->proto_defaults[i].protoBreed), - ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory)); + ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory), + default_ports_string(udp_ports,ndpi_str->proto_defaults[i].udp_default_ports), + default_ports_string(tcp_ports,ndpi_str->proto_defaults[i].tcp_default_ports) + ); + + } } /* ********************************** */ |