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