PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/ui/cli/tap-ansi_astat.c

https://github.com/labx-technologies-llc/wireshark
C | 160 lines | 97 code | 32 blank | 31 comment | 7 complexity | 231ec194557b5a0ba084b0aa4ef4072b MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. /* tap-ansi_astat.c
  2. *
  3. * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
  4. * In association with Telos Technology Inc.
  5. *
  6. * $Id$
  7. *
  8. * Wireshark - Network traffic analyzer
  9. * By Gerald Combs <gerald@wireshark.org>
  10. * Copyright 1998 Gerald Combs
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  25. */
  26. /*
  27. * This TAP provides statistics for the ANSI A Interface:
  28. */
  29. #include "config.h"
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include "epan/packet_info.h"
  33. #include "epan/value_string.h"
  34. #include <epan/tap.h>
  35. #include <epan/stat_cmd_args.h>
  36. #include <epan/dissectors/packet-bssap.h>
  37. #include <epan/dissectors/packet-ansi_a.h>
  38. typedef struct _ansi_a_stat_t {
  39. int bsmap_message_type[0xff];
  40. int dtap_message_type[0xff];
  41. } ansi_a_stat_t;
  42. static int
  43. ansi_a_stat_packet(
  44. void *tapdata,
  45. packet_info *pinfo _U_,
  46. epan_dissect_t *edt _U_,
  47. const void *data)
  48. {
  49. ansi_a_stat_t *stat_p = (ansi_a_stat_t *)tapdata;
  50. const ansi_a_tap_rec_t *tap_p = (const ansi_a_tap_rec_t *)data;
  51. switch (tap_p->pdu_type)
  52. {
  53. case BSSAP_PDU_TYPE_BSMAP:
  54. stat_p->bsmap_message_type[tap_p->message_type]++;
  55. break;
  56. case BSSAP_PDU_TYPE_DTAP:
  57. stat_p->dtap_message_type[tap_p->message_type]++;
  58. break;
  59. default:
  60. /*
  61. * unknown PDU type !!!
  62. */
  63. return(0);
  64. }
  65. return(1);
  66. }
  67. static void
  68. ansi_a_stat_draw(
  69. void *tapdata)
  70. {
  71. ansi_a_stat_t *stat_p = (ansi_a_stat_t *)tapdata;
  72. guint8 i;
  73. printf("\n");
  74. printf("=========== ANSI A-i/f Statistics ============================\n");
  75. printf("BSMAP\n");
  76. printf("Message (ID)Type Number\n");
  77. i = 0;
  78. while (ansi_a_ios401_bsmap_strings[i].strptr)
  79. {
  80. if (stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value] > 0)
  81. {
  82. printf("0x%02x %-50s%d\n",
  83. ansi_a_ios401_bsmap_strings[i].value,
  84. ansi_a_ios401_bsmap_strings[i].strptr,
  85. stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value]);
  86. }
  87. i++;
  88. }
  89. printf("\nDTAP\n");
  90. printf("Message (ID)Type Number\n");
  91. i = 0;
  92. while (ansi_a_ios401_dtap_strings[i].strptr)
  93. {
  94. if (stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value] > 0)
  95. {
  96. printf("0x%02x %-50s%d\n",
  97. ansi_a_ios401_dtap_strings[i].value,
  98. ansi_a_ios401_dtap_strings[i].strptr,
  99. stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value]);
  100. }
  101. i++;
  102. }
  103. printf("==============================================================\n");
  104. }
  105. static void
  106. ansi_a_stat_init(const char *opt_arg _U_, void* userdata _U_)
  107. {
  108. ansi_a_stat_t *stat_p;
  109. GString *err_p;
  110. stat_p = (ansi_a_stat_t *)g_malloc(sizeof(ansi_a_stat_t));
  111. memset(stat_p, 0, sizeof(ansi_a_stat_t));
  112. err_p =
  113. register_tap_listener("ansi_a", stat_p, NULL, 0,
  114. NULL,
  115. ansi_a_stat_packet,
  116. ansi_a_stat_draw);
  117. if (err_p != NULL)
  118. {
  119. g_free(stat_p);
  120. g_string_free(err_p, TRUE);
  121. exit(1);
  122. }
  123. }
  124. void
  125. register_tap_listener_ansi_astat(void)
  126. {
  127. register_stat_cmd_arg("ansi_a,", ansi_a_stat_init,NULL);
  128. }