20 lines
590 B
C++
20 lines
590 B
C++
#include <string.h>
|
|
|
|
#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;
|
|
}
|