CS 144 Checkpoint 6 - IP Router
![](/cs144-checkpoint-6/ip_router.jpeg)
Series - CS 144
Contents
“In this week’s lab checkpoint, you’ll implement an IP router on top of your existing
NetworkInterface
.”
There are two pitfalls to watch out for in this checkpoint.
When testing whether two IP addresses match, the case where the prefix_length
is zero must be handled separately. A right shift of 32 bits on uint32_t
is undefined behavior in C++.
[[nodiscard]] bool match( uint32_t other ) const
{
return prefix_length == 0 || ( route_prefix >> ( 32 - prefix_length ) ) == ( other >> ( 32 - prefix_length ) );
}
When decreasing the TTL of a datagram, the checksum of the packet must be recalculated, because the checksum is calculated over the entire IP header, including the TTL field.
This concludes Checkpoint 6.