The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2000, Richard Sharpe |
| 3 | * |
| 4 | * This software may be distributed either under the terms of the |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 5 | * BSD-style license that accompanies tcpdump or under the GNU GPL |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 6 | * version 2 or later. |
| 7 | * |
| 8 | * print-beep.c |
| 9 | * |
| 10 | */ |
| 11 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 12 | /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */ |
| 13 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 14 | #ifdef HAVE_CONFIG_H |
| 15 | #include "config.h" |
| 16 | #endif |
| 17 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 18 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 19 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 20 | #include <string.h> |
| 21 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 23 | |
| 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 Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 30 | static int |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 31 | l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1, |
| 32 | const char *str2, u_int l2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 34 | if (!ND_TTEST2(*str2, tl1)) { |
| 35 | /* |
| 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 Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 42 | if (tl1 > l2) |
| 43 | return 0; |
| 44 | |
| 45 | return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0); |
| 46 | } |
| 47 | |
| 48 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 49 | beep_print(netdissect_options *ndo, const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 50 | { |
| 51 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 52 | if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 53 | ND_PRINT((ndo, " BEEP MSG")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 54 | else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 55 | ND_PRINT((ndo, " BEEP RPY")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 56 | else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 57 | ND_PRINT((ndo, " BEEP ERR")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 58 | else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 59 | ND_PRINT((ndo, " BEEP ANS")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 60 | else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 61 | ND_PRINT((ndo, " BEEP NUL")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 62 | else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 63 | ND_PRINT((ndo, " BEEP SEQ")); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 64 | else if (l_strnstart(ndo, "END", 4, (const char *)bp, length)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 65 | ND_PRINT((ndo, " BEEP END")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 66 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 67 | ND_PRINT((ndo, " BEEP (payload or undecoded)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 68 | } |