summaryrefslogtreecommitdiff
path: root/Userland/Services/LookupServer/MulticastDNS.h
blob: 5fa6343c3d030566d812b8b7409fa1a58c7ffb68 (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
/*
 * 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&, DNSRecordType 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 }
    };
};

}