-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdnsresolver.h
executable file
·86 lines (63 loc) · 2.06 KB
/
mdnsresolver.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* QtNetworkCrumbs - Some networking toys for Qt
* Copyright (C) 2019-2024 Mathias Hasselmann
*/
#ifndef QNCMDNS_MDNSRESOLVER_H
#define QNCMDNS_MDNSRESOLVER_H
#include "multicastresolver.h"
class QHostAddress;
class QNetworkDatagram;
class QUdpSocket;
namespace qnc::mdns {
class Message;
class ServiceRecord;
class ServiceDescription
{
Q_GADGET
public:
ServiceDescription() = default;
ServiceDescription(QString domain, QByteArray name, ServiceRecord service, QStringList info);
auto name() const { return m_name; };
auto type() const { return m_type; }
auto target() const { return m_target; }
auto priority() const { return m_priority; }
auto weight() const { return m_weight; }
auto port() const { return m_port; }
auto info() const { return m_info; }
QString info(const QString &key) const;
QList<QUrl> locations() const;
private:
QString m_name;
QString m_type;
QString m_target;
int m_port;
int m_priority;
int m_weight;
QStringList m_info;
};
class Resolver : public core::MulticastResolver
{
Q_OBJECT
Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged FINAL)
public:
explicit Resolver(QObject *parent = {});
QString domain() const;
public slots:
void setDomain(QString domain);
bool lookupHostNames(QStringList hostNames);
bool lookupServices(QStringList serviceTypes);
bool lookup(qnc::mdns::Message query);
signals:
void domainChanged(QString domain);
void hostNameFound(QString hostname, QList<QHostAddress> addresses);
void serviceFound(qnc::mdns::ServiceDescription service);
void messageReceived(qnc::mdns::Message message);
protected:
[[nodiscard]] virtual quint16 port() const override;
[[nodiscard]] QHostAddress multicastGroup(const QHostAddress &address) const override;
void processDatagram(const QNetworkDatagram &datagram) override;
private:
QString m_domain;
};
} // namespace qnc::mdns
QDebug operator<<(QDebug debug, const qnc::mdns::ServiceDescription &service);
#endif // QNCMDNS_MDNSRESOLVER_H