diff options
author | Tom <tomut@yahoo.com> | 2022-04-12 23:41:02 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-04-15 16:34:26 +0100 |
commit | a3a1fe833b22f75319fb8114bb15bb18e0ad91c1 (patch) | |
tree | c05890149055776731801e774791bab36770718e | |
parent | f3af82585d493adebfe83a19b250d011dd4fa0fa (diff) | |
download | serenity-a3a1fe833b22f75319fb8114bb15bb18e0ad91c1.zip |
LibDNS: Add IPC encoder/decoder for the DNSAnswer class
-rw-r--r-- | Userland/Libraries/LibDNS/DNSAnswer.cpp | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibDNS/DNSAnswer.h | 8 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Userland/Libraries/LibDNS/DNSAnswer.cpp b/Userland/Libraries/LibDNS/DNSAnswer.cpp index 9dce5f4877..e395eee498 100644 --- a/Userland/Libraries/LibDNS/DNSAnswer.cpp +++ b/Userland/Libraries/LibDNS/DNSAnswer.cpp @@ -6,6 +6,8 @@ #include "DNSAnswer.h" #include <AK/Stream.h> +#include <LibIPC/Decoder.h> +#include <LibIPC/Encoder.h> #include <time.h> namespace DNS { @@ -95,3 +97,30 @@ ErrorOr<void> AK::Formatter<DNS::DNSRecordClass>::format(AK::FormatBuilder& buil TRY(builder.put_u64((u16)value)); return {}; } + +namespace IPC { + +bool encode(Encoder& encoder, DNS::DNSAnswer const& answer) +{ + encoder << answer.name().as_string() << (u16)answer.type() << (u16)answer.class_code() << answer.ttl() << answer.record_data() << answer.mdns_cache_flush(); + return true; +} + +ErrorOr<void> decode(Decoder& decoder, DNS::DNSAnswer& answer) +{ + String name; + TRY(decoder.decode(name)); + u16 record_type, class_code; + TRY(decoder.decode(record_type)); + TRY(decoder.decode(class_code)); + u32 ttl; + TRY(decoder.decode(ttl)); + String record_data; + TRY(decoder.decode(record_data)); + bool cache_flush; + TRY(decoder.decode(cache_flush)); + answer = { { name }, (DNS::DNSRecordType)record_type, (DNS::DNSRecordClass)class_code, ttl, record_data, cache_flush }; + return {}; +} + +} diff --git a/Userland/Libraries/LibDNS/DNSAnswer.h b/Userland/Libraries/LibDNS/DNSAnswer.h index 459028dc7a..b237aad2b1 100644 --- a/Userland/Libraries/LibDNS/DNSAnswer.h +++ b/Userland/Libraries/LibDNS/DNSAnswer.h @@ -11,6 +11,7 @@ #include <AK/String.h> #include <AK/Traits.h> #include <AK/Types.h> +#include <LibIPC/Forward.h> namespace DNS { @@ -90,3 +91,10 @@ struct AK::Formatter<DNS::DNSRecordClass> : StandardFormatter { ErrorOr<void> format(AK::FormatBuilder&, DNS::DNSRecordClass); }; + +namespace IPC { + +bool encode(Encoder&, DNS::DNSAnswer const&); +ErrorOr<void> decode(Decoder&, DNS::DNSAnswer&); + +} |