2020-06-05 16:14:17 +02:00
|
|
|
#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);
|
2020-06-16 20:24:59 +02:00
|
|
|
header.payload_length = ntohs(*(uint16_t*)(data + 4));
|
2020-06-05 16:14:17 +02:00
|
|
|
return true;
|
|
|
|
}
|