1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Use endian independent way of setting IP fragment offset and flags

This commit is contained in:
Matias Fontanini
2015-12-07 22:11:28 -08:00
parent 3e23bcc73c
commit a35b086d12
3 changed files with 7 additions and 4 deletions

View File

@@ -329,7 +329,7 @@ namespace Tins {
* \return The IP flags field
*/
Flags flags() const {
return static_cast<Flags>((_ip.frag_off & 0xe0) >> 5);
return static_cast<Flags>(Endian::be_to_host(_ip.frag_off) >> 13);
}
/**

View File

@@ -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<uint16_t>(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) {

View File

@@ -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<IP::Flags>(0));
return REASSEMBLED;
}
else