1/*
2 * Copyright (C) 2000, Richard Sharpe
3 *
4 * This software may be distributed either under the terms of the
5 * BSD-style licence 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#if 0
15static const char rcsid[] _U_ =
16  "@(#) Header: /tcpdump/master/tcpdump/print-beep.c,v 1.6 2003-11-16 09:36:13 guy Exp";
17#else
18__RCSID("$NetBSD: print-beep.c,v 1.2 2010/12/05 05:11:30 christos Exp $");
19#endif
20#endif
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <tcpdump-stdinc.h>
27
28#ifdef HAVE_MEMORY_H
29#include <memory.h>
30#endif
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35#include "interface.h"
36#include "extract.h"
37
38/* Check for a string but not go beyond length
39 * Return TRUE on match, FALSE otherwise
40 *
41 * Looks at the first few chars up to tl1 ...
42 */
43
44static int l_strnstart(const char *, u_int, const char *, u_int);
45
46static int
47l_strnstart(const char *tstr1, u_int tl1, const char *str2, u_int l2)
48{
49
50	if (tl1 > l2)
51		return 0;
52
53	return (strncmp(tstr1, str2, tl1) == 0 ? 1 : 0);
54}
55
56void
57beep_print(const u_char *bp, u_int length)
58{
59
60	if (l_strnstart("MSG", 4, (const char *)bp, length)) /* A REQuest */
61		printf(" BEEP MSG");
62	else if (l_strnstart("RPY ", 4, (const char *)bp, length))
63		printf(" BEEP RPY");
64	else if (l_strnstart("ERR ", 4, (const char *)bp, length))
65		printf(" BEEP ERR");
66	else if (l_strnstart("ANS ", 4, (const char *)bp, length))
67		printf(" BEEP ANS");
68	else if (l_strnstart("NUL ", 4, (const char *)bp, length))
69		printf(" BEEP NUL");
70	else if (l_strnstart("SEQ ", 4, (const char *)bp, length))
71		printf(" BEEP SEQ");
72	else if (l_strnstart("END", 4, (const char *)bp, length))
73		printf(" BEEP END");
74	else
75		printf(" BEEP (payload or undecoded)");
76}
77