Coverage Report

Created: 2026-09-26 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibDNS/PacketHeader.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/Endian.h>
10
#include <AK/Types.h>
11
12
namespace DNS {
13
14
class [[gnu::packed]] PacketHeader {
15
public:
16
    PacketHeader()
17
450
        : m_recursion_desired(false)
18
450
        , m_truncated(false)
19
450
        , m_authoritative_answer(false)
20
450
        , m_opcode(0)
21
450
        , m_query_or_response(false)
22
450
        , m_response_code(0)
23
450
        , m_checking_disabled(false)
24
450
        , m_authenticated_data(false)
25
450
        , m_zero(false)
26
450
        , m_recursion_available(false)
27
450
    {
28
450
    }
29
30
1.29k
    u16 id() const { return m_id; }
31
450
    void set_id(u16 w) { m_id = w; }
32
33
0
    bool recursion_desired() const { return m_recursion_desired; }
34
450
    void set_recursion_desired(bool b) { m_recursion_desired = b; }
35
36
0
    bool is_truncated() const { return m_truncated; }
37
450
    void set_truncated(bool b) { m_truncated = b; }
38
39
0
    bool is_authoritative_answer() const { return m_authoritative_answer; }
40
450
    void set_authoritative_answer(bool b) { m_authoritative_answer = b; }
41
42
0
    u8 opcode() const { return m_opcode; }
43
450
    void set_opcode(u8 b) { m_opcode = b; }
44
45
0
    bool is_query() const { return !m_query_or_response; }
46
1.29k
    bool is_response() const { return m_query_or_response; }
47
398
    void set_is_query() { m_query_or_response = false; }
48
52
    void set_is_response() { m_query_or_response = true; }
49
50
1.29k
    u8 response_code() const { return m_response_code; }
51
450
    void set_response_code(u8 b) { m_response_code = b; }
52
53
0
    bool checking_disabled() const { return m_checking_disabled; }
54
0
    void set_checking_disabled(bool b) { m_checking_disabled = b; }
55
56
0
    bool is_authenticated_data() const { return m_authenticated_data; }
57
0
    void set_authenticated_data(bool b) { m_authenticated_data = b; }
58
59
0
    bool is_recursion_available() const { return m_recursion_available; }
60
450
    void set_recursion_available(bool b) { m_recursion_available = b; }
61
62
6.54M
    u16 question_count() const { return m_question_count; }
63
450
    void set_question_count(u16 w) { m_question_count = w; }
64
65
1.39M
    u16 answer_count() const { return m_answer_count; }
66
450
    void set_answer_count(u16 w) { m_answer_count = w; }
67
68
0
    u16 authority_count() const { return m_authority_count; }
69
0
    void set_authority_count(u16 w) { m_authority_count = w; }
70
71
0
    u16 additional_count() const { return m_additional_count; }
72
0
    void set_additional_count(u16 w) { m_additional_count = w; }
73
74
0
    void* payload() { return this + 1; }
75
0
    void const* payload() const { return this + 1; }
76
77
private:
78
    NetworkOrdered<u16> m_id;
79
80
    bool m_recursion_desired : 1;
81
    bool m_truncated : 1;
82
    bool m_authoritative_answer : 1;
83
    u8 m_opcode : 4;
84
    bool m_query_or_response : 1;
85
    u8 m_response_code : 4;
86
    bool m_checking_disabled : 1;
87
    bool m_authenticated_data : 1;
88
    bool m_zero : 1;
89
    bool m_recursion_available : 1;
90
91
    NetworkOrdered<u16> m_question_count;
92
    NetworkOrdered<u16> m_answer_count;
93
    NetworkOrdered<u16> m_authority_count;
94
    NetworkOrdered<u16> m_additional_count;
95
};
96
97
static_assert(sizeof(PacketHeader) == 12);
98
99
}
100
101
template<>
102
struct AK::Traits<DNS::PacketHeader> : public AK::DefaultTraits<DNS::PacketHeader> {
103
0
    static constexpr bool is_trivially_serializable() { return true; }
104
};