xref: /minix/external/bsd/tcpdump/dist/print-beep.c (revision bb9622b5)
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 #include <sys/cdefs.h>
13 #ifndef lint
14 __RCSID("$NetBSD: print-beep.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
15 #endif
16 
17 #define NETDISSECT_REWORKED
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include <tcpdump-stdinc.h>
23 
24 #include <string.h>
25 
26 #include "interface.h"
27 
28 /* Check for a string but not go beyond length
29  * Return TRUE on match, FALSE otherwise
30  *
31  * Looks at the first few chars up to tl1 ...
32  */
33 
34 static int
35 l_strnstart(const char *tstr1, u_int tl1, const char *str2, u_int l2)
36 {
37 
38 	if (tl1 > l2)
39 		return 0;
40 
41 	return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0);
42 }
43 
44 void
45 beep_print(netdissect_options *ndo, const u_char *bp, u_int length)
46 {
47 
48 	if (l_strnstart("MSG", 4, (const char *)bp, length)) /* A REQuest */
49 		ND_PRINT((ndo, " BEEP MSG"));
50 	else if (l_strnstart("RPY ", 4, (const char *)bp, length))
51 		ND_PRINT((ndo, " BEEP RPY"));
52 	else if (l_strnstart("ERR ", 4, (const char *)bp, length))
53 		ND_PRINT((ndo, " BEEP ERR"));
54 	else if (l_strnstart("ANS ", 4, (const char *)bp, length))
55 		ND_PRINT((ndo, " BEEP ANS"));
56 	else if (l_strnstart("NUL ", 4, (const char *)bp, length))
57 		ND_PRINT((ndo, " BEEP NUL"));
58 	else if (l_strnstart("SEQ ", 4, (const char *)bp, length))
59 		ND_PRINT((ndo, " BEEP SEQ"));
60 	else if (l_strnstart("END", 4, (const char *)bp, length))
61 		ND_PRINT((ndo, " BEEP END"));
62 	else
63 		ND_PRINT((ndo, " BEEP (payload or undecoded)"));
64 }
65