Changeset 8b49230 for lib


Ignore:
Timestamp:
08/30/13 13:30:41 (8 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
bf1029a
Parents:
8780774
Message:

Fixed problems with decoding RadioTap? headers with libpacketdump on big endian
hosts

  • Moved byteswapX functions to a separate source file so that libpacketdump can also link against them.
  • bswap_* macros have been moved into lt_bswap.h so they can be used without having to include the entire libtrace_int.h header
  • Fixed endianness issues with the "fields" inside the RadioTap? header.
Location:
lib
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • lib/Makefile.am

    rc04929c r8b49230  
    4444                format_duck.c format_tsh.c $(NATIVEFORMATS) $(BPFFORMATS) \
    4545                format_atmhdr.c \
    46                 libtrace_int.h lt_inttypes.h \
    47                 linktypes.c link_wireless.c \
     46                libtrace_int.h lt_inttypes.h lt_bswap.h \
     47                linktypes.c link_wireless.c byteswap.c \
    4848                checksum.c checksum.h \
    4949                protocols_pktmeta.c protocols_l2.c protocols_l3.c \
  • lib/format_helper.c

    rd57ae6f r8b49230  
    320320        va_end(va);
    321321}
    322 
    323 /* Byte swapping functions for various inttypes */
    324 uint64_t byteswap64(uint64_t num)
    325 {
    326         return (byteswap32((num&0xFFFFFFFF00000000ULL)>>32))
    327               |((uint64_t)byteswap32(num&0x00000000FFFFFFFFULL)<<32);
    328 }
    329 
    330 uint32_t byteswap32(uint32_t num)
    331 {
    332         return ((num&0x000000FFU)<<24)
    333                 | ((num&0x0000FF00U)<<8)
    334                 | ((num&0x00FF0000U)>>8)
    335                 | ((num&0xFF000000U)>>24);
    336 }
    337 
    338 uint16_t byteswap16(uint16_t num)
    339 {
    340         return ((num<<8)&0xFF00)|((num>>8)&0x00FF);
    341 }
    342 
  • lib/libtrace_int.h

    r3799f51 r8b49230  
    5959#include "libtrace.h"
    6060#include "wandio.h"
     61#include "lt_bswap.h"
    6162
    6263#ifdef _MSC_VER
     
    900901                uint32_t *remaining);
    901902
    902 /** Byteswaps a 64-bit value.
    903  *
    904  * @param num           The value to be byteswapped.
    905  * @return The byteswapped 64-bit number
    906  *
    907  */
    908 uint64_t byteswap64(uint64_t num);
    909 
    910 /** Byteswaps a 32-bit value.
    911  *
    912  * @param num           The value to be byteswapped.
    913  * @return The byteswapped 32-bit number
    914  *
    915  */
    916 uint32_t byteswap32(uint32_t num);
    917 
    918 /** Byteswaps a 16-bit value.
    919  *
    920  * @param num           The value to be byteswapped.
    921  * @return The byteswapped 16-bit number
    922  *
    923  */
    924 uint16_t byteswap16(uint16_t num);
    925 
    926 /** @name Byte ordering
    927  * Macros that define how to convert a value into a particular byte-order
    928  *
    929  * @{
    930  */
    931 #if __BYTE_ORDER == __BIG_ENDIAN
    932 #define bswap_host_to_be64(num) ((uint64_t)(num))
    933 #define bswap_host_to_le64(num) byteswap64(num)
    934 #define bswap_host_to_be32(num) ((uint32_t)(num))
    935 #define bswap_host_to_le32(num) byteswap32(num)
    936 #define bswap_host_to_be16(num) ((uint16_t)(num))
    937 #define bswap_host_to_le16(num) byteswap16(num)
    938 
    939 #define bswap_be_to_host64(num) ((uint64_t)(num))
    940 #define bswap_le_to_host64(num) byteswap64(num)
    941 #define bswap_be_to_host32(num) ((uint32_t)(num))
    942 #define bswap_le_to_host32(num) byteswap32(num)
    943 #define bswap_be_to_host16(num) ((uint16_t)(num))
    944 #define bswap_le_to_host16(num) byteswap16(num)
    945 
    946 /* We use ntoh*() here, because the compiler may
    947  * attempt to optimise it
    948  */
    949 #elif __BYTE_ORDER == __LITTLE_ENDIAN
    950 #define bswap_host_to_be64(num) (byteswap64(num))
    951 #define bswap_host_to_le64(num) ((uint64_t)(num))
    952 #define bswap_host_to_be32(num) (htonl(num))
    953 #define bswap_host_to_le32(num) ((uint32_t)(num))
    954 #define bswap_host_to_be16(num) (htons(num))
    955 #define bswap_host_to_le16(num) ((uint16_t)(num))
    956 
    957 #define bswap_be_to_host64(num) (byteswap64(num))
    958 #define bswap_le_to_host64(num) ((uint64_t)(num))
    959 #define bswap_be_to_host32(num) (ntohl(num))
    960 #define bswap_le_to_host32(num) ((uint32_t)(num))
    961 #define bswap_be_to_host16(num) (ntohs(num))
    962 #define bswap_le_to_host16(num) ((uint16_t)(num))
    963 
    964 #else
    965 #error "Unknown byte order"
    966 #endif
    967 /** @} */
    968903
    969904#ifdef HAVE_BPF
Note: See TracChangeset for help on using the changeset viewer.