29 using buffer_t = uint8_t;
33 : data_{
static_cast<const buffer_t*
>(
data)}, length_{
length} {}
36 constexpr auto data() const noexcept -> std::span<const buffer_t> {
40 return {data_, length_};
44 constexpr auto length() const noexcept -> uint16_t {
return length_; }
48 return header_at<EtherHeader>(0);
58 auto type = eth->type();
64 return static_cast<EtherType>(vlan->type());
77 auto type = eth->type();
86 constexpr auto vlan_id() const noexcept -> std::optional<uint16_t> {
91 return static_cast<uint16_t
>(vlan->tci() & 0x0FFFu);
95 constexpr auto l3_offset() const noexcept -> uint16_t {
100 auto type = eth->type();
112 return header_at<ArpHeader>(
l3_offset());
121 return header_at<IPv4Header>(
l3_offset());
130 return header_at<IPv6Header>(
l3_offset());
139 const buffer_t ihl =
static_cast<uint8_t
>(ip->version_ihl & 0x0Fu);
140 const buffer_t bytes =
static_cast<uint8_t
>(ihl * 4u);
150 return static_cast<IpProtocol>(ip4->protocol);
153 return static_cast<IpProtocol>(ip6->next_header);
159 constexpr auto l4_offset() const noexcept -> std::optional<uint16_t> {
177 if (!proto || !off) {
183 return header_at<TCPHeader>(*off);
190 if (!proto || !off) {
196 return header_at<UDPHeader>(*off);
207 return header_at<ICMPv4Header>(*off);
218 return header_at<ICMPv6Header>(*off);
232 return header_at<SRv6Header>(offset);
236 template <WireHeader H>
237 constexpr auto header_at(uint16_t offset)
const noexcept ->
HeaderView<H> {
239 if (offset +
sizeof(H) > _data.size()) {
242 return HeaderView<H>{_data.data() + offset};
245 const buffer_t* data_{};
constexpr auto ip4_ihl_bytes() const noexcept -> std::optional< uint8_t >
Get the number of bytes in the IPv4 header.
Definition buffer_view.hxx:134
constexpr auto l4_offset() const noexcept -> std::optional< uint16_t >
Get the offset of the Layer 4 header.
Definition buffer_view.hxx:159
constexpr auto ip_protocol() const noexcept -> std::optional< IpProtocol >
Get the IP protocol (IPv4 or IPv6).
Definition buffer_view.hxx:148
constexpr auto length() const noexcept -> uint16_t
Get the length of the buffer.
Definition buffer_view.hxx:44
constexpr auto ether_header() const noexcept -> HeaderView< EtherHeader >
Get Ethernet header view.
Definition buffer_view.hxx:47
constexpr auto arp_header() const noexcept -> HeaderView< ArpHeader >
Get ARP header view.
Definition buffer_view.hxx:107
constexpr auto tcp_header() const noexcept -> HeaderView< TCPHeader >
Get TCP header view.
Definition buffer_view.hxx:174
constexpr auto vlan_header() const noexcept -> HeaderView< VlanHeader >
Get VLAN header view.
Definition buffer_view.hxx:71
constexpr auto ether_type() const noexcept -> std::optional< EtherType >
Get the EtherType of the packet for possible VLAN tag.
Definition buffer_view.hxx:52
constexpr auto srv6_header() const noexcept -> HeaderView< SRv6Header >
Get SRv6 Header view if present.
Definition buffer_view.hxx:222
constexpr auto icmp6_header() const noexcept -> HeaderView< ICMPv6Header >
Get ICMPv6 header view.
Definition buffer_view.hxx:211
constexpr auto icmp4_header() const noexcept -> HeaderView< ICMPv4Header >
Get ICMPv4 header view.
Definition buffer_view.hxx:200
constexpr auto ip6_header() const noexcept -> HeaderView< IPv6Header >
Get IPv6 header view.
Definition buffer_view.hxx:125
constexpr auto vlan_id() const noexcept -> std::optional< uint16_t >
Get VLAN ID if VLAN tag is present.
Definition buffer_view.hxx:86
constexpr auto ip4_header() const noexcept -> HeaderView< IPv4Header >
Get IPv4 header view.
Definition buffer_view.hxx:116
constexpr auto l3_offset() const noexcept -> uint16_t
Get the offset of the Layer 3 header.
Definition buffer_view.hxx:95
constexpr auto udp_header() const noexcept -> HeaderView< UDPHeader >
Get UDP header view.
Definition buffer_view.hxx:187
constexpr BufferView(const void *data, uint16_t length) noexcept
Definition buffer_view.hxx:32
constexpr auto data() const noexcept -> std::span< const buffer_t >
Get the underlying buffer data as a span.
Definition buffer_view.hxx:36
EtherType
Ethernet frame EtherType values (network byte order).
Definition ether.hxx:19
@ IPv4
Definition ether.hxx:20
@ VLAN
Definition ether.hxx:22
@ ARP
Definition ether.hxx:21
@ IPv6
Definition ether.hxx:23
IpProtocol
IP protocol (Next Header) numbers.
Definition ip_protocol.hxx:13
@ IPv6_Route
Definition ip_protocol.hxx:57
@ ICMPv4
Definition ip_protocol.hxx:15
@ TCP
Definition ip_protocol.hxx:20
@ ICMPv6
Definition ip_protocol.hxx:72
@ UDP
Definition ip_protocol.hxx:31