VBVX
0.1.0
Header-only C++23 library for safe, zero-copy parsing of packet buffers.
Loading...
Searching...
No Matches
icmp4.hxx
Go to the documentation of this file.
1
#pragma once
2
3
#include <bit>
4
#include <cstdint>
5
#include <optional>
6
7
#include "
utils.hxx
"
8
9
namespace
vbvx
{
10
19
enum class
ICMPv4Type
: uint8_t {
20
EchoReply
= 0,
21
DestinationUnreachable
= 3,
22
SourceQuench
= 4,
23
Redirect
= 5,
24
AlternateHostAddress
= 6,
25
EchoRequest
= 8,
26
RouterAdvertisement
= 9,
27
RouterSolicitation
= 10,
28
TimeExceeded
= 11,
29
ParameterProblem
= 12,
30
Timestamp
= 13,
31
TimestampReply
= 14,
32
InformationRequest
= 15,
33
InformationReply
= 16,
34
AddressMaskRequest
= 17,
35
AddressMaskReply
= 18,
36
ReservedForSecurity
= 19,
37
Traceroute
= 30,
38
DatagramConversionError
= 31,
39
MobileHostRedirect
= 32,
40
IPv6WhereAreYou
= 33,
41
IPv6IamHere
= 34,
42
MobileRegistrationRequest
= 35,
43
MobileRegistrationReply
= 36,
44
DomainNameRequest
= 37,
45
DomainNameReply
= 38,
46
SKIP
= 39,
47
Photuris
= 40,
48
MobilityExperimental
= 41,
49
ExtendedEchoRequest
= 42,
50
ExtendedEchoReply
= 43,
51
Experiment1
= 253,
52
Experiment2
= 254,
53
Reserved
= 255
54
};
55
64
struct
[[gnu::packed]]
ICMPv4Header
{
65
uint8_t
type
;
66
uint8_t
code
;
67
uint16_t
checksum_be
;
68
69
constexpr
auto
type_u8
() const noexcept -> uint8_t {
return
type
; }
70
constexpr
auto
code_u8
() const noexcept -> uint8_t {
return
code
; }
71
72
constexpr
auto
checksum
() const noexcept -> uint16_t {
73
return
autoswap
(
checksum_be
);
74
}
75
76
constexpr
auto
type_known
() const noexcept -> std::optional<
ICMPv4Type
> {
77
using
enum
ICMPv4Type
;
78
79
switch
(
type
) {
80
case
0:
return
EchoReply
;
81
case
3:
return
DestinationUnreachable
;
82
case
4:
return
SourceQuench
;
83
case
5:
return
Redirect
;
84
case
6:
return
AlternateHostAddress
;
85
case
8:
return
EchoRequest
;
86
case
9:
return
RouterAdvertisement
;
87
case
10:
return
RouterSolicitation
;
88
case
11:
return
TimeExceeded
;
89
case
12:
return
ParameterProblem
;
90
case
13:
return
Timestamp
;
91
case
14:
return
TimestampReply
;
92
case
15:
return
InformationRequest
;
93
case
16:
return
InformationReply
;
94
case
17:
return
AddressMaskRequest
;
95
case
18:
return
AddressMaskReply
;
96
case
19:
return
ReservedForSecurity
;
97
case
30:
return
Traceroute
;
98
case
31:
return
DatagramConversionError
;
99
case
32:
return
MobileHostRedirect
;
100
case
33:
return
IPv6WhereAreYou
;
101
case
34:
return
IPv6IamHere
;
102
case
35:
return
MobileRegistrationRequest
;
103
case
36:
return
MobileRegistrationReply
;
104
case
37:
return
DomainNameRequest
;
105
case
38:
return
DomainNameReply
;
106
case
39:
return
SKIP
;
107
case
40:
return
Photuris
;
108
case
41:
return
MobilityExperimental
;
109
case
42:
return
ExtendedEchoRequest
;
110
case
43:
return
ExtendedEchoReply
;
111
case
253:
return
Experiment1
;
112
case
254:
return
Experiment2
;
113
case
255:
return
Reserved
;
114
default
:
return
std::nullopt;
115
}
116
}
117
118
constexpr
void
set_checksum
(uint16_t v)
noexcept
{
119
checksum_be
=
autoswap
(v);
120
}
121
};
122
123
static_assert
(
sizeof
(ICMPv4Header) == 4,
"Wrong ICMP header size"
);
124
static_assert
(
alignof
(ICMPv4Header) == 1,
"Wrong ICMP header alignment"
);
125
126
}
// namespace vbvx
vbvx
Definition
arp.hxx:11
vbvx::ICMPv4Type
ICMPv4Type
ICMPv4 Type Numbers.
Definition
icmp4.hxx:19
vbvx::ICMPv4Type::AddressMaskReply
@ AddressMaskReply
Definition
icmp4.hxx:35
vbvx::ICMPv4Type::ReservedForSecurity
@ ReservedForSecurity
Definition
icmp4.hxx:36
vbvx::ICMPv4Type::Traceroute
@ Traceroute
Definition
icmp4.hxx:37
vbvx::ICMPv4Type::Photuris
@ Photuris
Definition
icmp4.hxx:47
vbvx::ICMPv4Type::MobilityExperimental
@ MobilityExperimental
Definition
icmp4.hxx:48
vbvx::ICMPv4Type::SourceQuench
@ SourceQuench
Definition
icmp4.hxx:22
vbvx::ICMPv4Type::ExtendedEchoReply
@ ExtendedEchoReply
Definition
icmp4.hxx:50
vbvx::ICMPv4Type::DomainNameRequest
@ DomainNameRequest
Definition
icmp4.hxx:44
vbvx::ICMPv4Type::Redirect
@ Redirect
Definition
icmp4.hxx:23
vbvx::ICMPv4Type::RouterAdvertisement
@ RouterAdvertisement
Definition
icmp4.hxx:26
vbvx::ICMPv4Type::Experiment1
@ Experiment1
Definition
icmp4.hxx:51
vbvx::ICMPv4Type::AddressMaskRequest
@ AddressMaskRequest
Definition
icmp4.hxx:34
vbvx::ICMPv4Type::EchoRequest
@ EchoRequest
Definition
icmp4.hxx:25
vbvx::ICMPv4Type::TimestampReply
@ TimestampReply
Definition
icmp4.hxx:31
vbvx::ICMPv4Type::Experiment2
@ Experiment2
Definition
icmp4.hxx:52
vbvx::ICMPv4Type::IPv6IamHere
@ IPv6IamHere
Definition
icmp4.hxx:41
vbvx::ICMPv4Type::MobileRegistrationRequest
@ MobileRegistrationRequest
Definition
icmp4.hxx:42
vbvx::ICMPv4Type::TimeExceeded
@ TimeExceeded
Definition
icmp4.hxx:28
vbvx::ICMPv4Type::RouterSolicitation
@ RouterSolicitation
Definition
icmp4.hxx:27
vbvx::ICMPv4Type::InformationReply
@ InformationReply
Definition
icmp4.hxx:33
vbvx::ICMPv4Type::InformationRequest
@ InformationRequest
Definition
icmp4.hxx:32
vbvx::ICMPv4Type::Reserved
@ Reserved
Definition
icmp4.hxx:53
vbvx::ICMPv4Type::MobileRegistrationReply
@ MobileRegistrationReply
Definition
icmp4.hxx:43
vbvx::ICMPv4Type::Timestamp
@ Timestamp
Definition
icmp4.hxx:30
vbvx::ICMPv4Type::AlternateHostAddress
@ AlternateHostAddress
Definition
icmp4.hxx:24
vbvx::ICMPv4Type::ExtendedEchoRequest
@ ExtendedEchoRequest
Definition
icmp4.hxx:49
vbvx::ICMPv4Type::IPv6WhereAreYou
@ IPv6WhereAreYou
Definition
icmp4.hxx:40
vbvx::ICMPv4Type::SKIP
@ SKIP
Definition
icmp4.hxx:46
vbvx::ICMPv4Type::ParameterProblem
@ ParameterProblem
Definition
icmp4.hxx:29
vbvx::ICMPv4Type::MobileHostRedirect
@ MobileHostRedirect
Definition
icmp4.hxx:39
vbvx::ICMPv4Type::DomainNameReply
@ DomainNameReply
Definition
icmp4.hxx:45
vbvx::ICMPv4Type::DestinationUnreachable
@ DestinationUnreachable
Definition
icmp4.hxx:21
vbvx::ICMPv4Type::DatagramConversionError
@ DatagramConversionError
Definition
icmp4.hxx:38
vbvx::ICMPv4Type::EchoReply
@ EchoReply
Definition
icmp4.hxx:20
vbvx::autoswap
constexpr _Tp autoswap(_Tp tp)
Byte-swap a value if the host is little-endian.
Definition
utils.hxx:13
vbvx::ICMPv4Header
ICMP header (type, code, checksum) (4 bytes).
Definition
icmp4.hxx:64
vbvx::ICMPv4Header::checksum
constexpr auto checksum() const noexcept -> uint16_t
Definition
icmp4.hxx:72
vbvx::ICMPv4Header::code_u8
constexpr auto code_u8() const noexcept -> uint8_t
Definition
icmp4.hxx:70
vbvx::ICMPv4Header::checksum_be
uint16_t checksum_be
Definition
icmp4.hxx:67
vbvx::ICMPv4Header::type
uint8_t type
Definition
icmp4.hxx:65
vbvx::ICMPv4Header::type_known
constexpr auto type_known() const noexcept -> std::optional< ICMPv4Type >
Definition
icmp4.hxx:76
vbvx::ICMPv4Header::type_u8
constexpr auto type_u8() const noexcept -> uint8_t
Definition
icmp4.hxx:69
vbvx::ICMPv4Header::code
uint8_t code
Definition
icmp4.hxx:66
vbvx::ICMPv4Header::set_checksum
constexpr void set_checksum(uint16_t v) noexcept
Definition
icmp4.hxx:118
utils.hxx
vbvx
icmp4.hxx
Generated by
1.16.0