This project implements a small part of DNS protocol (rfc1035) in C++ and Qt framework.
Thus, it can send a DNS request, receive a DNS response, and get a IP.
Each query is cached to save requests.
And in order to simplify the parsing work, I have additionally wrote Buffer::unpack and Buffer::pack method. The usage is listed below, and you can just individually use this class.
NOTE: In fact, Qt itself has a QDnsLookup class to accomplish this work.
// main.cpp
#include <QCoreApplication>
#include "buffer.h"
#include "asyncdns.h"
#include <QObject>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QHostAddress google_dns("8.8.8.8");
AsyncDNS resolver(google_dns);
resolver.sendDNSRequest("www.zhihu.com");
return a.exec();
}
- DNS cache
(just dig a hole, updating...)