mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LookupServer: Move DNS related code into new LibDNS library
This allows other code to use the DNSPacket class, e.g. when sent over IPC.
This commit is contained in:
parent
0a92dbd390
commit
be4a4144f2
17 changed files with 51 additions and 40 deletions
|
@ -15,6 +15,7 @@ add_subdirectory(LibDesktop)
|
||||||
add_subdirectory(LibDeviceTree)
|
add_subdirectory(LibDeviceTree)
|
||||||
add_subdirectory(LibDiff)
|
add_subdirectory(LibDiff)
|
||||||
add_subdirectory(LibDl)
|
add_subdirectory(LibDl)
|
||||||
|
add_subdirectory(LibDNS)
|
||||||
add_subdirectory(LibDSP)
|
add_subdirectory(LibDSP)
|
||||||
add_subdirectory(LibEDID)
|
add_subdirectory(LibEDID)
|
||||||
add_subdirectory(LibELF)
|
add_subdirectory(LibELF)
|
||||||
|
|
8
Userland/Libraries/LibDNS/CMakeLists.txt
Normal file
8
Userland/Libraries/LibDNS/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
set(SOURCES
|
||||||
|
DNSAnswer.cpp
|
||||||
|
DNSName.cpp
|
||||||
|
DNSPacket.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
serenity_lib(LibDNS dns)
|
||||||
|
target_link_libraries(LibDNS LibC)
|
|
@ -8,7 +8,7 @@
|
||||||
#include <AK/Stream.h>
|
#include <AK/Stream.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
DNSAnswer::DNSAnswer(DNSName const& name, DNSRecordType type, DNSRecordClass class_code, u32 ttl, String const& record_data, bool mdns_cache_flush)
|
DNSAnswer::DNSAnswer(DNSName const& name, DNSRecordType type, DNSRecordClass class_code, u32 ttl, String const& record_data, bool mdns_cache_flush)
|
||||||
: m_name(name)
|
: m_name(name)
|
||||||
|
@ -28,26 +28,26 @@ bool DNSAnswer::has_expired() const
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> AK::Formatter<LookupServer::DNSRecordType>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordType value)
|
ErrorOr<void> AK::Formatter<DNS::DNSRecordType>::format(AK::FormatBuilder& builder, DNS::DNSRecordType value)
|
||||||
{
|
{
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case LookupServer::DNSRecordType::A:
|
case DNS::DNSRecordType::A:
|
||||||
return builder.put_string("A");
|
return builder.put_string("A");
|
||||||
case LookupServer::DNSRecordType::NS:
|
case DNS::DNSRecordType::NS:
|
||||||
return builder.put_string("NS");
|
return builder.put_string("NS");
|
||||||
case LookupServer::DNSRecordType::CNAME:
|
case DNS::DNSRecordType::CNAME:
|
||||||
return builder.put_string("CNAME");
|
return builder.put_string("CNAME");
|
||||||
case LookupServer::DNSRecordType::SOA:
|
case DNS::DNSRecordType::SOA:
|
||||||
return builder.put_string("SOA");
|
return builder.put_string("SOA");
|
||||||
case LookupServer::DNSRecordType::PTR:
|
case DNS::DNSRecordType::PTR:
|
||||||
return builder.put_string("PTR");
|
return builder.put_string("PTR");
|
||||||
case LookupServer::DNSRecordType::MX:
|
case DNS::DNSRecordType::MX:
|
||||||
return builder.put_string("MX");
|
return builder.put_string("MX");
|
||||||
case LookupServer::DNSRecordType::TXT:
|
case DNS::DNSRecordType::TXT:
|
||||||
return builder.put_string("TXT");
|
return builder.put_string("TXT");
|
||||||
case LookupServer::DNSRecordType::AAAA:
|
case DNS::DNSRecordType::AAAA:
|
||||||
return builder.put_string("AAAA");
|
return builder.put_string("AAAA");
|
||||||
case LookupServer::DNSRecordType::SRV:
|
case DNS::DNSRecordType::SRV:
|
||||||
return builder.put_string("SRV");
|
return builder.put_string("SRV");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,10 +56,10 @@ ErrorOr<void> AK::Formatter<LookupServer::DNSRecordType>::format(AK::FormatBuild
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> AK::Formatter<LookupServer::DNSRecordClass>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordClass value)
|
ErrorOr<void> AK::Formatter<DNS::DNSRecordClass>::format(AK::FormatBuilder& builder, DNS::DNSRecordClass value)
|
||||||
{
|
{
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case LookupServer::DNSRecordClass::IN:
|
case DNS::DNSRecordClass::IN:
|
||||||
return builder.put_string("IN");
|
return builder.put_string("IN");
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
enum class DNSRecordType : u16 {
|
enum class DNSRecordType : u16 {
|
||||||
A = 1,
|
A = 1,
|
||||||
|
@ -58,23 +58,23 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<LookupServer::DNSRecordType> : StandardFormatter {
|
struct AK::Formatter<DNS::DNSRecordType> : StandardFormatter {
|
||||||
Formatter() = default;
|
Formatter() = default;
|
||||||
explicit Formatter(StandardFormatter formatter)
|
explicit Formatter(StandardFormatter formatter)
|
||||||
: StandardFormatter(formatter)
|
: StandardFormatter(formatter)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> format(AK::FormatBuilder&, LookupServer::DNSRecordType);
|
ErrorOr<void> format(AK::FormatBuilder&, DNS::DNSRecordType);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<LookupServer::DNSRecordClass> : StandardFormatter {
|
struct AK::Formatter<DNS::DNSRecordClass> : StandardFormatter {
|
||||||
Formatter() = default;
|
Formatter() = default;
|
||||||
explicit Formatter(StandardFormatter formatter)
|
explicit Formatter(StandardFormatter formatter)
|
||||||
: StandardFormatter(formatter)
|
: StandardFormatter(formatter)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> format(AK::FormatBuilder&, LookupServer::DNSRecordClass);
|
ErrorOr<void> format(AK::FormatBuilder&, DNS::DNSRecordClass);
|
||||||
};
|
};
|
|
@ -10,7 +10,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
DNSName::DNSName(String const& name)
|
DNSName::DNSName(String const& name)
|
||||||
{
|
{
|
|
@ -10,7 +10,7 @@
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
class DNSName {
|
class DNSName {
|
||||||
public:
|
public:
|
||||||
|
@ -40,8 +40,8 @@ OutputStream& operator<<(OutputStream& stream, DNSName const&);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct AK::Formatter<LookupServer::DNSName> : Formatter<StringView> {
|
struct AK::Formatter<DNS::DNSName> : Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, LookupServer::DNSName const& value)
|
ErrorOr<void> format(FormatBuilder& builder, DNS::DNSName const& value)
|
||||||
{
|
{
|
||||||
return Formatter<StringView>::format(builder, value.as_string());
|
return Formatter<StringView>::format(builder, value.as_string());
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
void DNSPacket::add_question(DNSQuestion const& question)
|
void DNSPacket::add_question(DNSQuestion const& question)
|
||||||
{
|
{
|
|
@ -13,7 +13,7 @@
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
enum class ShouldRandomizeCase {
|
enum class ShouldRandomizeCase {
|
||||||
No = 0,
|
No = 0,
|
|
@ -9,7 +9,7 @@
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
class [[gnu::packed]] DNSPacketHeader {
|
class [[gnu::packed]] DNSPacketHeader {
|
||||||
public:
|
public:
|
|
@ -9,7 +9,7 @@
|
||||||
#include "DNSName.h"
|
#include "DNSName.h"
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace DNS {
|
||||||
|
|
||||||
#define MDNS_WANTS_UNICAST_RESPONSE 0x8000
|
#define MDNS_WANTS_UNICAST_RESPONSE 0x8000
|
||||||
|
|
|
@ -8,9 +8,6 @@ compile_ipc(LookupServer.ipc LookupServerEndpoint.h)
|
||||||
compile_ipc(LookupClient.ipc LookupClientEndpoint.h)
|
compile_ipc(LookupClient.ipc LookupClientEndpoint.h)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
DNSAnswer.cpp
|
|
||||||
DNSName.cpp
|
|
||||||
DNSPacket.cpp
|
|
||||||
DNSServer.cpp
|
DNSServer.cpp
|
||||||
LookupServer.cpp
|
LookupServer.cpp
|
||||||
LookupServerEndpoint.h
|
LookupServerEndpoint.h
|
||||||
|
@ -21,4 +18,4 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_bin(LookupServer)
|
serenity_bin(LookupServer)
|
||||||
target_link_libraries(LookupServer LibCore LibIPC LibMain)
|
target_link_libraries(LookupServer LibCore LibDNS LibIPC LibMain)
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ConnectionFromClient.h"
|
#include "ConnectionFromClient.h"
|
||||||
#include "DNSPacket.h"
|
|
||||||
#include "LookupServer.h"
|
#include "LookupServer.h"
|
||||||
#include <AK/IPv4Address.h>
|
#include <AK/IPv4Address.h>
|
||||||
|
#include <LibDNS/DNSPacket.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace LookupServer {
|
||||||
|
|
||||||
|
using namespace DNS;
|
||||||
|
|
||||||
static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
|
static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
|
||||||
|
|
||||||
ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, int client_id)
|
ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, int client_id)
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DNSServer.h"
|
#include "DNSServer.h"
|
||||||
#include "DNSPacket.h"
|
|
||||||
#include "LookupServer.h"
|
#include "LookupServer.h"
|
||||||
#include <AK/IPv4Address.h>
|
#include <AK/IPv4Address.h>
|
||||||
|
#include <LibDNS/DNSPacket.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace LookupServer {
|
||||||
|
|
||||||
|
using namespace DNS;
|
||||||
|
|
||||||
DNSServer::DNSServer(Object* parent)
|
DNSServer::DNSServer(Object* parent)
|
||||||
: Core::UDPServer(parent)
|
: Core::UDPServer(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "LookupServer.h"
|
#include "LookupServer.h"
|
||||||
#include "ConnectionFromClient.h"
|
#include "ConnectionFromClient.h"
|
||||||
#include "DNSPacket.h"
|
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/Random.h>
|
#include <AK/Random.h>
|
||||||
|
@ -16,6 +15,7 @@
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/LocalServer.h>
|
#include <LibCore/LocalServer.h>
|
||||||
#include <LibCore/Stream.h>
|
#include <LibCore/Stream.h>
|
||||||
|
#include <LibDNS/DNSPacket.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ConnectionFromClient.h"
|
#include "ConnectionFromClient.h"
|
||||||
#include "DNSName.h"
|
|
||||||
#include "DNSPacket.h"
|
|
||||||
#include "DNSServer.h"
|
#include "DNSServer.h"
|
||||||
#include "MulticastDNS.h"
|
#include "MulticastDNS.h"
|
||||||
#include <LibCore/FileWatcher.h>
|
#include <LibCore/FileWatcher.h>
|
||||||
#include <LibCore/Object.h>
|
#include <LibCore/Object.h>
|
||||||
|
#include <LibDNS/DNSName.h>
|
||||||
|
#include <LibDNS/DNSPacket.h>
|
||||||
#include <LibIPC/MultiServer.h>
|
#include <LibIPC/MultiServer.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace LookupServer {
|
||||||
|
|
||||||
class DNSAnswer;
|
using namespace DNS;
|
||||||
|
|
||||||
class LookupServer final : public Core::Object {
|
class LookupServer final : public Core::Object {
|
||||||
C_OBJECT(LookupServer);
|
C_OBJECT(LookupServer);
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MulticastDNS.h"
|
#include "MulticastDNS.h"
|
||||||
#include "DNSPacket.h"
|
|
||||||
#include <AK/IPv4Address.h>
|
#include <AK/IPv4Address.h>
|
||||||
#include <AK/JsonArray.h>
|
#include <AK/JsonArray.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
|
|
|
@ -6,15 +6,17 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "DNSAnswer.h"
|
|
||||||
#include "DNSName.h"
|
|
||||||
#include "DNSPacket.h"
|
|
||||||
#include <AK/IPv4Address.h>
|
#include <AK/IPv4Address.h>
|
||||||
#include <LibCore/UDPServer.h>
|
#include <LibCore/UDPServer.h>
|
||||||
|
#include <LibDNS/DNSAnswer.h>
|
||||||
|
#include <LibDNS/DNSName.h>
|
||||||
|
#include <LibDNS/DNSPacket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
namespace LookupServer {
|
namespace LookupServer {
|
||||||
|
|
||||||
|
using namespace DNS;
|
||||||
|
|
||||||
class MulticastDNS : public Core::UDPServer {
|
class MulticastDNS : public Core::UDPServer {
|
||||||
C_OBJECT(MulticastDNS)
|
C_OBJECT(MulticastDNS)
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue