Changeset 11041eb


Ignore:
Timestamp:
07/02/13 14:19:40 (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:
da46c9d
Parents:
fdb5e98
Message:
  • Changed all BYTE_ORDER checks to be consistent and use the same macros
  • Ensure that BYTE_ORDER is defined for *all* systems -- stupid BSDs
  • Be careful about writing values from timevals into our pcap header -- 64 bit timevals could cause some issues here
Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pcapfile.c

    rc909fad r11041eb  
    456456        }
    457457
    458         hdr.ts_sec = tv.tv_sec;
    459         hdr.ts_usec = tv.tv_usec;
     458
     459        hdr.ts_sec = (uint32_t)tv.tv_sec;
     460        hdr.ts_usec = (uint32_t)tv.tv_usec;
    460461        hdr.caplen = trace_get_capture_length(packet);
    461462        assert(hdr.caplen < LIBTRACE_PACKET_BUFSIZE);
  • lib/libtrace.h.in

    rd57ae6f r11041eb  
    6565#ifndef WIN32
    6666#include <sys/time.h>
     67#endif
     68
     69/* Deal with missing byte order macros */
     70#include <sys/param.h>
     71
     72#if defined(BYTE_ORDER) && !defined(__BYTE_ORDER)
     73#define __BYTE_ORDER    BYTE_ORDER
     74#endif
     75
     76#if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN)
     77#define __BIG_ENDIAN    BIG_ENDIAN
     78#endif
     79
     80#if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN)
     81#define __LITTLE_ENDIAN LITTLE_ENDIAN
    6782#endif
    6883
     
    510525typedef struct libtrace_ip
    511526{
    512 #if BYTE_ORDER == LITTLE_ENDIAN
     527#if __BYTE_ORDER == __LITTLE_ENDIAN
    513528    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
    514529    LT_BITFIELD8 ip_v:4;                /**< Version */
    515 #elif BYTE_ORDER == BIG_ENDIAN
     530#elif __BYTE_ORDER == __BIG_ENDIAN
    516531    LT_BITFIELD8 ip_v:4;                /**< Version */
    517532    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
     
    567582    uint32_t seq;               /**< Sequence number */
    568583    uint32_t ack_seq;           /**< Acknowledgement Number */
    569 #  if BYTE_ORDER == LITTLE_ENDIAN
     584#  if __BYTE_ORDER == __LITTLE_ENDIAN
    570585    LT_BITFIELD8 ecn_ns:1;      /**< ECN Nonce Sum */
    571586    LT_BITFIELD8 res1:3;        /**< Reserved bits */
     
    579594    LT_BITFIELD8 ece:1;         /**< ECN Echo */
    580595    LT_BITFIELD8 cwr:1;         /**< ECN CWR */
    581 #  elif BYTE_ORDER == BIG_ENDIAN
     596#  elif __BYTE_ORDER == __BIG_ENDIAN
    582597    LT_BITFIELD8 doff:4;        /**< Data offset */
    583598    LT_BITFIELD8 res1:3;        /**< Reserved bits */
     
    758773/** 802.11 header */
    759774typedef struct libtrace_80211_t {
    760 #if BYTE_ORDER == LITTLE_ENDIAN
     775#if __BYTE_ORDER == __LITTLE_ENDIAN
    761776        LT_BITFIELD32      protocol:2;  /**< Protocol Version */
    762777        LT_BITFIELD32      type:2;      /**< Frame Type */
     
    768783#endif
    769784
    770 #if BYTE_ORDER == LITTLE_ENDIAN
     785#if __BYTE_ORDER == __LITTLE_ENDIAN
    771786        LT_BITFIELD32      to_ds:1;     /**< Packet to Distribution Service */
    772787        LT_BITFIELD32      from_ds:1;   /**< Packet from Distribution Service */
     
    828843/** Options Field present in some OSPFv2 packets */
    829844typedef struct libtrace_ospf_options_t {
    830 #if BYTE_ORDER == LITTLE_ENDIAN
     845#if __BYTE_ORDER == __LITTLE_ENDIAN
    831846        LT_BITFIELD8 unused1:1;
    832847        LT_BITFIELD8 e_bit:1;
     
    836851        LT_BITFIELD8 dc_bit:1;
    837852        LT_BITFIELD8 unused2:2;
    838 #elif BYTE_ORDER == BIG_ENDIAN
     853#elif __BYTE_ORDER == __BIG_ENDIAN
    839854        LT_BITFIELD8 unused2:2;
    840855        LT_BITFIELD8 dc_bit:1;
     
    880895        uint16_t mtu;           /**< Interface MTU */
    881896        libtrace_ospf_options_t db_desc_options;        /**< Options */
    882 #if BYTE_ORDER == LITTLE_ENDIAN
     897#if __BYTE_ORDER == __LITTLE_ENDIAN
    883898        LT_BITFIELD8 db_desc_ms:1;      /**< If set, this router is the master */
    884899        LT_BITFIELD8 db_desc_m:1;       /**< If set, more packets to follow */
    885900        LT_BITFIELD8 db_desc_i:1;       /**< If set, this is the first packet in sequence */
    886901        LT_BITFIELD8 zero:5;
    887 #elif BYTE_ORDER == BIG_ENDIAN
     902#elif __BYTE_ORDER == __BIG_ENDIAN
    888903        LT_BITFIELD8 zero:5;
    889904        LT_BITFIELD8 db_desc_i:1;       /**< If set, this is the first packet in sequence */
     
    914929{
    915930        struct in_addr netmask; /**< Netmask for the destination */
    916 #if BYTE_ORDER == LITTLE_ENDIAN
     931#if __BYTE_ORDER == __LITTLE_ENDIAN
    917932        LT_BITFIELD8 tos:7;
    918933        LT_BITFIELD8 e:1;       /**< If set, metric is Type 2. Else, Type 1 */
    919 #elif BYTE_ORDER == BIG_ENDIAN
     934#elif __BYTE_ORDER == __BIG_ENDIAN
    920935        LT_BITFIELD8 e:1;       /**< If set, metric is Type 2. Else, Type 1 */
    921936        LT_BITFIELD8 tos:7;
     
    959974typedef struct libtrace_ospf_router_lsa_t
    960975{
    961 #if BYTE_ORDER == LITTLE_ENDIAN
     976#if __BYTE_ORDER == __LITTLE_ENDIAN
    962977        LT_BITFIELD8 b:1;       /**< Area Border Router Flag */
    963978        LT_BITFIELD8 e:1;       /**< External Router Flag */
    964979        LT_BITFIELD8 v:1;       /**< Virtual Endpoint Flag */
    965980        LT_BITFIELD8 zero:5;
    966 #elif BYTE_ORDER == BIG_ENDIAN
     981#elif __BYTE_ORDER == __BIG_ENDIAN
    967982        LT_BITFIELD8 zero:5;
    968983        LT_BITFIELD8 v:1;       /**< Virtual Endpoint Flag */
  • lib/trace.c

    ra464de7 r11041eb  
    4848#endif
    4949#include <stdarg.h>
     50#include <sys/param.h>
    5051
    5152#ifdef HAVE_LIMITS_H
     
    923924#if __BYTE_ORDER == __BIG_ENDIAN
    924925                tv.tv_sec = ts & 0xFFFFFFFF;
     926                tv.tv_usec = ((ts >> 32) * 1000000) & 0xFFFFFFFF;
    925927#elif __BYTE_ORDER == __LITTLE_ENDIAN
    926928                tv.tv_sec = ts >> 32;
     929                tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32;
    927930#else
    928931#error "What on earth are you running this on?"
    929932#endif
    930                 tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32;
    931933                if (tv.tv_usec >= 1000000) {
    932934                        tv.tv_usec -= 1000000;
     
    961963#if __BYTE_ORDER == __BIG_ENDIAN
    962964                ts.tv_sec = erfts & 0xFFFFFFFF;
     965                tv.tv_nsec = ((ts >> 32) * 1000000000) & 0xFFFFFFFF;
    963966#elif __BYTE_ORDER == __LITTLE_ENDIAN
    964967                ts.tv_sec = erfts >> 32;
     968                ts.tv_nsec = ((erfts&0xFFFFFFFF)*1000000000)>>32;
    965969#else
    966970#error "What on earth are you running this on?"
    967971#endif
    968                 ts.tv_nsec = ((erfts&0xFFFFFFFF)*1000000000)>>32;
    969972                if (ts.tv_nsec >= 1000000000) {
    970973                        ts.tv_nsec -= 1000000000;
     
    16361639#if __BYTE_ORDER == __BIG_ENDIAN
    16371640                        tv.tv_sec = ts & 0xFFFFFFFF;
     1641                        tv.tv_usec = ((ts >> 32) * 1000000) & 0xFFFFFFFF;
    16381642#elif __BYTE_ORDER == __LITTLE_ENDIAN
    16391643                        tv.tv_sec = ts >> 32;
     1644                        tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32;
    16401645#else
    16411646#error "What on earth are you running this on?"
    16421647#endif
    1643                         tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32;
    16441648                        if (tv.tv_usec >= 1000000) {
    16451649                                tv.tv_usec -= 1000000;
Note: See TracChangeset for help on using the changeset viewer.