From 356fe00aad9b872f054b11da1dceda60fabb4830 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Tue, 4 Dec 2012 16:15:08 -0300 Subject: [PATCH] Fixed compilation error in OSX. Fixed bug when sending IP PDUs in BSD. --- include/endianness.h | 18 ++++++++---------- include/ip.h | 5 ----- src/dot11.cpp | 4 +++- src/ip.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/include/endianness.h b/include/endianness.h index 9b727c6..7a11b70 100644 --- a/include/endianness.h +++ b/include/endianness.h @@ -33,16 +33,14 @@ #include #include "macros.h" -#if defined(BSD) - #if defined(__APPLE__) - #include - #define TINS_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN) - #define TINS_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN) - #else - #include - #define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) - #define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN) - #endif +#if defined(__APPLE__) + #include + #define TINS_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN) + #define TINS_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN) +#elif defined(BSD) + #include + #define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) + #define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN) #elif defined(WIN32) // Assume windows == little endian. fixme later #define TINS_IS_LITTLE_ENDIAN 1 diff --git a/include/ip.h b/include/ip.h index 64bc8ee..ce14602 100644 --- a/include/ip.h +++ b/include/ip.h @@ -260,12 +260,7 @@ namespace Tins { * \return The total length of this IP PDU. */ uint16_t tot_len() const { - // FreeBSD wants this in host byte order............ - #ifdef __FreeBSD__ - return _ip.tot_len; - #else return Endian::be_to_host(_ip.tot_len); - #endif } /** diff --git a/src/dot11.cpp b/src/dot11.cpp index 27e0e88..552e4f6 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -32,9 +32,11 @@ #include #include #include +#include "macros.h" #ifndef WIN32 - #ifdef BSD + #if defined(BSD) || defined(__APPLE__) + #include #include #else #include diff --git a/src/ip.cpp b/src/ip.cpp index c95a2be..212762e 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -170,12 +170,7 @@ void IP::tos(uint8_t new_tos) { } void IP::tot_len(uint16_t new_tot_len) { - // FreeBSD wants this in host byte order............ - #ifdef __FreeBSD__ - _ip.tot_len = new_tot_len; - #else _ip.tot_len = Endian::host_to_be(new_tot_len); - #endif } void IP::id(uint16_t new_id) { @@ -394,6 +389,11 @@ void IP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU* pare protocol(new_flag); //flag(new_flag); } + + #ifdef __FreeBSD__ + if(!parent) + total_sz = Endian::host_to_be(total_sz); + #endif tot_len(total_sz); head_len(my_sz / sizeof(uint32_t));