blob: ff3ecfd2f3433d956b338380fa5596d15e8223a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/*
* Copyright (c) 2021, Sergey Bugaev <bugaevc@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/IPv4Address.h>
#include <LibCore/UDPServer.h>
#include <LibDNS/Answer.h>
#include <LibDNS/Name.h>
#include <LibDNS/Packet.h>
#include <netinet/in.h>
namespace LookupServer {
using namespace DNS;
class MulticastDNS : public Core::UDPServer {
C_OBJECT(MulticastDNS)
public:
Vector<Answer> lookup(Name const&, RecordType record_type);
private:
explicit MulticastDNS(Object* parent = nullptr);
void announce();
ErrorOr<size_t> emit_packet(Packet const&, sockaddr_in const* destination = nullptr);
void handle_packet();
void handle_query(Packet const&);
Vector<IPv4Address> local_addresses() const;
Name m_hostname;
static constexpr sockaddr_in mdns_addr {
#ifdef AK_OS_BSD_GENERIC
.sin_len = sizeof(struct sockaddr_in),
#endif
.sin_family = AF_INET,
// htons(5353)
.sin_port = 0xe914,
// 224.0.0.251
.sin_addr = { 0xfb0000e0 },
.sin_zero = { 0 }
};
};
}
|