diff options
author | Anton Kling <anton@kling.gg> | 2023-10-27 00:48:21 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-10-30 21:49:48 +0100 |
commit | 5026f823fa2708404302aa59d03401635a435c0b (patch) | |
tree | 03d8db6da25416fa27b9744ae60df2cfa5fc1d2b /network/ipv4.c | |
parent | f8e15da04472f5ed6a26e588de4a23cb3e1ba20b (diff) |
Kernel/Networking/LibC: Add syscalls and libc functions for UDP
This allows a UDP server to be created in userland and read data.
Currently it can't send data and is very very simplistic.
Code is horrible and probably needs some fixing until it can be further built
upon.
Diffstat (limited to 'network/ipv4.c')
-rw-r--r-- | network/ipv4.c | 27 |
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; + } +} |