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