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 /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */ 13 14 #include <config.h> 15 16 #include "netdissect-stdinc.h" 17 18 #include <string.h> 19 20 #include "netdissect.h" 21 22 /* Check for a string but not go beyond length 23 * Return TRUE on match, FALSE otherwise 24 * 25 * Looks at the first few chars up to tl1 ... 26 */ 27 28 static int 29 l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1, 30 const char *str2, u_int l2) 31 { 32 if (!ND_TTEST_LEN(str2, tl1)) { 33 /* 34 * We don't have tl1 bytes worth of captured data 35 * for the string, so we can't check for this 36 * string. 37 */ 38 return 0; 39 } 40 if (tl1 > l2) 41 return 0; 42 43 return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0); 44 } 45 46 void 47 beep_print(netdissect_options *ndo, const u_char *bp, u_int length) 48 { 49 50 ndo->ndo_protocol = "beep"; 51 if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */ 52 ND_PRINT(" BEEP MSG"); 53 else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length)) 54 ND_PRINT(" BEEP RPY"); 55 else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length)) 56 ND_PRINT(" BEEP ERR"); 57 else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length)) 58 ND_PRINT(" BEEP ANS"); 59 else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length)) 60 ND_PRINT(" BEEP NUL"); 61 else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length)) 62 ND_PRINT(" BEEP SEQ"); 63 else if (l_strnstart(ndo, "END", 4, (const char *)bp, length)) 64 ND_PRINT(" BEEP END"); 65 else 66 ND_PRINT(" BEEP (payload or undecoded)"); 67 } 68