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