Parse roughly IPv6 header
This commit is contained in:
parent
55ada8abc1
commit
8b75660bbc
3 changed files with 31 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ CXX=g++
|
||||||
CXXFLAGS=-O2 -g -Wall -Wextra -std=c++17
|
CXXFLAGS=-O2 -g -Wall -Wextra -std=c++17
|
||||||
CXXLIBS=
|
CXXLIBS=
|
||||||
|
|
||||||
OBJS=UdpVpn.o VpnPeer.o TunDevice.o util.o main.o
|
OBJS=UdpVpn.o VpnPeer.o TunDevice.o ip_header.o util.o main.o
|
||||||
TARGET=congestvpn
|
TARGET=congestvpn
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
19
ip_header.cpp
Normal file
19
ip_header.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#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);
|
||||||
|
return true;
|
||||||
|
}
|
11
ip_header.hpp
Normal file
11
ip_header.hpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
struct IPv6Header {
|
||||||
|
in6_addr source;
|
||||||
|
in6_addr dest;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Parse an IPv6 header, filling `header`. Returns `true` on success. */
|
||||||
|
bool parse_ipv6_header(const char* data, size_t len, IPv6Header& header);
|
Loading…
Reference in a new issue