Replace macros: BSWAP16, BSWAP32, BSWAP64 with glib-version.

XXX, people are not aware that expression of this macros might be evaluated multiple times, like:
 -  BSWAP16(tvb_get_letohs(tvb, off)) : \
 +  GUINT16_SWAP_LE_BE(tvb_get_letohs(tvb, off)) : \

Should be tvb_get_ntohs() called?


svn path=/trunk/; revision=53653
This commit is contained in:
Jakub Zawadzki 2013-11-29 19:21:20 +00:00
parent 5ac6474c94
commit d99fdfda63
9 changed files with 77 additions and 110 deletions

View File

@ -70,7 +70,6 @@
#include <errno.h> #include <errno.h>
#include <wsutil/crash_info.h> #include <wsutil/crash_info.h>
#include <wsutil/pint.h>
#ifndef HAVE_GETOPT #ifndef HAVE_GETOPT
#include "wsutil/wsgetopt.h" #include "wsutil/wsgetopt.h"
@ -1694,10 +1693,10 @@ cap_pipe_adjust_header(gboolean byte_swapped, struct pcap_hdr *hdr, struct pcapr
{ {
if (byte_swapped) { if (byte_swapped) {
/* Byte-swap the record header fields. */ /* Byte-swap the record header fields. */
rechdr->ts_sec = BSWAP32(rechdr->ts_sec); rechdr->ts_sec = GUINT32_SWAP_LE_BE(rechdr->ts_sec);
rechdr->ts_usec = BSWAP32(rechdr->ts_usec); rechdr->ts_usec = GUINT32_SWAP_LE_BE(rechdr->ts_usec);
rechdr->incl_len = BSWAP32(rechdr->incl_len); rechdr->incl_len = GUINT32_SWAP_LE_BE(rechdr->incl_len);
rechdr->orig_len = BSWAP32(rechdr->orig_len); rechdr->orig_len = GUINT32_SWAP_LE_BE(rechdr->orig_len);
} }
/* In file format version 2.3, the "incl_len" and "orig_len" fields were /* In file format version 2.3, the "incl_len" and "orig_len" fields were
@ -2278,10 +2277,10 @@ cap_pipe_open_live(char *pipename,
if (pcap_opts->cap_pipe_byte_swapped) { if (pcap_opts->cap_pipe_byte_swapped) {
/* Byte-swap the header fields about which we care. */ /* Byte-swap the header fields about which we care. */
hdr->version_major = BSWAP16(hdr->version_major); hdr->version_major = GUINT16_SWAP_LE_BE(hdr->version_major);
hdr->version_minor = BSWAP16(hdr->version_minor); hdr->version_minor = GUINT16_SWAP_LE_BE(hdr->version_minor);
hdr->snaplen = BSWAP32(hdr->snaplen); hdr->snaplen = GUINT32_SWAP_LE_BE(hdr->snaplen);
hdr->network = BSWAP32(hdr->network); hdr->network = GUINT32_SWAP_LE_BE(hdr->network);
} }
pcap_opts->linktype = hdr->network; pcap_opts->linktype = hdr->network;

View File

@ -251,7 +251,7 @@ typedef struct mimo_control
* must be valid variables. * must be valid variables.
*/ */
#define FETCH_FCF(off) (wlan_broken_fc ? \ #define FETCH_FCF(off) (wlan_broken_fc ? \
BSWAP16(tvb_get_letohs(tvb, off)) : \ GUINT16_SWAP_LE_BE(tvb_get_letohs(tvb, off)) : \
tvb_get_letohs(tvb, off)) tvb_get_letohs(tvb, off))
/* /*

View File

@ -29,8 +29,6 @@
#include <glib.h> #include <glib.h>
#include <string.h> #include <string.h>
#include <wsutil/pint.h>
#include <epan/packet.h> #include <epan/packet.h>
#include "packet-null.h" #include "packet-null.h"
#include <epan/atalk-utils.h> #include <epan/atalk-utils.h>
@ -294,7 +292,7 @@ capture_null( const guchar *pd, int len, packet_counts *ld )
null_header >>= 16; null_header >>= 16;
} else { } else {
/* Byte-swap it. */ /* Byte-swap it. */
null_header = BSWAP32(null_header); null_header = GUINT32_SWAP_LE_BE(null_header);
} }
} else { } else {
/* /*
@ -308,7 +306,7 @@ capture_null( const guchar *pd, int len, packet_counts *ld )
* type; that's in the lower 16 bits of "null_header", but * type; that's in the lower 16 bits of "null_header", but
* is byte-swapped. * is byte-swapped.
*/ */
null_header = BSWAP16(null_header & 0xFFFF); null_header = GUINT16_SWAP_LE_BE(null_header & 0xFFFF);
} }
} }
@ -394,7 +392,7 @@ dissect_null(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
null_header >>= 16; null_header >>= 16;
} else { } else {
/* Byte-swap it. */ /* Byte-swap it. */
null_header = BSWAP32(null_header); null_header = GUINT32_SWAP_LE_BE(null_header);
} }
} else { } else {
/* /*
@ -408,7 +406,7 @@ dissect_null(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
* type; that's in the lower 16 bits of "null_header", but * type; that's in the lower 16 bits of "null_header", but
* is byte-swapped. * is byte-swapped.
*/ */
null_header = BSWAP16(null_header & 0xFFFF); null_header = GUINT16_SWAP_LE_BE(null_header & 0xFFFF);
} }
} }

View File

@ -117,7 +117,7 @@ int csids_open(wtap *wth, int *err, gchar **err_info)
/* maybe this is just a byteswapped version. the iplen ipflags */ /* maybe this is just a byteswapped version. the iplen ipflags */
/* and ipid are swapped. We cannot use the normal swaps because */ /* and ipid are swapped. We cannot use the normal swaps because */
/* we don't know the host */ /* we don't know the host */
iplen = BSWAP16(iplen); iplen = GUINT16_SWAP_LE_BE(iplen);
if( iplen <= hdr.caplen ) { if( iplen <= hdr.caplen ) {
/* we know this format */ /* we know this format */
byteswap = TRUE; byteswap = TRUE;

View File

@ -73,11 +73,11 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info)
/* /*
* OK, try byte-swapping the header fields. * OK, try byte-swapping the header fields.
*/ */
hdr.length = BSWAP32(hdr.length); hdr.length = GUINT32_SWAP_LE_BE(hdr.length);
hdr.unit = BSWAP32(hdr.unit); hdr.unit = GUINT32_SWAP_LE_BE(hdr.unit);
hdr.type = BSWAP32(hdr.type); hdr.type = GUINT32_SWAP_LE_BE(hdr.type);
hdr.dir = BSWAP32(hdr.dir); hdr.dir = GUINT32_SWAP_LE_BE(hdr.dir);
hdr.trunc = BSWAP32(hdr.trunc); hdr.trunc = GUINT32_SWAP_LE_BE(hdr.trunc);
if (!I4B_HDR_IS_OK(hdr)) { if (!I4B_HDR_IS_OK(hdr)) {
/* /*
* It doesn't look valid in either byte order. * It doesn't look valid in either byte order.
@ -164,14 +164,14 @@ i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
/* /*
* Byte-swap the header. * Byte-swap the header.
*/ */
hdr.length = BSWAP32(hdr.length); hdr.length = GUINT32_SWAP_LE_BE(hdr.length);
hdr.unit = BSWAP32(hdr.unit); hdr.unit = GUINT32_SWAP_LE_BE(hdr.unit);
hdr.type = BSWAP32(hdr.type); hdr.type = GUINT32_SWAP_LE_BE(hdr.type);
hdr.dir = BSWAP32(hdr.dir); hdr.dir = GUINT32_SWAP_LE_BE(hdr.dir);
hdr.trunc = BSWAP32(hdr.trunc); hdr.trunc = GUINT32_SWAP_LE_BE(hdr.trunc);
hdr.count = BSWAP32(hdr.count); hdr.count = GUINT32_SWAP_LE_BE(hdr.count);
hdr.ts_sec = BSWAP32(hdr.ts_sec); hdr.ts_sec = GUINT32_SWAP_LE_BE(hdr.ts_sec);
hdr.ts_usec = BSWAP32(hdr.ts_usec); hdr.ts_usec = GUINT32_SWAP_LE_BE(hdr.ts_usec);
} }
if (hdr.length < sizeof(hdr)) { if (hdr.length < sizeof(hdr)) {

View File

@ -172,10 +172,10 @@ int libpcap_open(wtap *wth, int *err, gchar **err_info)
if (byte_swapped) { if (byte_swapped) {
/* Byte-swap the header fields about which we care. */ /* Byte-swap the header fields about which we care. */
hdr.version_major = BSWAP16(hdr.version_major); hdr.version_major = GUINT16_SWAP_LE_BE(hdr.version_major);
hdr.version_minor = BSWAP16(hdr.version_minor); hdr.version_minor = GUINT16_SWAP_LE_BE(hdr.version_minor);
hdr.snaplen = BSWAP32(hdr.snaplen); hdr.snaplen = GUINT32_SWAP_LE_BE(hdr.snaplen);
hdr.network = BSWAP32(hdr.network); hdr.network = GUINT32_SWAP_LE_BE(hdr.network);
} }
if (hdr.version_major < 2) { if (hdr.version_major < 2) {
/* We only support version 2.0 and later. */ /* We only support version 2.0 and later. */
@ -792,10 +792,10 @@ adjust_header(wtap *wth, struct pcaprec_hdr *hdr)
libpcap = (libpcap_t *)wth->priv; libpcap = (libpcap_t *)wth->priv;
if (libpcap->byte_swapped) { if (libpcap->byte_swapped) {
/* Byte-swap the record header fields. */ /* Byte-swap the record header fields. */
hdr->ts_sec = BSWAP32(hdr->ts_sec); hdr->ts_sec = GUINT32_SWAP_LE_BE(hdr->ts_sec);
hdr->ts_usec = BSWAP32(hdr->ts_usec); hdr->ts_usec = GUINT32_SWAP_LE_BE(hdr->ts_usec);
hdr->incl_len = BSWAP32(hdr->incl_len); hdr->incl_len = GUINT32_SWAP_LE_BE(hdr->incl_len);
hdr->orig_len = BSWAP32(hdr->orig_len); hdr->orig_len = GUINT32_SWAP_LE_BE(hdr->orig_len);
} }
/* Swap the "incl_len" and "orig_len" fields, if necessary. */ /* Swap the "incl_len" and "orig_len" fields, if necessary. */

View File

@ -407,8 +407,8 @@ pcapng_read_option(FILE_T fh, pcapng_t *pn, pcapng_option_header_t *oh,
} }
block_read = sizeof (*oh); block_read = sizeof (*oh);
if (pn->byte_swapped) { if (pn->byte_swapped) {
oh->option_code = BSWAP16(oh->option_code); oh->option_code = GUINT16_SWAP_LE_BE(oh->option_code);
oh->option_length = BSWAP16(oh->option_length); oh->option_length = GUINT16_SWAP_LE_BE(oh->option_length);
} }
/* sanity check: don't run past the end of the block */ /* sanity check: don't run past the end of the block */
@ -519,11 +519,11 @@ pcapng_read_section_header_block(FILE_T fh, gboolean first_block,
case(0x4D3C2B1A): case(0x4D3C2B1A):
/* this seems pcapng with swapped byte order */ /* this seems pcapng with swapped byte order */
pn->byte_swapped = TRUE; pn->byte_swapped = TRUE;
pn->version_major = BSWAP16(shb.version_major); pn->version_major = GUINT16_SWAP_LE_BE(shb.version_major);
pn->version_minor = BSWAP16(shb.version_minor); pn->version_minor = GUINT16_SWAP_LE_BE(shb.version_minor);
/* tweak the block length to meet current swapping that we know now */ /* tweak the block length to meet current swapping that we know now */
bh->block_total_length = BSWAP32(bh->block_total_length); bh->block_total_length = GUINT32_SWAP_LE_BE(bh->block_total_length);
pcapng_debug3("pcapng_read_section_header_block: SHB (big endian) V%u.%u, len %u", pcapng_debug3("pcapng_read_section_header_block: SHB (big endian) V%u.%u, len %u",
pn->version_major, pn->version_minor, bh->block_total_length); pn->version_major, pn->version_minor, bh->block_total_length);
@ -576,7 +576,7 @@ pcapng_read_section_header_block(FILE_T fh, gboolean first_block,
/* 64bit section_length (currently unused) */ /* 64bit section_length (currently unused) */
if (pn->byte_swapped) { if (pn->byte_swapped) {
wblock->data.section.section_length = BSWAP64(shb.section_length); wblock->data.section.section_length = GUINT64_SWAP_LE_BE(shb.section_length);
} else { } else {
wblock->data.section.section_length = shb.section_length; wblock->data.section.section_length = shb.section_length;
} }
@ -717,8 +717,8 @@ pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn,
/* mandatory values */ /* mandatory values */
if (pn->byte_swapped) { if (pn->byte_swapped) {
wblock->data.if_descr.link_type = BSWAP16(idb.linktype); wblock->data.if_descr.link_type = GUINT16_SWAP_LE_BE(idb.linktype);
wblock->data.if_descr.snap_len = BSWAP32(idb.snaplen); wblock->data.if_descr.snap_len = GUINT32_SWAP_LE_BE(idb.snaplen);
} else { } else {
wblock->data.if_descr.link_type = idb.linktype; wblock->data.if_descr.link_type = idb.linktype;
wblock->data.if_descr.snap_len = idb.snaplen; wblock->data.if_descr.snap_len = idb.snaplen;
@ -828,7 +828,7 @@ pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn,
*/ */
memcpy(&wblock->data.if_descr.if_speed, option_content, sizeof(guint64)); memcpy(&wblock->data.if_descr.if_speed, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->data.if_descr.if_speed = BSWAP64(wblock->data.if_descr.if_speed); wblock->data.if_descr.if_speed = GUINT64_SWAP_LE_BE(wblock->data.if_descr.if_speed);
pcapng_debug1("pcapng_read_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", wblock->data.if_descr.if_speed); pcapng_debug1("pcapng_read_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", wblock->data.if_descr.if_speed);
} else { } else {
pcapng_debug1("pcapng_read_if_descr_block: if_speed length %u not 8 as expected", oh.option_length); pcapng_debug1("pcapng_read_if_descr_block: if_speed length %u not 8 as expected", oh.option_length);
@ -993,12 +993,12 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
block_read = bytes_read; block_read = bytes_read;
if (pn->byte_swapped) { if (pn->byte_swapped) {
packet.interface_id = BSWAP32(epb.interface_id); packet.interface_id = GUINT32_SWAP_LE_BE(epb.interface_id);
packet.drops_count = -1; /* invalid */ packet.drops_count = -1; /* invalid */
packet.ts_high = BSWAP32(epb.timestamp_high); packet.ts_high = GUINT32_SWAP_LE_BE(epb.timestamp_high);
packet.ts_low = BSWAP32(epb.timestamp_low); packet.ts_low = GUINT32_SWAP_LE_BE(epb.timestamp_low);
packet.cap_len = BSWAP32(epb.captured_len); packet.cap_len = GUINT32_SWAP_LE_BE(epb.captured_len);
packet.packet_len = BSWAP32(epb.packet_len); packet.packet_len = GUINT32_SWAP_LE_BE(epb.packet_len);
} else { } else {
packet.interface_id = epb.interface_id; packet.interface_id = epb.interface_id;
packet.drops_count = -1; /* invalid */ packet.drops_count = -1; /* invalid */
@ -1031,12 +1031,12 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
block_read = bytes_read; block_read = bytes_read;
if (pn->byte_swapped) { if (pn->byte_swapped) {
packet.interface_id = BSWAP16(pb.interface_id); packet.interface_id = GUINT16_SWAP_LE_BE(pb.interface_id);
packet.drops_count = BSWAP16(pb.drops_count); packet.drops_count = GUINT16_SWAP_LE_BE(pb.drops_count);
packet.ts_high = BSWAP32(pb.timestamp_high); packet.ts_high = GUINT32_SWAP_LE_BE(pb.timestamp_high);
packet.ts_low = BSWAP32(pb.timestamp_low); packet.ts_low = GUINT32_SWAP_LE_BE(pb.timestamp_low);
packet.cap_len = BSWAP32(pb.captured_len); packet.cap_len = GUINT32_SWAP_LE_BE(pb.captured_len);
packet.packet_len = BSWAP32(pb.packet_len); packet.packet_len = GUINT32_SWAP_LE_BE(pb.packet_len);
} else { } else {
packet.interface_id = pb.interface_id; packet.interface_id = pb.interface_id;
packet.drops_count = pb.drops_count; packet.drops_count = pb.drops_count;
@ -1235,7 +1235,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
wblock->packet_header->presence_flags |= WTAP_HAS_PACK_FLAGS; wblock->packet_header->presence_flags |= WTAP_HAS_PACK_FLAGS;
memcpy(&wblock->packet_header->pack_flags, option_content, sizeof(guint32)); memcpy(&wblock->packet_header->pack_flags, option_content, sizeof(guint32));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->packet_header->pack_flags = BSWAP32(wblock->packet_header->pack_flags); wblock->packet_header->pack_flags = GUINT32_SWAP_LE_BE(wblock->packet_header->pack_flags);
if (wblock->packet_header->pack_flags & 0x000001E0) { if (wblock->packet_header->pack_flags & 0x000001E0) {
/* The FCS length is present */ /* The FCS length is present */
fcslen = (wblock->packet_header->pack_flags & 0x000001E0) >> 5; fcslen = (wblock->packet_header->pack_flags & 0x000001E0) >> 5;
@ -1257,7 +1257,7 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, wta
wblock->packet_header->presence_flags |= WTAP_HAS_DROP_COUNT; wblock->packet_header->presence_flags |= WTAP_HAS_DROP_COUNT;
memcpy(&wblock->packet_header->drop_count, option_content, sizeof(guint64)); memcpy(&wblock->packet_header->drop_count, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->packet_header->drop_count = BSWAP64(wblock->packet_header->drop_count); wblock->packet_header->drop_count = GUINT64_SWAP_LE_BE(wblock->packet_header->drop_count);
pcapng_debug1("pcapng_read_packet_block: drop_count %" G_GINT64_MODIFIER "u", wblock->packet_header->drop_count); pcapng_debug1("pcapng_read_packet_block: drop_count %" G_GINT64_MODIFIER "u", wblock->packet_header->drop_count);
} else { } else {
@ -1340,7 +1340,7 @@ pcapng_read_simple_packet_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *
int_data = g_array_index(pn->interface_data, interface_data_t, 0); int_data = g_array_index(pn->interface_data, interface_data_t, 0);
if (pn->byte_swapped) { if (pn->byte_swapped) {
simple_packet.packet_len = BSWAP32(spb.packet_len); simple_packet.packet_len = GUINT32_SWAP_LE_BE(spb.packet_len);
} else { } else {
simple_packet.packet_len = spb.packet_len; simple_packet.packet_len = spb.packet_len;
} }
@ -1577,8 +1577,8 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t
block_read += bytes_read; block_read += bytes_read;
if (pn->byte_swapped) { if (pn->byte_swapped) {
nrb.record_type = BSWAP16(nrb.record_type); nrb.record_type = GUINT16_SWAP_LE_BE(nrb.record_type);
nrb.record_len = BSWAP16(nrb.record_len); nrb.record_len = GUINT16_SWAP_LE_BE(nrb.record_len);
} }
if (to_read - block_read < nrb.record_len + PADDING4(nrb.record_len)) { if (to_read - block_read < nrb.record_len + PADDING4(nrb.record_len)) {
@ -1635,7 +1635,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t
memcpy(&v4_addr, memcpy(&v4_addr,
buffer_start_ptr(&nrb_rec), 4); buffer_start_ptr(&nrb_rec), 4);
if (pn->byte_swapped) if (pn->byte_swapped)
v4_addr = BSWAP32(v4_addr); v4_addr = GUINT32_SWAP_LE_BE(v4_addr);
for (namep = (char *)buffer_start_ptr(&nrb_rec) + 4, record_len = nrb.record_len - 4; for (namep = (char *)buffer_start_ptr(&nrb_rec) + 4, record_len = nrb.record_len - 4;
record_len != 0; record_len != 0;
namep += namelen, record_len -= namelen) { namep += namelen, record_len -= namelen) {
@ -1793,9 +1793,9 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
block_read = bytes_read; block_read = bytes_read;
if (pn->byte_swapped) { if (pn->byte_swapped) {
wblock->data.if_stats.interface_id = BSWAP32(isb.interface_id); wblock->data.if_stats.interface_id = GUINT32_SWAP_LE_BE(isb.interface_id);
wblock->data.if_stats.ts_high = BSWAP32(isb.timestamp_high); wblock->data.if_stats.ts_high = GUINT32_SWAP_LE_BE(isb.timestamp_high);
wblock->data.if_stats.ts_low = BSWAP32(isb.timestamp_low); wblock->data.if_stats.ts_low = GUINT32_SWAP_LE_BE(isb.timestamp_low);
} else { } else {
wblock->data.if_stats.interface_id = isb.interface_id; wblock->data.if_stats.interface_id = isb.interface_id;
wblock->data.if_stats.ts_high = isb.timestamp_high; wblock->data.if_stats.ts_high = isb.timestamp_high;
@ -1861,8 +1861,8 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
memcpy(&high, option_content, sizeof(guint32)); memcpy(&high, option_content, sizeof(guint32));
memcpy(&low, option_content + sizeof(guint32), sizeof(guint32)); memcpy(&low, option_content + sizeof(guint32), sizeof(guint32));
if (pn->byte_swapped) { if (pn->byte_swapped) {
high = BSWAP32(high); high = GUINT32_SWAP_LE_BE(high);
low = BSWAP32(low); low = GUINT32_SWAP_LE_BE(low);
} }
wblock->data.if_stats.isb_starttime = (guint64)high; wblock->data.if_stats.isb_starttime = (guint64)high;
wblock->data.if_stats.isb_starttime <<= 32; wblock->data.if_stats.isb_starttime <<= 32;
@ -1882,8 +1882,8 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
memcpy(&high, option_content, sizeof(guint32)); memcpy(&high, option_content, sizeof(guint32));
memcpy(&low, option_content + sizeof(guint32), sizeof(guint32)); memcpy(&low, option_content + sizeof(guint32), sizeof(guint32));
if (pn->byte_swapped) { if (pn->byte_swapped) {
high = BSWAP32(high); high = GUINT32_SWAP_LE_BE(high);
low = BSWAP32(low); low = GUINT32_SWAP_LE_BE(low);
} }
wblock->data.if_stats.isb_endtime = (guint64)high; wblock->data.if_stats.isb_endtime = (guint64)high;
wblock->data.if_stats.isb_endtime <<= 32; wblock->data.if_stats.isb_endtime <<= 32;
@ -1900,7 +1900,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
*/ */
memcpy(&wblock->data.if_stats.isb_ifrecv, option_content, sizeof(guint64)); memcpy(&wblock->data.if_stats.isb_ifrecv, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->data.if_stats.isb_ifrecv = BSWAP64(wblock->data.if_stats.isb_ifrecv); wblock->data.if_stats.isb_ifrecv = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_ifrecv);
pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifrecv); pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifrecv);
} else { } else {
pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv length %u not 8 as expected", oh.option_length); pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifrecv length %u not 8 as expected", oh.option_length);
@ -1913,7 +1913,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
*/ */
memcpy(&wblock->data.if_stats.isb_ifdrop, option_content, sizeof(guint64)); memcpy(&wblock->data.if_stats.isb_ifdrop, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->data.if_stats.isb_ifdrop = BSWAP64(wblock->data.if_stats.isb_ifdrop); wblock->data.if_stats.isb_ifdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_ifdrop);
pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifdrop); pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_ifdrop);
} else { } else {
pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop length %u not 8 as expected", oh.option_length); pcapng_debug1("pcapng_read_interface_statistics_block: isb_ifdrop length %u not 8 as expected", oh.option_length);
@ -1926,7 +1926,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
*/ */
memcpy(&wblock->data.if_stats.isb_filteraccept, option_content, sizeof(guint64)); memcpy(&wblock->data.if_stats.isb_filteraccept, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->data.if_stats.isb_ifdrop = BSWAP64(wblock->data.if_stats.isb_filteraccept); wblock->data.if_stats.isb_ifdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_filteraccept);
pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_filteraccept); pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_filteraccept);
} else { } else {
pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept length %u not 8 as expected", oh.option_length); pcapng_debug1("pcapng_read_interface_statistics_block: isb_filteraccept length %u not 8 as expected", oh.option_length);
@ -1939,7 +1939,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
*/ */
memcpy(&wblock->data.if_stats.isb_osdrop, option_content, sizeof(guint64)); memcpy(&wblock->data.if_stats.isb_osdrop, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->data.if_stats.isb_osdrop = BSWAP64(wblock->data.if_stats.isb_osdrop); wblock->data.if_stats.isb_osdrop = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_osdrop);
pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_osdrop); pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_osdrop);
} else { } else {
pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop length %u not 8 as expected", oh.option_length); pcapng_debug1("pcapng_read_interface_statistics_block: isb_osdrop length %u not 8 as expected", oh.option_length);
@ -1952,7 +1952,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh, pca
*/ */
memcpy(&wblock->data.if_stats.isb_usrdeliv, option_content, sizeof(guint64)); memcpy(&wblock->data.if_stats.isb_usrdeliv, option_content, sizeof(guint64));
if (pn->byte_swapped) if (pn->byte_swapped)
wblock->data.if_stats.isb_usrdeliv = BSWAP64(wblock->data.if_stats.isb_osdrop); wblock->data.if_stats.isb_usrdeliv = GUINT64_SWAP_LE_BE(wblock->data.if_stats.isb_osdrop);
pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_usrdeliv); pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv %" G_GINT64_MODIFIER "u", wblock->data.if_stats.isb_usrdeliv);
} else { } else {
pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv length %u not 8 as expected", oh.option_length); pcapng_debug1("pcapng_read_interface_statistics_block: isb_usrdeliv length %u not 8 as expected", oh.option_length);
@ -2028,8 +2028,8 @@ pcapng_read_block(FILE_T fh, gboolean first_block, pcapng_t *pn, wtapng_block_t
block_read = bytes_read; block_read = bytes_read;
if (pn->byte_swapped) { if (pn->byte_swapped) {
bh.block_type = BSWAP32(bh.block_type); bh.block_type = GUINT32_SWAP_LE_BE(bh.block_type);
bh.block_total_length = BSWAP32(bh.block_total_length); bh.block_total_length = GUINT32_SWAP_LE_BE(bh.block_total_length);
} }
wblock->type = bh.block_type; wblock->type = bh.block_type;
@ -2095,7 +2095,7 @@ pcapng_read_block(FILE_T fh, gboolean first_block, pcapng_t *pn, wtapng_block_t
block_read += bytes_read; block_read += bytes_read;
if (pn->byte_swapped) if (pn->byte_swapped)
block_total_length = BSWAP32(block_total_length); block_total_length = GUINT32_SWAP_LE_BE(block_total_length);
if (!(block_total_length == bh.block_total_length)) { if (!(block_total_length == bh.block_total_length)) {
*err = WTAP_ERR_BAD_FILE; *err = WTAP_ERR_BAD_FILE;
@ -2249,7 +2249,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
file_seek(wth->fh, saved_offset, SEEK_SET, err); file_seek(wth->fh, saved_offset, SEEK_SET, err);
if (pn.byte_swapped) { if (pn.byte_swapped) {
bh.block_type = BSWAP32(bh.block_type); bh.block_type = GUINT32_SWAP_LE_BE(bh.block_type);
} }
pcapng_debug1("pcapng_open: Check for more IDB:s block_type 0x%x", bh.block_type); pcapng_debug1("pcapng_open: Check for more IDB:s block_type 0x%x", bh.block_type);

View File

@ -121,25 +121,6 @@ gint64 wtap_dump_file_tell(wtap_dumper *wdh, int *err);
extern gint wtap_num_file_types; extern gint wtap_num_file_types;
/* Macros to byte-swap 64-bit, 32-bit and 16-bit quantities. */
#define BSWAP64(x) \
((((x)&G_GINT64_CONSTANT(0xFF00000000000000U))>>56) | \
(((x)&G_GINT64_CONSTANT(0x00FF000000000000U))>>40) | \
(((x)&G_GINT64_CONSTANT(0x0000FF0000000000U))>>24) | \
(((x)&G_GINT64_CONSTANT(0x000000FF00000000U))>>8) | \
(((x)&G_GINT64_CONSTANT(0x00000000FF000000U))<<8) | \
(((x)&G_GINT64_CONSTANT(0x0000000000FF0000U))<<24) | \
(((x)&G_GINT64_CONSTANT(0x000000000000FF00U))<<40) | \
(((x)&G_GINT64_CONSTANT(0x00000000000000FFU))<<56))
#define BSWAP32(x) \
((((x)&0xFF000000)>>24) | \
(((x)&0x00FF0000)>>8) | \
(((x)&0x0000FF00)<<8) | \
(((x)&0x000000FF)<<24))
#define BSWAP16(x) \
((((x)&0xFF00)>>8) | \
(((x)&0x00FF)<<8))
/* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities; /* Macros to byte-swap possibly-unaligned 64-bit, 32-bit and 16-bit quantities;
* they take a pointer to the quantity, and byte-swap it in place. * they take a pointer to the quantity, and byte-swap it in place.
*/ */

View File

@ -139,15 +139,4 @@
((guint8*)(p))[3] = (guint8)((v) >> 0); \ ((guint8*)(p))[3] = (guint8)((v) >> 0); \
} }
/* Macros to byte-swap 32-bit and 16-bit quantities. */
#define BSWAP32(x) \
((((x)&0xFF000000)>>24) | \
(((x)&0x00FF0000)>>8) | \
(((x)&0x0000FF00)<<8) | \
(((x)&0x000000FF)<<24))
#define BSWAP16(x) \
((((x)&0xFF00)>>8) | \
(((x)&0x00FF)<<8))
#endif /* PINT_H */ #endif /* PINT_H */