Assertions for TCP and IP header length field

This commit is contained in:
dmiller 2026-06-26 22:06:05 +00:00
parent 3fa8d201fa
commit 4651a54b4b
2 changed files with 4 additions and 4 deletions

View file

@ -234,12 +234,14 @@ u8 IPv4Header::getVersion() const {
int IPv4Header::setHeaderLength(){
assert(ipoptlen <= 40);
h.ip_hl = 5 + (ipoptlen/4);
return OP_SUCCESS;
} /* End of setHeaderLength() */
int IPv4Header::setHeaderLength(u8 l){
assert(l <= 0x0f);
h.ip_hl = l;
return OP_SUCCESS;
} /* End of setHeaderLength() */

View file

@ -260,17 +260,15 @@ u32 TCPHeader::getAck() const {
} /* End of getAck() */
/* TODO: Test this method. It may not work becuasse th_off is supposed to
* be 4 bits long and arg o is 8.
* UPDATE: It seems to work just fine. However, let's keep this note just
* in case problems arise. */
int TCPHeader::setOffset(u8 o){
assert(o <= 0x0f);
h.th_off = o;
return OP_SUCCESS;
} /* End of setOffset() */
int TCPHeader::setOffset(){
assert(tcpoptlen <= 40);
h.th_off = 5 + tcpoptlen/4;
return OP_SUCCESS;
} /* End of setOffset() */