diff --git a/include/tins/ip.h b/include/tins/ip.h index 773acf6..c33029e 100644 --- a/include/tins/ip.h +++ b/include/tins/ip.h @@ -329,7 +329,7 @@ namespace Tins { * \return The IP flags field */ Flags flags() const { - return static_cast((_ip.frag_off & 0xe0) >> 5); + return static_cast(Endian::be_to_host(_ip.frag_off) >> 13); } /** diff --git a/src/ip.cpp b/src/ip.cpp index e9af2ff..2a8d4c9 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -179,11 +179,13 @@ void IP::frag_off(uint16_t new_frag_off) { } void IP::fragment_offset(small_uint<13> new_frag_off) { - _ip.frag_off = (_ip.frag_off & 0xe0) | Endian::host_to_be(new_frag_off); + uint16_t value = (Endian::be_to_host(_ip.frag_off) & 0xe000) | new_frag_off; + _ip.frag_off = Endian::host_to_be(value); } void IP::flags(Flags new_flags) { - _ip.frag_off = (_ip.frag_off & 0xff1f) | (new_flags << 5); + uint16_t value = (Endian::be_to_host(_ip.frag_off) & 0x1fff) | (new_flags << 13); + _ip.frag_off = Endian::host_to_be(value); } void IP::ttl(uint8_t new_ttl) { diff --git a/src/ip_reassembler.cpp b/src/ip_reassembler.cpp index afb80e5..1cb3cbf 100644 --- a/src/ip_reassembler.cpp +++ b/src/ip_reassembler.cpp @@ -112,7 +112,8 @@ IPv4Reassembler::packet_status IPv4Reassembler::process(PDU &pdu) { return FRAGMENTED; } ip->inner_pdu(pdu); - ip->frag_off(0); + ip->fragment_offset(0); + ip->flags(static_cast(0)); return REASSEMBLED; } else