congestvpn/ip_header.cpp
Théophile Bastian 0b8cf0edc1 Tun: reject packets with bad length
Those packets are probably packets truncated because the buffer is not
large enough.
2020-06-16 20:24:59 +02:00

20 lines
589 B
C++

#include <cstring>
#include "ip_header.hpp"
#include "util.hpp"
bool parse_ipv6_header(const char* data, size_t len, IPv6Header& header) {
if(len < 40) { // header too short
kdebugf("Bad v6 header -- too short.\n");
return false;
}
if((data[0] & 0xf0) != 0x60) { // bad version number
kdebugf("Bad v6 header -- bad version number (byte = %x).\n", data[0]);
return false;
}
memcpy(&(header.source), data + 8, 16);
memcpy(&(header.dest), data + 24, 16);
header.payload_length = ntohs(*(uint16_t*)(data + 4));
return true;
}