|
@@ -1,8 +1,9 @@
|
1
|
1
|
#include <iostream>
|
2
|
2
|
#include <QCoreApplication>
|
|
3
|
+#include "dns-client/QDnsUdpClient.h"
|
|
4
|
+#include "dns-client/QDnsTcpClient.h"
|
3
|
5
|
#include "dns-server/QDnsUdpServer.h"
|
4
|
6
|
#include "dns-server/QDnsTcpServer.h"
|
5
|
|
-#include "dns-base/QDnsBase.h"
|
6
|
7
|
|
7
|
8
|
int main(int argc, char* argv[])
|
8
|
9
|
{
|
|
@@ -13,7 +14,7 @@ int main(int argc, char* argv[])
|
13
|
14
|
|
14
|
15
|
auto onRequest = [](QDns::Server::QDnsUdpServer::OnRequestParams params)
|
15
|
16
|
{
|
16
|
|
- QDns::Base::QDnsPacket answer = params.packet.makeAnswer();
|
|
17
|
+ QDns::Base::QDnsPacket answer = params.query.makeAnswer();
|
17
|
18
|
auto header = answer.getHeader();
|
18
|
19
|
header.setReplyCode(QDns::Base::HeaderReplyCode::Refused);
|
19
|
20
|
answer.setHeader(header);
|
|
@@ -32,5 +33,57 @@ int main(int argc, char* argv[])
|
32
|
33
|
udpServer.start(bindAddress, bindPort);
|
33
|
34
|
QObject::connect(&udpServer, &QDns::Server::QDnsServer::onRequest, onRequest);
|
34
|
35
|
|
|
36
|
+
|
|
37
|
+// QDns::Client::QDnsUdpClient client(QHostAddress("127.0.0.1"));
|
|
38
|
+// QDns::Client::QDnsUdpClient client(QHostAddress("8.8.8.8"));
|
|
39
|
+ QDns::Client::QDnsTcpClient client(QHostAddress("127.0.0.1"), 5053);
|
|
40
|
+// QDns::Client::QDnsTcpClient client(QHostAddress("8.8.8.8"));
|
|
41
|
+
|
|
42
|
+ QList<QString> labels;
|
|
43
|
+ labels << "www.google.fr" << "www.google.com" << "www.rthoni.com";
|
|
44
|
+
|
|
45
|
+ QObject::connect(&client, &QDns::Client::QDnsClient::onAnswer, [&client, &labels](QDns::Client::QDnsClient::OnAnswerParams params)
|
|
46
|
+ {
|
|
47
|
+ labels.removeOne(params.query.getQueries().at(0).getName());
|
|
48
|
+ for (const auto& answer : params.answer.getAnswerRecords())
|
|
49
|
+ {
|
|
50
|
+ qDebug() << "Answer:" << answer.getName();
|
|
51
|
+ }
|
|
52
|
+ qDebug() << "Answer:" << params.answer.getAnswerRecords().size();
|
|
53
|
+ if (labels.empty())
|
|
54
|
+ {
|
|
55
|
+ client.disconnectFromHost();
|
|
56
|
+ }
|
|
57
|
+ });
|
|
58
|
+
|
|
59
|
+ QObject::connect(&client, &QDns::Client::QDnsClient::onError, [&client, &labels](QDns::Client::QDnsClient::OnErrorParams params)
|
|
60
|
+ {
|
|
61
|
+ if (params.query.isValid())
|
|
62
|
+ {
|
|
63
|
+ labels.removeOne(params.query.getQueries().at(0).getName());
|
|
64
|
+ }
|
|
65
|
+ qDebug() << "Error:" << params.error;
|
|
66
|
+ if (labels.empty())
|
|
67
|
+ {
|
|
68
|
+ client.disconnectFromHost();
|
|
69
|
+ }
|
|
70
|
+ });
|
|
71
|
+
|
|
72
|
+ QObject::connect(&client, &QDns::Client::QDnsClient::onStateChanged, [&client, &labels](QDns::Client::QDnsClient::OnStateChangedParams params)
|
|
73
|
+ {
|
|
74
|
+ qDebug() << "State:" << params.state;
|
|
75
|
+ if (params.state == QDns::Client::QDnsClient::ClientState::Connected)
|
|
76
|
+ {
|
|
77
|
+ for (const auto& label : labels)
|
|
78
|
+ {
|
|
79
|
+ client.query(QDns::Base::QDnsPacket::makeSimpleQuery(label, QDns::Base::RecordType::A));
|
|
80
|
+ }
|
|
81
|
+ }
|
|
82
|
+ });
|
|
83
|
+
|
|
84
|
+ client.connectToHost();
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
35
|
88
|
return app.exec();
|
36
|
89
|
}
|