aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2013-11-16 22:31:07 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2013-11-16 22:31:07 +0000
commit004220fb63d9c49f5ba389a7d80d0bbde14ba11f (patch)
tree21410e677f84ba94ab90afc1dab7c4866c9596cc
parent0e029166ba5f894893c06fba315e1a7340eef156 (diff)
Exporting/importing variables cause problems, so create function to do bitswaping.
svn path=/trunk/; revision=53374
-rw-r--r--epan/dissectors/packet-bmc.c7
-rw-r--r--epan/dissectors/packet-fddi.c7
-rw-r--r--epan/dissectors/packet-h223.c5
-rw-r--r--wsutil/bitswap.c10
-rw-r--r--wsutil/bitswap.h4
5 files changed, 16 insertions, 17 deletions
diff --git a/epan/dissectors/packet-bmc.c b/epan/dissectors/packet-bmc.c
index b70e2381ae..38217a64db 100644
--- a/epan/dissectors/packet-bmc.c
+++ b/epan/dissectors/packet-bmc.c
@@ -88,7 +88,7 @@ static int
dissect_bmc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
guint8 message_type;
- guint8 *p_rev, *reversing_buffer;
+ guint8 *reversing_buffer;
gint offset = 0;
gint i, len;
proto_item *ti;
@@ -104,10 +104,7 @@ dissect_bmc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
/* Needs bit-reversing. Create a new buffer, copy the message to it and bit-reverse */
len = tvb_length(tvb);
reversing_buffer = (guint8 *)tvb_memdup(NULL, tvb, offset, len);
- p_rev = reversing_buffer;
- /* Entire message is bit reversed */
- for (i=0; i<len; i++, p_rev++)
- *p_rev = BIT_SWAP(*p_rev);
+ bit_swap_buf_inplace(reversing_buffer, len);
/* Make this new buffer part of the display and provide a way to dispose of it */
bit_reversed_tvb = tvb_new_child_real_data(tvb, reversing_buffer, len, len);
diff --git a/epan/dissectors/packet-fddi.c b/epan/dissectors/packet-fddi.c
index c6347941cb..78671225f7 100644
--- a/epan/dissectors/packet-fddi.c
+++ b/epan/dissectors/packet-fddi.c
@@ -137,11 +137,8 @@ static dissector_handle_t data_handle;
static void
swap_mac_addr(guint8 *swapped_addr, tvbuff_t *tvb, gint offset)
{
- int i;
-
- for (i = 0; i < 6; i++) {
- swapped_addr[i] = BIT_SWAP(tvb_get_guint8(tvb, offset+i));
- }
+ tvb_memcpy(tvb, swapped_addr, offset, 6);
+ bit_swap_buf_inplace(swapped_addr, 6);
}
diff --git a/epan/dissectors/packet-h223.c b/epan/dissectors/packet-h223.c
index 078ee5fd48..0463013763 100644
--- a/epan/dissectors/packet-h223.c
+++ b/epan/dissectors/packet-h223.c
@@ -1370,9 +1370,8 @@ dissect_h223_bitswapped (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint i;
len = tvb_length(tvb);
- datax = (guint8 *)wmem_alloc(pinfo->pool, len);
- for( i=0; i<len; i++)
- datax[i]=BIT_SWAP(tvb_get_guint8(tvb,i));
+ datax = tvb_memdup(pinfo->pool, tvb, 0, len);
+ bit_swap_buf_inplace(datax, len);
/*
* Add the reversed tvbuff to the list of tvbuffs to which
diff --git a/wsutil/bitswap.c b/wsutil/bitswap.c
index 8e0fa657b7..ec387c5c8b 100644
--- a/wsutil/bitswap.c
+++ b/wsutil/bitswap.c
@@ -30,7 +30,7 @@
#include "bitswap.h"
/* "swaptab[i]" is the value of "i" with the bits reversed. */
-WS_DLL_PUBLIC_DEF const guint8 swaptab[256] =
+static const guint8 swaptab[256] =
{
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
@@ -65,3 +65,11 @@ WS_DLL_PUBLIC_DEF const guint8 swaptab[256] =
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
};
+
+void bit_swap_buf_inplace(guint8 *buf, size_t len)
+{
+ size_t i;
+
+ for (i = 0; i < len; i++)
+ buf[i] = swaptab[buf[i]];
+}
diff --git a/wsutil/bitswap.h b/wsutil/bitswap.h
index bbf374b01e..ad50ab5192 100644
--- a/wsutil/bitswap.h
+++ b/wsutil/bitswap.h
@@ -31,9 +31,7 @@
extern "C" {
#endif /* __cplusplus */
-WS_DLL_PUBLIC const guint8 swaptab[256];
-
-#define BIT_SWAP(b) (swaptab[b])
+WS_DLL_PUBLIC void bit_swap_buf_inplace(guint8 *buf, size_t len);
#ifdef __cplusplus
}