Exporting/importing variables cause problems, so create function to do bitswaping.

svn path=/trunk/; revision=53374
This commit is contained in:
Jakub Zawadzki 2013-11-16 22:31:07 +00:00
parent 0e029166ba
commit 004220fb63
5 changed files with 16 additions and 17 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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]];
}

View File

@ -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
}