You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.1 KiB

  1. From 6dcf1f3fbab782804339db5a3fe8cd0c88c07795 Mon Sep 17 00:00:00 2001
  2. From: lucaderi <deri@ntop.org>
  3. Date: Thu, 4 Oct 2018 21:36:46 +0200
  4. Subject: [PATCH 6/9] Backported ndpi_protocol2id
  5. ---
  6. src/include/ndpi_api.h | 17 +++++++++++++++--
  7. src/lib/ndpi_main.c | 17 +++++++++++++++++
  8. 2 files changed, 32 insertions(+), 2 deletions(-)
  9. diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
  10. index 56c5436..ccbad73 100644
  11. --- a/src/include/ndpi_api.h
  12. +++ b/src/include/ndpi_api.h
  13. @@ -274,7 +274,7 @@ extern "C" {
  14. */
  15. u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
  16. struct ndpi_flow_struct *flow);
  17. -
  18. +
  19. /**
  20. * API call that is called internally by ndpi_detection_process_packet or by apps
  21. * that want to avoid calling ndpi_detection_process_packet as they have already
  22. @@ -432,6 +432,19 @@ extern "C" {
  23. char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod,
  24. ndpi_protocol proto, char *buf, u_int buf_len);
  25. + /**
  26. + * Same as ndpi_protocol2name() with the difference that the numeric protocol
  27. + * name is returned
  28. + *
  29. + * @par ndpi_mod = the detection module
  30. + * @par proto = the struct ndpi_protocol contain the protocols name
  31. + * @par buf = the buffer to write the name of the protocols
  32. + * @par buf_len = the length of the buffer
  33. + * @return the buffer contains the master_protocol and protocol name
  34. + *
  35. + */
  36. + char* ndpi_protocol2id(struct ndpi_detection_module_struct *ndpi_mod,
  37. + ndpi_protocol proto, char *buf, u_int buf_len);
  38. /**
  39. * Write the protocol name in the buffer -buf- as master_protocol.protocol (number)
  40. *
  41. @@ -746,7 +759,7 @@ extern "C" {
  42. u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
  43. u_int ndpi_get_ndpi_detection_module_size();
  44. void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
  45. -
  46. +
  47. /**
  48. * Add a string to match to an automata
  49. *
  50. diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
  51. index 33ccbb1..e1cf577 100644
  52. --- a/src/lib/ndpi_main.c
  53. +++ b/src/lib/ndpi_main.c
  54. @@ -5319,6 +5319,23 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
  55. /* ****************************************************** */
  56. +char* ndpi_protocol2id(struct ndpi_detection_module_struct *ndpi_mod,
  57. + ndpi_protocol proto, char *buf, u_int buf_len) {
  58. + if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN)
  59. + && (proto.master_protocol != proto.app_protocol)) {
  60. + if(proto.app_protocol != NDPI_PROTOCOL_UNKNOWN)
  61. + snprintf(buf, buf_len, "%u.%u",
  62. + proto.master_protocol, proto.app_protocol);
  63. + else
  64. + snprintf(buf, buf_len, "%u", proto.master_protocol);
  65. + } else
  66. + snprintf(buf, buf_len, "%u", proto.app_protocol);
  67. +
  68. + return(buf);
  69. +}
  70. +
  71. +/* ****************************************************** */
  72. +
  73. char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod,
  74. ndpi_protocol proto, char *buf, u_int buf_len) {
  75. if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN)
  76. --
  77. 2.19.1