summaryrefslogtreecommitdiff
path: root/Userland/Services/LookupServer
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-09 16:47:51 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-10 17:26:17 +0200
commitedb21e02ea8ed69aee8f07f4d3129c2a9ca1d9ef (patch)
treefce9ec37aa2816a1e8ec2063533322671ad70d8b /Userland/Services/LookupServer
parent3304d675e1c02c1e0fe857ca94f85cece8f2d837 (diff)
downloadserenity-edb21e02ea8ed69aee8f07f4d3129c2a9ca1d9ef.zip
LookupServer: Track the receive timestamp for DNS answers
Diffstat (limited to 'Userland/Services/LookupServer')
-rw-r--r--Userland/Services/LookupServer/DNSAnswer.cpp7
-rw-r--r--Userland/Services/LookupServer/DNSAnswer.h3
2 files changed, 4 insertions, 6 deletions
diff --git a/Userland/Services/LookupServer/DNSAnswer.cpp b/Userland/Services/LookupServer/DNSAnswer.cpp
index ed1c3bb126..b4c9e8fc9a 100644
--- a/Userland/Services/LookupServer/DNSAnswer.cpp
+++ b/Userland/Services/LookupServer/DNSAnswer.cpp
@@ -18,15 +18,12 @@ DNSAnswer::DNSAnswer(const DNSName& name, DNSRecordType type, DNSRecordClass cla
, m_record_data(record_data)
, m_mdns_cache_flush(mdns_cache_flush)
{
- auto now = time(nullptr);
- m_expiration_time = now + m_ttl;
- if (m_expiration_time < now)
- m_expiration_time = 0;
+ time(&m_received_time);
}
bool DNSAnswer::has_expired() const
{
- return time(nullptr) >= m_expiration_time;
+ return time(nullptr) >= m_received_time + m_ttl;
}
}
diff --git a/Userland/Services/LookupServer/DNSAnswer.h b/Userland/Services/LookupServer/DNSAnswer.h
index 981f589ba7..8b8560efdd 100644
--- a/Userland/Services/LookupServer/DNSAnswer.h
+++ b/Userland/Services/LookupServer/DNSAnswer.h
@@ -40,6 +40,7 @@ public:
DNSRecordClass class_code() const { return m_class_code; }
u16 raw_class_code() const { return (u16)m_class_code | (m_mdns_cache_flush ? MDNS_CACHE_FLUSH : 0); }
u32 ttl() const { return m_ttl; }
+ time_t received_time() const { return m_received_time; }
const String& record_data() const { return m_record_data; }
bool mdns_cache_flush() const { return m_mdns_cache_flush; }
@@ -50,7 +51,7 @@ private:
DNSRecordType m_type { 0 };
DNSRecordClass m_class_code { 0 };
u32 m_ttl { 0 };
- time_t m_expiration_time { 0 };
+ time_t m_received_time { 0 };
String m_record_data;
bool m_mdns_cache_flush { false };
};