From 72e038b9bf2dfbc97b4ba2b21a7a214137b53da6 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Thu, 4 Feb 2016 20:20:14 -0800 Subject: [PATCH] Fix invalid endian on IP fragment offset on OSX --- src/ip.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ip.cpp b/src/ip.cpp index d822098..4d0b79d 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -429,10 +429,13 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pare protocol(new_flag); } } + + uint16_t original_frag_off = ip_.frag_off; #if __FreeBSD__ || defined(__FreeBSD_kernel__) || __APPLE__ if (!parent) { total_sz = Endian::host_to_be(total_sz); + ip_.frag_off = Endian::be_to_host(ip_.frag_off); } #endif tot_len(total_sz); @@ -440,6 +443,9 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pare stream.write(ip_); + // Restore the fragment offset field in case we flipped it + ip_.frag_off = original_frag_off; + for (options_type::const_iterator it = ip_options_.begin(); it != ip_options_.end(); ++it) { write_option(*it, stream); }