aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss@ulticom.com>2008-05-20 21:51:01 +0000
committerJeff Morriss <jeff.morriss@ulticom.com>2008-05-20 21:51:01 +0000
commit58459d3fba39398b53294beccc307d539bd0db33 (patch)
tree7d78ccd8aad555faaf4ef91c0acc48b9a04ff2de /wsutil
parent5364227de00058969236206467448325f4c823b6 (diff)
Create a new "Wireshark utility" library and move the mpeg-audio stuff from
wiretap to this new libwsutil. This solves http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=1677 by making libwireshark no longer depend on libwiretap. svn path=/trunk/; revision=25330
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/Makefile.am46
-rw-r--r--wsutil/Makefile.nmake51
-rw-r--r--wsutil/libwsutil.def17
-rw-r--r--wsutil/mpeg-audio.c96
-rw-r--r--wsutil/mpeg-audio.h98
5 files changed, 308 insertions, 0 deletions
diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am
new file mode 100644
index 0000000000..f99671e773
--- /dev/null
+++ b/wsutil/Makefile.am
@@ -0,0 +1,46 @@
+# Makefile.am
+#
+# $Id$
+#
+# Wireshark - Network traffic analyzer
+# By Gerald Combs <gerald@wireshark.org>
+# Copyright 1998 Gerald Combs
+#
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if HAVE_WARNINGS_AS_ERRORS
+AM_CFLAGS = -Werror
+endif
+
+lib_LTLIBRARIES = libwsutil.la
+
+CLEANFILES = \
+ libwsutil.a \
+ libwsutil.la \
+ *~
+
+MAINTAINERCLEANFILES = \
+ Makefile.in
+
+libwsutil_la_SOURCES = \
+ mpeg-audio.c \
+ mpeg-audio.h
+
+libwsutil_la_LIBADD = @GLIB_LIBS@
+
+EXTRA_DIST = \
+ Makefile.nmake
+
diff --git a/wsutil/Makefile.nmake b/wsutil/Makefile.nmake
new file mode 100644
index 0000000000..1a275bfd64
--- /dev/null
+++ b/wsutil/Makefile.nmake
@@ -0,0 +1,51 @@
+## Makefile for building wireshark.exe with Microsoft C and nmake
+## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
+#
+# $Id$
+
+include ..\config.nmake
+include <win32.mak>
+include ..\Makefile.nmake.inc
+
+############### no need to modify below this line #########
+
+CFLAGS=-WX -DHAVE_CONFIG_H /I. /I.. $(GLIB_CFLAGS) \
+ /I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS)
+
+CVARSDLL=-DWIN32 -DNULL=0 -D_MT -D_DLL
+
+.c.obj::
+ $(CC) $(CVARSDLL) $(CFLAGS) -Fd.\ -c $<
+
+
+libwsutil_LIBS =
+
+OBJECTS = \
+ mpeg-audio.obj
+
+
+libwsutil.lib: libwsutil.dll
+libwsutil.exp: libwsutil.dll
+
+libwsutil.dll : $(OBJECTS) libwsutil.def ..\image\libwsutil.res
+ $(link) $(dlllflags) $(conlibsdll) \
+ $(LOCAL_LDFLAGS) \
+ /DEF:libwsutil.def /OUT:libwsutil.dll \
+ /IMPLIB:libwsutil.lib \
+ ..\image\libwsutil.res \
+ $(OBJECTS) $(libwsutil_LIBS)
+!IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20"
+ mt.exe -nologo -manifest "libwsutil.dll.manifest" -outputresource:libwsutil.dll;2
+!ENDIF
+
+clean :
+ rm -f $(OBJECTS) \
+ libwsutil.lib \
+ libwsutil.exp \
+ libwsutil.dll \
+ libwsutil.dll.manifest \
+ *.pdb
+
+distclean: clean
+
+maintainer-clean: distclean
diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def
new file mode 100644
index 0000000000..be1cd2822d
--- /dev/null
+++ b/wsutil/libwsutil.def
@@ -0,0 +1,17 @@
+; wsutil.def
+; $Id$
+
+; Add symbols that should be exported out of libwsutil.dll
+;
+; DATA symbols must be declared WS_VAR_IMPORT in the header file!
+;
+; NOTE: TABS DON'T WORK IN THIS FILE, USE SPACES INSTEAD!!!
+;
+EXPORTS
+
+mpa_bitrate
+mpa_frequency
+mpa_layer
+mpa_padding
+mpa_samples
+mpa_version
diff --git a/wsutil/mpeg-audio.c b/wsutil/mpeg-audio.c
new file mode 100644
index 0000000000..cca12be56b
--- /dev/null
+++ b/wsutil/mpeg-audio.c
@@ -0,0 +1,96 @@
+/* mpeg-audio.c
+ *
+ * MPEG Audio header dissection
+ * Written by Shaun Jackman <sjackman@gmail.com>
+ * Copyright 2007 Shaun Jackman
+ *
+ * $Id$
+ *
+ * Wiretap Library
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "mpeg-audio.h"
+
+static const int mpa_versions[4] = { 2, -1, 1, 0 };
+static const int mpa_layers[4] = { -1, 2, 1, 0 };
+
+static const unsigned mpa_samples_data[3][3] = {
+ { 384, 1152, 1152 },
+ { 384, 1152, 576 },
+ { 384, 1152, 576 },
+};
+
+static const unsigned mpa_bitrates[3][3][16] = { /* kb/s */
+ {
+ { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
+ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
+ { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 },
+ },
+ {
+ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
+ },
+ {
+ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
+ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
+ },
+};
+
+static const unsigned mpa_frequencies[3][4] = {
+ { 44100, 48000, 32000 },
+ { 22050, 24000, 16000 },
+ { 11025, 12000, 8000 },
+};
+
+static const unsigned mpa_padding_data[3] = { 4, 1, 1 };
+
+int
+mpa_version(const struct mpa *mpa)
+{
+ return mpa_versions[mpa->version];
+}
+
+int
+mpa_layer(const struct mpa *mpa)
+{
+ return mpa_layers[mpa->layer];
+}
+
+unsigned
+mpa_samples(const struct mpa *mpa)
+{
+ return mpa_samples_data[mpa_versions[mpa->version]][mpa_layer(mpa)];
+}
+
+unsigned
+mpa_bitrate(const struct mpa *mpa)
+{
+ return (1000 * (mpa_bitrates[mpa_versions[mpa->version]][mpa_layers[mpa->layer]][mpa->bitrate]));
+}
+
+unsigned
+mpa_frequency(const struct mpa *mpa)
+{
+ return(mpa_frequencies[mpa_versions[mpa->version]][mpa->frequency]);
+}
+
+unsigned
+mpa_padding(const struct mpa *mpa)
+{
+ return(mpa->padding ? mpa_padding_data[mpa_layers[mpa->layer]] : 0);
+}
diff --git a/wsutil/mpeg-audio.h b/wsutil/mpeg-audio.h
new file mode 100644
index 0000000000..d0dfd26da2
--- /dev/null
+++ b/wsutil/mpeg-audio.h
@@ -0,0 +1,98 @@
+/* mpeg-audio.h
+ *
+ * MPEG Audio header dissection
+ * Written by Shaun Jackman <sjackman@gmail.com>
+ * Copyright 2007 Shaun Jackman
+ *
+ * $Id$
+ *
+ * Wiretap Library
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef MPA_H
+#define MPA_H 1
+
+struct mpa {
+ unsigned emphasis :2;
+ unsigned original :1;
+ unsigned copyright :1;
+ unsigned modeext :2;
+ unsigned mode :2;
+ unsigned private :1;
+ unsigned padding :1;
+ unsigned frequency :2;
+ unsigned bitrate :4;
+ unsigned protection :1;
+ unsigned layer :2;
+ unsigned version :2;
+ unsigned sync :11;
+};
+
+#define MPA_UNMARSHAL_SYNC(n) ((n) >> 21 & 0x7ff)
+#define MPA_UNMARSHAL_VERSION(n) ((n) >> 19 & 0x3)
+#define MPA_UNMARSHAL_LAYER(n) ((n) >> 17 & 0x3)
+#define MPA_UNMARSHAL_PROTECTION(n) ((n) >> 16 & 0x1)
+#define MPA_UNMARSHAL_BITRATE(n) ((n) >> 12 & 0xf)
+#define MPA_UNMARSHAL_FREQUENCY(n) ((n) >> 10 & 0x3)
+#define MPA_UNMARSHAL_PADDING(n) ((n) >> 9 & 0x1)
+#define MPA_UNMARSHAL_PRIVATE(n) ((n) >> 8 & 0x1)
+#define MPA_UNMARSHAL_MODE(n) ((n) >> 6 & 0x3)
+#define MPA_UNMARSHAL_MODEEXT(n) ((n) >> 4 & 0x3)
+#define MPA_UNMARSHAL_COPYRIGHT(n) ((n) >> 3 & 0x1)
+#define MPA_UNMARSHAL_ORIGINAL(n) ((n) >> 2 & 0x1)
+#define MPA_UNMARSHAL_EMPHASIS(n) ((n) >> 0 & 0x3)
+
+#define MPA_UNMARSHAL(mpa, n) do { \
+ (mpa)->sync = MPA_UNMARSHAL_SYNC(n); \
+ (mpa)->version = MPA_UNMARSHAL_VERSION(n); \
+ (mpa)->layer = MPA_UNMARSHAL_LAYER(n); \
+ (mpa)->protection = MPA_UNMARSHAL_PROTECTION(n); \
+ (mpa)->bitrate = MPA_UNMARSHAL_BITRATE(n); \
+ (mpa)->frequency = MPA_UNMARSHAL_FREQUENCY(n); \
+ (mpa)->padding = MPA_UNMARSHAL_PADDING(n); \
+ (mpa)->private = MPA_UNMARSHAL_PRIVATE(n); \
+ (mpa)->mode = MPA_UNMARSHAL_MODE(n); \
+ (mpa)->modeext = MPA_UNMARSHAL_MODEEXT(n); \
+ (mpa)->copyright = MPA_UNMARSHAL_COPYRIGHT(n); \
+ (mpa)->original = MPA_UNMARSHAL_ORIGINAL(n); \
+ (mpa)->emphasis = MPA_UNMARSHAL_EMPHASIS(n); \
+ } while (0)
+
+int mpa_version(const struct mpa *);
+int mpa_layer(const struct mpa *);
+unsigned mpa_samples(const struct mpa *);
+unsigned mpa_bitrate(const struct mpa *);
+unsigned mpa_frequency(const struct mpa *);
+unsigned mpa_padding(const struct mpa *);
+
+#define MPA_DATA_BYTES(mpa) (mpa_bitrate(mpa) * mpa_samples(mpa) \
+ / mpa_frequency(mpa) / 8)
+#define MPA_BYTES(mpa) (MPA_DATA_BYTES(mpa) + mpa_padding(mpa))
+#define MPA_DURATION_NS(mpa) \
+ (1000000000 / mpa_frequency(mpa) * mpa_samples(mpa))
+
+enum { MPA_SYNC = 0x7ff };
+
+#define MPA_SYNC_VALID(mpa) ((mpa)->sync == MPA_SYNC)
+#define MPA_VERSION_VALID(mpa) (mpa_version(mpa) >= 0)
+#define MPA_LAYER_VALID(mpa) (mpa_layer(mpa) >= 0)
+#define MPA_BITRATE_VALID(mpa) (mpa_bitrate(mpa) > 0)
+#define MPA_FREQUENCY_VALID(mpa) (mpa_frequency(mpa) > 0)
+#define MPA_VALID(mpa) (MPA_SYNC_VALID(mpa) \
+ && MPA_VERSION_VALID(mpa) && MPA_LAYER_VALID(mpa) \
+ && MPA_BITRATE_VALID(mpa) && MPA_FREQUENCY_VALID(mpa))
+
+#endif