SOL9 Sample: DnsPtrRecordQuery
|
1 Screenshot
2 Source code
/*
* DnsPtrRecordQuery.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2011/1/2
// 2011/1/14 Updated
// 2011/1/18 Modified to use DnsRecordQueryT class
#include <sol/WSAInitializer.h>
#include <sol/dns/DnsRecordQueryT.h>
#include <sol/Locale.h>
namespace SOL {
class DnsPtrRecordQuery :public Object {
private:
DnsRecordQueryT<DNS_PTR_DATA> dns;
private:
TCHAR reversedIP[20];
public:
/**
* Constructor
*/
DnsPtrRecordQuery()
:dns(DNS_TYPE_PTR)
{
}
public:
void start(const TCHAR* ip)
{
reverseIP(ip, reversedIP);
int count = dns.query(reversedIP);
//Display the query result(all DNS_PTR_DATA).
_tprintf(_T("All DNS_PTR_DATA(count=%d)\n"), count);
dns.display();
//Get the first DNS_PTR_DAT
DNS_PTR_DATA data;
dns.getFirst(data);
//Display a structure data of DNS_PTR_DATA
_tprintf(_T("\nFirst DNS_PTR_DATA\n"));
DnsData dnsData;
dnsData.display(data);
}
private:
void reverseIP(__in const TCHAR* ip, __out TCHAR* reversedIP)
{
TCHAR* sep = _T(".");
TCHAR array[4][4];
TCHAR* ctx;//
int i = 0;
TCHAR* token = strtok_s((TCHAR*)ip, sep, &ctx);
while (token != NULL) {
_stprintf_s(array[i], 4, _T("%s"), token);
token = strtok_s((TCHAR*)NULL, sep, &ctx);
i++;
}
_stprintf_s(reversedIP, SizeOf(reversedIP), _T("%s.%s.%s.%s.%s"), array[3], array[2], array[1], array[0],
_T("IN-ADDR.ARPA"));
}
};
}
void _tmain(int argc, TCHAR** argv)
{
if (argc !=2) {
_tprintf(_T("Usage:%s ipaddress\n"), argv[0]);
_tprintf(_T("Ex: %s 216.239.38.10\n"), argv[0]);
return;
}
WSAInitializer initializer;
Locale locale;
try {
DnsPtrRecordQuery recordQuery;
recordQuery.start(argv[1]);
} catch (Exception& ex) {
ex.printf();
} catch (...) {
_tprintf(_T("Exception\n"));
}
}
Last modified: 2 May 2016
Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.