Introduce BSWAP64() and use it in the pcapng code
authorsfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 20 Jan 2008 02:31:34 +0000 (02:31 +0000)
committersfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 20 Jan 2008 02:31:34 +0000 (02:31 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@24142 f5534014-38df-0310-8fa8-9805f1628bb7

wiretap/pcapng.c
wiretap/wtap-int.h

index 5dbd3afb6dcc3e6ecdb42d259af51071961e6ddf..072a9f30f1a3b9027be421596a17caeb976806ff 100644 (file)
@@ -320,7 +320,7 @@ pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t
 
                        g_warning("pcapng_read_section_header_block: SHB (little endian) V%u.%u, len %u",
                                pn->version_major, pn->version_minor, bh->block_total_length);
-               break;
+                       break;
                case(0x4D3C2B1A):
                        /* this seems pcapng with swapped byte order */
                        pn->byte_swapped                = TRUE;
@@ -536,9 +536,8 @@ pcapng_read_if_descr_block(FILE_T fh, pcapng_block_header_t *bh, pcapng_t *pn, w
             case(8): /* if_speed */
                 if(oh.option_length == 8) {
                     wblock->data.if_descr.if_speed = *((guint64 *)option_content);
-                    /* XXX - need 64 bit byte swap */
-                    /*if(pn->byte_swapped) 
-                               wblock->data.if_descr.if_speed = BSWAP64(wblock->data.if_descr.if_speed);*/
+                    if(pn->byte_swapped) 
+                               wblock->data.if_descr.if_speed = BSWAP64(wblock->data.if_descr.if_speed);
 
                            g_warning("pcapng_read_if_descr_block: if_speed %" G_GINT64_MODIFIER "u (bps)", wblock->data.if_descr.if_speed);
                 } else {
index 04272f45f088f52817e0f46006303dbea8cdfba0..780cde2bfe450095636342743db9897d644e2310 100644 (file)
@@ -280,7 +280,16 @@ extern int wtap_dump_file_ferror(wtap_dumper *wdh);
 
 extern gint wtap_num_file_types;
 
-/* Macros to byte-swap 32-bit and 16-bit quantities. */
+/* 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) | \