mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:47:44 +00:00
LookupServer: Implement basic mDNS support :^)
The implementation is extremely basic, and is far from fully conforming to the spec. Among other things, it does not really work in case there are multiple network adapters. Nevertheless, it works quite well for the simple case! You can now do this on your host machine: $ ping courage.local and same on your Serenity box: $ ping host-machine-name.local
This commit is contained in:
parent
fd76e07399
commit
bb06e720de
6 changed files with 251 additions and 1 deletions
46
Userland/Services/LookupServer/MulticastDNS.h
Normal file
46
Userland/Services/LookupServer/MulticastDNS.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DNSAnswer.h"
|
||||
#include "DNSName.h"
|
||||
#include "DNSPacket.h"
|
||||
#include <AK/IPv4Address.h>
|
||||
#include <LibCore/UDPServer.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
namespace LookupServer {
|
||||
|
||||
class MulticastDNS : public Core::UDPServer {
|
||||
C_OBJECT(MulticastDNS)
|
||||
public:
|
||||
Vector<DNSAnswer> lookup(const DNSName&, unsigned short record_type);
|
||||
|
||||
private:
|
||||
explicit MulticastDNS(Object* parent = nullptr);
|
||||
|
||||
void announce();
|
||||
ssize_t emit_packet(const DNSPacket&, const sockaddr_in* destination = nullptr);
|
||||
|
||||
void handle_packet();
|
||||
void handle_query(const DNSPacket&);
|
||||
|
||||
Vector<IPv4Address> local_addresses() const;
|
||||
|
||||
DNSName m_hostname;
|
||||
|
||||
static constexpr sockaddr_in mdns_addr {
|
||||
AF_INET,
|
||||
// htons(5353)
|
||||
0xe914,
|
||||
// 224.0.0.251
|
||||
{ 0xfb0000e0 },
|
||||
0
|
||||
};
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue