mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Add IP::fragment_offset and IP::flags
This commit is contained in:
12
src/ip.cpp
12
src/ip.cpp
@@ -157,9 +157,7 @@ void IP::init_ip_fields() {
|
||||
}
|
||||
|
||||
bool IP::is_fragmented() const {
|
||||
// It's 0 if offset == 0 && more_frag == 0
|
||||
// It's 0x4000 if dont_fragment = 1
|
||||
return frag_off() != 0 && frag_off() != 0x4000;
|
||||
return flags() == IP::MORE_FRAGMENTS || fragment_offset() != 0;
|
||||
}
|
||||
|
||||
/* Setters */
|
||||
@@ -180,6 +178,14 @@ void IP::frag_off(uint16_t new_frag_off) {
|
||||
_ip.frag_off = Endian::host_to_be(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);
|
||||
}
|
||||
|
||||
void IP::flags(Flags new_flags) {
|
||||
_ip.frag_off = (_ip.frag_off & 0xff1f) | (new_flags << 5);
|
||||
}
|
||||
|
||||
void IP::ttl(uint8_t new_ttl) {
|
||||
_ip.ttl = new_ttl;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ void IPv4Stream::add_fragment(IP *ip) {
|
||||
return;
|
||||
fragments.insert(it, IPv4Fragment(ip->inner_pdu(), offset));
|
||||
received_size += ip->inner_pdu()->size();
|
||||
if(!extract_more_frag(ip)) {
|
||||
if(ip->flags() != IP::MORE_FRAGMENTS) {
|
||||
total_size = offset + ip->inner_pdu()->size();
|
||||
received_end = true;
|
||||
}
|
||||
@@ -83,12 +83,9 @@ PDU *IPv4Stream::allocate_pdu() const {
|
||||
}
|
||||
|
||||
uint16_t IPv4Stream::extract_offset(const IP *ip) {
|
||||
return (ip->frag_off() & 0x1fff) * 8;
|
||||
return ip->fragment_offset() * 8;
|
||||
}
|
||||
|
||||
bool IPv4Stream::extract_more_frag(const IP *ip) {
|
||||
return (ip->frag_off() & 0x2000) != 0;
|
||||
}
|
||||
} // namespace Internals
|
||||
|
||||
IPv4Reassembler::IPv4Reassembler(overlapping_technique technique)
|
||||
|
||||
Reference in New Issue
Block a user