Changeset 8b49230 for libpacketdump


Ignore:
Timestamp:
08/30/13 13:30:41 (7 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:
libpacketdump
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpacketdump/Makefile.am

    rb471b67 r8b49230  
    166166ospf2_1005_la_LDFLAGS=$(modflags)
    167167
    168 libpacketdump_la_SOURCES = libpacketdump.cc \
     168libpacketdump_la_SOURCES = libpacketdump.cc ../lib/byteswap.c \
    169169                        lexer.l parser.y bitbuffer.c bitbuffer.h grammar.h
    170170
  • libpacketdump/libpacketdump.cc

    rc7f8451 r8b49230  
    44#include <time.h>
    55#include "libpacketdump.h"
     6#include "lt_bswap.h"
    67#include <stdio.h>
    78#include <netdb.h>
     
    303304        };
    304305}
     306
  • libpacketdump/link_15.c

    ref07202 r8b49230  
    22 * libpacketdump decoder for Radiotap
    33 */
    4 #include "libtrace_int.h" /* bswaps */
    54#include <sys/types.h>
    65#include <netinet/in.h>
     
    109#include "libtrace.h"
    1110#include "libpacketdump.h"
     11#include "lt_bswap.h"
    1212
    1313#define ALIGN_NATURAL_32(_p,_s,_c) \
     
    2323        struct libtrace_radiotap_t *rtap;
    2424        uint16_t rtap_len;
     25        uint32_t rtap_pres;
    2526        uint16_t rtap_real_len; /* to make sure length in header matches fields present */
    2627        rtap = (libtrace_radiotap_t *)packet;
     
    3536        rtap_real_len = sizeof(struct libtrace_radiotap_t);
    3637        rtap_len = bswap_le_to_host16(rtap->it_len);
     38        rtap_pres = bswap_le_to_host32(rtap->it_present);
    3739
    3840        printf(" version: %u, length: %u, fields: %#08x\n", rtap->it_version,
    39                         rtap_len, rtap->it_present);
     41                        rtap_len, rtap_pres);
    4042       
    4143        /* Check for extended bitmasks */
    4244        ptr = (uint32_t *) &(rtap->it_present);
    4345       
    44         if ( (*ptr) & (1 << TRACE_RADIOTAP_EXT) )
     46        if ( (rtap_pres) & (1 << TRACE_RADIOTAP_EXT) )
    4547                printf("  extended fields:");
    4648       
    47         while( (*ptr) & (1 << TRACE_RADIOTAP_EXT) ) {
     49        while( (rtap_pres) & (1 << TRACE_RADIOTAP_EXT) ) {
    4850                rtap_real_len += sizeof (uint32_t);
    49                 printf(" %#08x", *(++ptr));     
     51                ptr++;
     52                printf(" %#08x", bswap_le_to_host32(*ptr));     
    5053        }
    5154
     
    5457        s = p = (uint8_t *) ++ptr;
    5558
    56         if (rtap->it_present & (1 << TRACE_RADIOTAP_TSFT)) {
     59        if (rtap_pres & (1 << TRACE_RADIOTAP_TSFT)) {
    5760                printf(" Radiotap: TSFT = %" PRIu64 " microseconds\n", bswap_le_to_host64(*((uint64_t *)p)));
    5861                p += sizeof (uint64_t);
     
    6063        }
    6164
    62         if (rtap->it_present & (1 << TRACE_RADIOTAP_FLAGS)) {
     65        if (rtap_pres & (1 << TRACE_RADIOTAP_FLAGS)) {
    6366                printf(" Radiotap: Flags = 0x%02x\n", *p);
    6467                p += sizeof (uint8_t);
     
    6770
    6871       
    69         if (rtap->it_present & (1 << TRACE_RADIOTAP_RATE)) {
     72        if (rtap_pres & (1 << TRACE_RADIOTAP_RATE)) {
    7073                printf(" Radiotap: Rate = %u kbps\n", (*p) * 500);
    7174                p +=  sizeof (uint8_t);
     
    7376        }
    7477       
    75         if (rtap->it_present & (1 << TRACE_RADIOTAP_CHANNEL)) {
     78        if (rtap_pres & (1 << TRACE_RADIOTAP_CHANNEL)) {
    7679                ALIGN_NATURAL_16(p,s,rtap_real_len);
    7780                printf(" Radiotap: Freq = %u MHz, ChanFlags: 0x%04x\n", bswap_le_to_host16(*((uint16_t *)p)),
     
    8184        }
    8285                                                                                       
    83         if (rtap->it_present & (1 << TRACE_RADIOTAP_FHSS)) {
     86        if (rtap_pres & (1 << TRACE_RADIOTAP_FHSS)) {
    8487                ALIGN_NATURAL_16(p,s, rtap_real_len);
    8588                printf(" Radiotap: FHSS HopSet = %u , HopPattern: %u\n", *p, *(p+1));
     
    8992
    9093
    91         if (rtap->it_present & (1 << TRACE_RADIOTAP_DBM_ANTSIGNAL)) {
     94        if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_ANTSIGNAL)) {
    9295                printf(" Radiotap: Signal = %i dBm\n", (int8_t) *p) ;
    9396                p += sizeof (uint8_t);
     
    9699
    97100
    98         if (rtap->it_present & (1 << TRACE_RADIOTAP_DBM_ANTNOISE)) {
     101        if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_ANTNOISE)) {
    99102                printf(" Radiotap: Noise = %i dBm\n", (int8_t) *p);
    100103                p += sizeof (uint8_t);
     
    103106
    104107
    105         if (rtap->it_present & (1 << TRACE_RADIOTAP_LOCK_QUALITY)) {
     108        if (rtap_pres & (1 << TRACE_RADIOTAP_LOCK_QUALITY)) {
    106109                ALIGN_NATURAL_16(p,s, rtap_real_len);
    107110                printf(" Radiotap: Barker Code Lock Quality = %u\n", bswap_le_to_host16(*((uint16_t *)p)));
     
    111114
    112115
    113         if (rtap->it_present & (1 << TRACE_RADIOTAP_TX_ATTENUATION)) {
     116        if (rtap_pres & (1 << TRACE_RADIOTAP_TX_ATTENUATION)) {
    114117                ALIGN_NATURAL_16(p,s, rtap_real_len);
    115118                printf(" Radiotap: TX Attenuation = %u\n", bswap_le_to_host16(*((uint16_t *)p)));
     
    118121        }
    119122
    120         if (rtap->it_present & (1 << TRACE_RADIOTAP_DB_TX_ATTENUATION)) {
     123        if (rtap_pres & (1 << TRACE_RADIOTAP_DB_TX_ATTENUATION)) {
    121124                ALIGN_NATURAL_16(p,s,rtap_real_len);
    122125                printf(" Radiotap: TX Attenuation = %u dB\n", bswap_le_to_host16(*((uint16_t *)p)));
     
    125128        }
    126129
    127         if (rtap->it_present & (1 << TRACE_RADIOTAP_DBM_TX_POWER)) {
     130        if (rtap_pres & (1 << TRACE_RADIOTAP_DBM_TX_POWER)) {
    128131                printf(" Radiotap: TX Power = %i dBm\n", *p);
    129132                p += sizeof (uint8_t);
     
    131134        }
    132135
    133         if (rtap->it_present & (1 << TRACE_RADIOTAP_ANTENNA)) {
     136        if (rtap_pres & (1 << TRACE_RADIOTAP_ANTENNA)) {
    134137                printf(" Radiotap: Antenna = %u\n", *p);
    135138                p += sizeof (uint8_t);
     
    137140        }
    138141
    139         if (rtap->it_present & (1 << TRACE_RADIOTAP_DB_ANTSIGNAL)) {
     142        if (rtap_pres & (1 << TRACE_RADIOTAP_DB_ANTSIGNAL)) {
    140143                printf(" Radiotap: Signal = %u dB\n", *p);
    141144                p += sizeof (uint8_t);
     
    143146        }
    144147
    145         if (rtap->it_present & (1 << TRACE_RADIOTAP_DB_ANTNOISE)) {
     148        if (rtap_pres & (1 << TRACE_RADIOTAP_DB_ANTNOISE)) {
    146149                printf(" Radiotap: Noise = %u dB\n", *p);
    147150                p += sizeof (uint8_t);
     
    149152        }
    150153
    151         if (rtap->it_present & (1 << TRACE_RADIOTAP_RX_FLAGS)) {
     154        if (rtap_pres & (1 << TRACE_RADIOTAP_RX_FLAGS)) {
    152155                ALIGN_NATURAL_16(p,s,rtap_real_len);
    153156                printf(" Radiotap: RX Flags = 0x%04x\n", *((uint16_t *)p));
     
    156159        }
    157160
    158         if (rtap->it_present & (1 << TRACE_RADIOTAP_TX_FLAGS)) {
     161        if (rtap_pres & (1 << TRACE_RADIOTAP_TX_FLAGS)) {
    159162                ALIGN_NATURAL_16(p,s,rtap_real_len);
    160163                printf(" Radiotap: TX Flags = 0x%04x\n", *((uint16_t *)p));
     
    163166        }
    164167
    165         if (rtap->it_present & (1 << TRACE_RADIOTAP_RTS_RETRIES)) {
     168        if (rtap_pres & (1 << TRACE_RADIOTAP_RTS_RETRIES)) {
    166169                printf(" Radiotap: RTS Retries = %u\n", *p);
    167170                p += sizeof (uint8_t);
     
    169172        }
    170173
    171         if (rtap->it_present & (1 << TRACE_RADIOTAP_DATA_RETRIES)) {
     174        if (rtap_pres & (1 << TRACE_RADIOTAP_DATA_RETRIES)) {
    172175                printf(" Radiotap: Data Retries = %u\n", *p);
    173176                p += sizeof (uint8_t);
Note: See TracChangeset for help on using the changeset viewer.