1a90e161bSBill Fenner /* 2a90e161bSBill Fenner * Copyright (C) 2000, Richard Sharpe 3a90e161bSBill Fenner * 4a90e161bSBill Fenner * This software may be distributed either under the terms of the 53340d773SGleb Smirnoff * BSD-style license that accompanies tcpdump or under the GNU GPL 6a90e161bSBill Fenner * version 2 or later. 7a90e161bSBill Fenner * 8a90e161bSBill Fenner * print-beep.c 9a90e161bSBill Fenner * 10a90e161bSBill Fenner */ 11a90e161bSBill Fenner 123340d773SGleb Smirnoff /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */ 133340d773SGleb Smirnoff 14*ee67461eSJoseph Mingrone #include <config.h> 15a90e161bSBill Fenner 16*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 17a90e161bSBill Fenner 18a90e161bSBill Fenner #include <string.h> 19a90e161bSBill Fenner 203340d773SGleb Smirnoff #include "netdissect.h" 21a90e161bSBill Fenner 22a90e161bSBill Fenner /* Check for a string but not go beyond length 23a90e161bSBill Fenner * Return TRUE on match, FALSE otherwise 24a90e161bSBill Fenner * 25a90e161bSBill Fenner * Looks at the first few chars up to tl1 ... 26a90e161bSBill Fenner */ 27a90e161bSBill Fenner 28a90e161bSBill Fenner static int 290bff6a5aSEd Maste l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1, 300bff6a5aSEd Maste const char *str2, u_int l2) 31a90e161bSBill Fenner { 32*ee67461eSJoseph Mingrone if (!ND_TTEST_LEN(str2, tl1)) { 330bff6a5aSEd Maste /* 340bff6a5aSEd Maste * We don't have tl1 bytes worth of captured data 350bff6a5aSEd Maste * for the string, so we can't check for this 360bff6a5aSEd Maste * string. 370bff6a5aSEd Maste */ 380bff6a5aSEd Maste return 0; 390bff6a5aSEd Maste } 40a90e161bSBill Fenner if (tl1 > l2) 41a90e161bSBill Fenner return 0; 42a90e161bSBill Fenner 43a90e161bSBill Fenner return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0); 44a90e161bSBill Fenner } 45a90e161bSBill Fenner 46a90e161bSBill Fenner void 473c602fabSXin LI beep_print(netdissect_options *ndo, const u_char *bp, u_int length) 48a90e161bSBill Fenner { 49a90e161bSBill Fenner 50*ee67461eSJoseph Mingrone ndo->ndo_protocol = "beep"; 510bff6a5aSEd Maste if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */ 52*ee67461eSJoseph Mingrone ND_PRINT(" BEEP MSG"); 530bff6a5aSEd Maste else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length)) 54*ee67461eSJoseph Mingrone ND_PRINT(" BEEP RPY"); 550bff6a5aSEd Maste else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length)) 56*ee67461eSJoseph Mingrone ND_PRINT(" BEEP ERR"); 570bff6a5aSEd Maste else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length)) 58*ee67461eSJoseph Mingrone ND_PRINT(" BEEP ANS"); 590bff6a5aSEd Maste else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length)) 60*ee67461eSJoseph Mingrone ND_PRINT(" BEEP NUL"); 610bff6a5aSEd Maste else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length)) 62*ee67461eSJoseph Mingrone ND_PRINT(" BEEP SEQ"); 630bff6a5aSEd Maste else if (l_strnstart(ndo, "END", 4, (const char *)bp, length)) 64*ee67461eSJoseph Mingrone ND_PRINT(" BEEP END"); 65a90e161bSBill Fenner else 66*ee67461eSJoseph Mingrone ND_PRINT(" BEEP (payload or undecoded)"); 67a90e161bSBill Fenner } 68