Merge commit '37e84ab74e939caf52150fc3352081786ecc0c29' into merges
[unleashed.git] / contrib / tcpdump / print-beep.c
blob64a162d7499192523344fd9337b392850bb4a33b
1 /*
2 * Copyright (C) 2000, Richard Sharpe
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.
8 * print-beep.c
12 /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
18 #include <netdissect-stdinc.h>
20 #include <string.h>
22 #include "netdissect.h"
24 /* Check for a string but not go beyond length
25 * Return TRUE on match, FALSE otherwise
27 * Looks at the first few chars up to tl1 ...
30 static int
31 l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1,
32 const char *str2, u_int l2)
34 if (!ND_TTEST2(*str2, tl1)) {
36 * We don't have tl1 bytes worth of captured data
37 * for the string, so we can't check for this
38 * string.
40 return 0;
42 if (tl1 > l2)
43 return 0;
45 return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0);
48 void
49 beep_print(netdissect_options *ndo, const u_char *bp, u_int length)
52 if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */
53 ND_PRINT((ndo, " BEEP MSG"));
54 else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length))
55 ND_PRINT((ndo, " BEEP RPY"));
56 else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length))
57 ND_PRINT((ndo, " BEEP ERR"));
58 else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length))
59 ND_PRINT((ndo, " BEEP ANS"));
60 else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length))
61 ND_PRINT((ndo, " BEEP NUL"));
62 else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length))
63 ND_PRINT((ndo, " BEEP SEQ"));
64 else if (l_strnstart(ndo, "END", 4, (const char *)bp, length))
65 ND_PRINT((ndo, " BEEP END"));
66 else
67 ND_PRINT((ndo, " BEEP (payload or undecoded)"));