print-beep.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2000, Richard Sharpe
  3. *
  4. * This software may be distributed either under the terms of the
  5. * BSD-style license that accompanies tcpdump or under the GNU GPL
  6. * version 2 or later.
  7. *
  8. * print-beep.c
  9. *
  10. */
  11. /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */
  12. #ifdef HAVE_CONFIG_H
  13. #include "config.h"
  14. #endif
  15. #include <netdissect-stdinc.h>
  16. #include <string.h>
  17. #include "netdissect.h"
  18. /* Check for a string but not go beyond length
  19. * Return TRUE on match, FALSE otherwise
  20. *
  21. * Looks at the first few chars up to tl1 ...
  22. */
  23. static int
  24. l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1,
  25. const char *str2, u_int l2)
  26. {
  27. if (!ND_TTEST2(*str2, tl1)) {
  28. /*
  29. * We don't have tl1 bytes worth of captured data
  30. * for the string, so we can't check for this
  31. * string.
  32. */
  33. return 0;
  34. }
  35. if (tl1 > l2)
  36. return 0;
  37. return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0);
  38. }
  39. void
  40. beep_print(netdissect_options *ndo, const u_char *bp, u_int length)
  41. {
  42. if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */
  43. ND_PRINT((ndo, " BEEP MSG"));
  44. else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length))
  45. ND_PRINT((ndo, " BEEP RPY"));
  46. else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length))
  47. ND_PRINT((ndo, " BEEP ERR"));
  48. else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length))
  49. ND_PRINT((ndo, " BEEP ANS"));
  50. else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length))
  51. ND_PRINT((ndo, " BEEP NUL"));
  52. else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length))
  53. ND_PRINT((ndo, " BEEP SEQ"));
  54. else if (l_strnstart(ndo, "END", 4, (const char *)bp, length))
  55. ND_PRINT((ndo, " BEEP END"));
  56. else
  57. ND_PRINT((ndo, " BEEP (payload or undecoded)"));
  58. }