summaryrefslogtreecommitdiff
path: root/network/ipv4.c
diff options
context:
space:
mode:
Diffstat (limited to 'network/ipv4.c')
-rw-r--r--network/ipv4.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/network/ipv4.c b/network/ipv4.c
new file mode 100644
index 0000000..27b38ec
--- /dev/null
+++ b/network/ipv4.c
@@ -0,0 +1,27 @@
+#include <assert.h>
+#include <network/bytes.h>
+#include <network/ipv4.h>
+#include <network/udp.h>
+
+void handle_ipv4(const uint8_t *payload, uint32_t packet_length) {
+ assert(packet_length > 4);
+ uint8_t version = (*payload & 0xF0) >> 4;
+ uint8_t IHL = (*payload & 0xF);
+ kprintf("version: %x\n", version);
+ assert(4 == version);
+ assert(5 == IHL);
+ uint16_t ipv4_total_length = ntohs(*(uint16_t *)(payload + 2));
+ assert(ipv4_total_length >= 20);
+ // Make sure the ipv4 header is not trying to get uninitalized memory
+ assert(ipv4_total_length <= packet_length);
+
+ uint8_t protocol = *(payload + 9);
+ switch (protocol) {
+ case 0x11:
+ handle_udp(payload + 20, ipv4_total_length - 20);
+ break;
+ default:
+ kprintf("Protocol given in IPv4 header not handeld: %x\n", protocol);
+ break;
+ }
+}