14static constexpr uint16_t FRAG_FLAGS_MASK = 0xE000u;
15static constexpr uint16_t FRAG_OFFSET_MASK = 0x1FFFu;
47 constexpr auto version() const noexcept -> uint8_t {
51 constexpr auto ihl_words() const noexcept -> uint16_t {
55 constexpr auto ihl_bytes() const noexcept -> uint16_t {
59 constexpr auto dscp() const noexcept -> uint8_t {
return (
tos >> 2) & 0x3Fu; }
60 constexpr auto ecn() const noexcept -> uint8_t {
return tos & 0x03u; }
68 constexpr auto frag_off() const noexcept -> uint16_t {
81 return static_cast<uint16_t
>(
frag_off() & FRAG_OFFSET_MASK);
94 raw &= FRAG_OFFSET_MASK;
95 raw |=
static_cast<uint16_t
>(std::to_underlying(flags) & FRAG_FLAGS_MASK);
101 raw &= FRAG_FLAGS_MASK;
102 raw |=
static_cast<uint16_t
>(units8 & FRAG_OFFSET_MASK);
110 constexpr void set_df(
bool enabled)
noexcept {
114 constexpr void set_mf(
bool enabled)
noexcept {
122 constexpr auto checksum() const noexcept -> uint16_t {
130 constexpr auto src_addr() const noexcept -> uint32_t {
134 constexpr auto dst_addr() const noexcept -> uint32_t {
143 constexpr void set_flag(
IPv4Flags flag,
bool enabled)
noexcept {
144 auto raw = frag_off();
145 const auto mask = std::to_underlying(flag);
147 raw |=
static_cast<uint16_t
>(mask);
149 raw &=
static_cast<uint16_t
>(~mask);
154static_assert(
sizeof(
IPv4Header) == 20,
"Wrong IPv4 header size");
155static_assert(
alignof(
IPv4Header) == 1,
"Wrong IPv4 header alignment");
IPv4Flags
IPv4 fragmentation flags.
Definition ip4_header.hxx:18
@ MF
Definition ip4_header.hxx:20
@ None
Definition ip4_header.hxx:19
@ DF
Definition ip4_header.hxx:21
@ RFU
Definition ip4_header.hxx:22
constexpr _Tp autoswap(_Tp tp)
Byte-swap a value if the host is little-endian.
Definition utils.hxx:13
IpProtocol
IP protocol (Next Header) numbers.
Definition ip_protocol.hxx:13
Enable bitwise operators for an enum class.
Definition flags_view.hxx:25