blob: 76017eaf89dc38161cc6db7a5dd50f1ec7a2c7dd [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (C) 2000, Richard Sharpe
3 *
4 * This software may be distributed either under the terms of the
Elliott Hughese2e3bd12017-05-15 10:59:29 -07005 * BSD-style license that accompanies tcpdump or under the GNU GPL
The Android Open Source Project2949f582009-03-03 19:30:46 -08006 * version 2 or later.
7 *
8 * print-beep.c
9 *
10 */
11
Elliott Hughese2e3bd12017-05-15 10:59:29 -070012/* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */
13
The Android Open Source Project2949f582009-03-03 19:30:46 -080014#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070015#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080016#endif
17
Elliott Hughes820eced2021-08-20 18:00:50 -070018#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080019
The Android Open Source Project2949f582009-03-03 19:30:46 -080020#include <string.h>
21
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080023
24/* Check for a string but not go beyond length
25 * Return TRUE on match, FALSE otherwise
26 *
27 * Looks at the first few chars up to tl1 ...
28 */
29
The Android Open Source Project2949f582009-03-03 19:30:46 -080030static int
Elliott Hughescec480a2017-12-19 16:54:57 -080031l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1,
32 const char *str2, u_int l2)
The Android Open Source Project2949f582009-03-03 19:30:46 -080033{
Elliott Hughes820eced2021-08-20 18:00:50 -070034 if (!ND_TTEST_LEN(str2, tl1)) {
Elliott Hughescec480a2017-12-19 16:54:57 -080035 /*
36 * We don't have tl1 bytes worth of captured data
37 * for the string, so we can't check for this
38 * string.
39 */
40 return 0;
41 }
The Android Open Source Project2949f582009-03-03 19:30:46 -080042 if (tl1 > l2)
43 return 0;
44
45 return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0);
46}
47
48void
Elliott Hughes892a68b2015-10-19 14:43:53 -070049beep_print(netdissect_options *ndo, const u_char *bp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -080050{
51
Elliott Hughes820eced2021-08-20 18:00:50 -070052 ndo->ndo_protocol = "beep";
Elliott Hughescec480a2017-12-19 16:54:57 -080053 if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */
Elliott Hughes820eced2021-08-20 18:00:50 -070054 ND_PRINT(" BEEP MSG");
Elliott Hughescec480a2017-12-19 16:54:57 -080055 else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length))
Elliott Hughes820eced2021-08-20 18:00:50 -070056 ND_PRINT(" BEEP RPY");
Elliott Hughescec480a2017-12-19 16:54:57 -080057 else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length))
Elliott Hughes820eced2021-08-20 18:00:50 -070058 ND_PRINT(" BEEP ERR");
Elliott Hughescec480a2017-12-19 16:54:57 -080059 else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length))
Elliott Hughes820eced2021-08-20 18:00:50 -070060 ND_PRINT(" BEEP ANS");
Elliott Hughescec480a2017-12-19 16:54:57 -080061 else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length))
Elliott Hughes820eced2021-08-20 18:00:50 -070062 ND_PRINT(" BEEP NUL");
Elliott Hughescec480a2017-12-19 16:54:57 -080063 else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length))
Elliott Hughes820eced2021-08-20 18:00:50 -070064 ND_PRINT(" BEEP SEQ");
Elliott Hughescec480a2017-12-19 16:54:57 -080065 else if (l_strnstart(ndo, "END", 4, (const char *)bp, length))
Elliott Hughes820eced2021-08-20 18:00:50 -070066 ND_PRINT(" BEEP END");
The Android Open Source Project2949f582009-03-03 19:30:46 -080067 else
Elliott Hughes820eced2021-08-20 18:00:50 -070068 ND_PRINT(" BEEP (payload or undecoded)");
The Android Open Source Project2949f582009-03-03 19:30:46 -080069}