141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (C) 2000, Richard Sharpe
341c99275SPeter Avalos *
441c99275SPeter Avalos * This software may be distributed either under the terms of the
5411677aeSAaron LI * BSD-style license that accompanies tcpdump or under the GNU GPL
641c99275SPeter Avalos * version 2 or later.
741c99275SPeter Avalos *
841c99275SPeter Avalos * print-beep.c
941c99275SPeter Avalos *
1041c99275SPeter Avalos */
1141c99275SPeter Avalos
12411677aeSAaron LI /* \summary: Blocks Extensible Exchange Protocol (BEEP) printer */
1341c99275SPeter Avalos
1441c99275SPeter Avalos #ifdef HAVE_CONFIG_H
15*ed775ee7SAntonio Huete Jimenez #include <config.h>
1641c99275SPeter Avalos #endif
1741c99275SPeter Avalos
18*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
1941c99275SPeter Avalos
2041c99275SPeter Avalos #include <string.h>
2141c99275SPeter Avalos
22411677aeSAaron LI #include "netdissect.h"
2341c99275SPeter Avalos
2441c99275SPeter Avalos /* Check for a string but not go beyond length
2541c99275SPeter Avalos * Return TRUE on match, FALSE otherwise
2641c99275SPeter Avalos *
2741c99275SPeter Avalos * Looks at the first few chars up to tl1 ...
2841c99275SPeter Avalos */
2941c99275SPeter Avalos
3041c99275SPeter Avalos static int
l_strnstart(netdissect_options * ndo,const char * tstr1,u_int tl1,const char * str2,u_int l2)31411677aeSAaron LI l_strnstart(netdissect_options *ndo, const char *tstr1, u_int tl1,
32411677aeSAaron LI const char *str2, u_int l2)
3341c99275SPeter Avalos {
34*ed775ee7SAntonio Huete Jimenez if (!ND_TTEST_LEN(str2, tl1)) {
35411677aeSAaron LI /*
36411677aeSAaron LI * We don't have tl1 bytes worth of captured data
37411677aeSAaron LI * for the string, so we can't check for this
38411677aeSAaron LI * string.
39411677aeSAaron LI */
40411677aeSAaron LI return 0;
41411677aeSAaron LI }
4241c99275SPeter Avalos if (tl1 > l2)
4341c99275SPeter Avalos return 0;
4441c99275SPeter Avalos
4541c99275SPeter Avalos return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0);
4641c99275SPeter Avalos }
4741c99275SPeter Avalos
4841c99275SPeter Avalos void
beep_print(netdissect_options * ndo,const u_char * bp,u_int length)49411677aeSAaron LI beep_print(netdissect_options *ndo, const u_char *bp, u_int length)
5041c99275SPeter Avalos {
5141c99275SPeter Avalos
52*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "beep";
53411677aeSAaron LI if (l_strnstart(ndo, "MSG", 4, (const char *)bp, length)) /* A REQuest */
54*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP MSG");
55411677aeSAaron LI else if (l_strnstart(ndo, "RPY ", 4, (const char *)bp, length))
56*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP RPY");
57411677aeSAaron LI else if (l_strnstart(ndo, "ERR ", 4, (const char *)bp, length))
58*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP ERR");
59411677aeSAaron LI else if (l_strnstart(ndo, "ANS ", 4, (const char *)bp, length))
60*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP ANS");
61411677aeSAaron LI else if (l_strnstart(ndo, "NUL ", 4, (const char *)bp, length))
62*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP NUL");
63411677aeSAaron LI else if (l_strnstart(ndo, "SEQ ", 4, (const char *)bp, length))
64*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP SEQ");
65411677aeSAaron LI else if (l_strnstart(ndo, "END", 4, (const char *)bp, length))
66*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP END");
6741c99275SPeter Avalos else
68*ed775ee7SAntonio Huete Jimenez ND_PRINT(" BEEP (payload or undecoded)");
6941c99275SPeter Avalos }
70