VBVX
0.1.0
Header-only C++23 library for safe, zero-copy parsing of packet buffers.
Loading...
Searching...
No Matches
ip6_header.hxx
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstdint>
4
5
#include "
utils.hxx
"
6
#include "
ip_protocol.hxx
"
7
8
namespace
vbvx
{
9
18
struct
[[gnu::packed]]
IPv6Header
{
19
uint32_t
ver_tc_flow_be
;
20
uint16_t
payload_length_be
;
21
uint8_t
next_header
;
22
uint8_t
hop_limit
;
23
uint8_t
src_addr
[16];
24
uint8_t
dst_addr
[16];
25
26
constexpr
auto
ver_tc_flow_host
() const noexcept -> uint32_t {
27
return
autoswap
(
ver_tc_flow_be
);
28
}
29
30
constexpr
auto
version
() const noexcept -> uint8_t {
31
return
static_cast<
uint8_t
>
((
ver_tc_flow_host
() >> 28) & 0x0Fu);
32
}
33
34
constexpr
auto
traffic_class
() const noexcept -> uint8_t {
35
return
static_cast<
uint8_t
>
((
ver_tc_flow_host
() >> 20) & 0xFFu);
36
}
37
38
constexpr
auto
flow_label
() const noexcept -> uint32_t {
39
return
static_cast<
uint32_t
>
(
ver_tc_flow_host
() & 0x000FFFFFu);
40
}
41
42
constexpr
auto
payload_length
() const noexcept -> uint16_t {
43
return
autoswap
(
payload_length_be
);
44
}
45
46
constexpr
auto
l4_protocol
() const noexcept ->
IpProtocol
{
47
return
static_cast<
IpProtocol
>
(
next_header
);
48
}
49
50
constexpr
auto
src_bytes
() const noexcept -> std::span<const uint8_t, 16> {
51
return
std::span<const uint8_t, 16>{
src_addr
, 16};
52
}
53
54
constexpr
auto
dst_bytes
() const noexcept -> std::span<const uint8_t, 16> {
55
return
std::span<const uint8_t, 16>{
dst_addr
, 16};
56
}
57
};
58
59
static_assert
(
sizeof
(IPv6Header) == 40,
"Wrong IPv6 header size"
);
60
static_assert
(
alignof
(IPv6Header) == 1,
"Wrong IPv6 header alignment"
);
61
62
}
// namespace vbvx
ip_protocol.hxx
vbvx
Definition
arp.hxx:11
vbvx::autoswap
constexpr _Tp autoswap(_Tp tp)
Byte-swap a value if the host is little-endian.
Definition
utils.hxx:13
vbvx::IpProtocol
IpProtocol
IP protocol (Next Header) numbers.
Definition
ip_protocol.hxx:13
vbvx::IPv6Header
IPv6 header (40 bytes).
Definition
ip6_header.hxx:18
vbvx::IPv6Header::payload_length_be
uint16_t payload_length_be
Definition
ip6_header.hxx:20
vbvx::IPv6Header::src_bytes
constexpr auto src_bytes() const noexcept -> std::span< const uint8_t, 16 >
Definition
ip6_header.hxx:50
vbvx::IPv6Header::ver_tc_flow_be
uint32_t ver_tc_flow_be
Definition
ip6_header.hxx:19
vbvx::IPv6Header::version
constexpr auto version() const noexcept -> uint8_t
Definition
ip6_header.hxx:30
vbvx::IPv6Header::l4_protocol
constexpr auto l4_protocol() const noexcept -> IpProtocol
Definition
ip6_header.hxx:46
vbvx::IPv6Header::payload_length
constexpr auto payload_length() const noexcept -> uint16_t
Definition
ip6_header.hxx:42
vbvx::IPv6Header::dst_addr
uint8_t dst_addr[16]
Definition
ip6_header.hxx:24
vbvx::IPv6Header::ver_tc_flow_host
constexpr auto ver_tc_flow_host() const noexcept -> uint32_t
Definition
ip6_header.hxx:26
vbvx::IPv6Header::src_addr
uint8_t src_addr[16]
Definition
ip6_header.hxx:23
vbvx::IPv6Header::next_header
uint8_t next_header
Definition
ip6_header.hxx:21
vbvx::IPv6Header::traffic_class
constexpr auto traffic_class() const noexcept -> uint8_t
Definition
ip6_header.hxx:34
vbvx::IPv6Header::dst_bytes
constexpr auto dst_bytes() const noexcept -> std::span< const uint8_t, 16 >
Definition
ip6_header.hxx:54
vbvx::IPv6Header::hop_limit
uint8_t hop_limit
Definition
ip6_header.hxx:22
vbvx::IPv6Header::flow_label
constexpr auto flow_label() const noexcept -> uint32_t
Definition
ip6_header.hxx:38
utils.hxx
vbvx
ip6_header.hxx
Generated by
1.16.0