diff --git a/src/radiotap.cpp b/src/radiotap.cpp index e2816c9..d0c3c5c 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -522,7 +522,7 @@ void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU stream.write(rate_); } if (radio_.flags.channel) { - if (((buffer - buffer_start) & 1) == 1) { + if (((stream.pointer() - buffer_start) & 1) == 1) { stream.write(0); } stream.write(channel_freq_); @@ -535,7 +535,7 @@ void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU stream.write(dbm_noise_); } if (radio_.flags.lock_quality) { - if (((buffer - buffer_start) & 1) == 1) { + if (((stream.pointer() - buffer_start) & 1) == 1) { stream.write(0); } stream.write(signal_quality_); @@ -547,7 +547,7 @@ void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU stream.write(db_signal_); } if (radio_.flags.rx_flags) { - if (((buffer - buffer_start) & 1) == 1) { + if (((stream.pointer() - buffer_start) & 1) == 1) { stream.write(0); } stream.write(rx_flags_); diff --git a/tests/src/radiotap.cpp b/tests/src/radiotap.cpp index ec2453c..c6ff43b 100644 --- a/tests/src/radiotap.cpp +++ b/tests/src/radiotap.cpp @@ -9,6 +9,8 @@ #include "dot11/dot11_data.h" #include "dot11/dot11_beacon.h" #include "arp.h" +#include "snap.h" +#include "eapol.h" #include "utils.h" using namespace std; @@ -379,4 +381,23 @@ TEST_F(RadioTapTest, TSFT) { EXPECT_EQ(radio.tsft(), 0x7afb9a8dU); } +TEST_F(RadioTapTest, SerializationWorksFine) { + const uint8_t expected[] = { + 0, 0, 26, 0, 43, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 108, + 9, 160, 0, 206, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 170, 3, 0, 0, 0, 136, 142, + 1, 3, 0, 95, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 43, 4, 210 + }; + RadioTap radio = RadioTap() / Dot11Data() / SNAP() / RSNEAPOL(); + RadioTap::serialization_type buffer = radio.serialize(); + EXPECT_EQ( + RadioTap::serialization_type(expected, expected + sizeof(expected)), + buffer + ); +} + #endif // HAVE_DOT11