SOL9 Sample: DnsTextRecordQuery

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * DnsTextRecordQuery.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2011/1/1
// 2011/1/14 Updated
// 2011/1/20 Modified to use DnsRecordQueryT class

#include <sol/WSAInitializer.h>
#include <sol/dns/DnsRecordQueryT.h>
#include <sol/Locale.h>

namespace SOL {

class DnsTextRecordQuery :public Object {
private:
  DnsRecordQueryT<DNS_TXT_DATA> dns;

public:
  /**
   * Constructor
   */
  DnsTextRecordQuery()
    :dns(DNS_TYPE_TEXT)
  {
  }

public:
  ~DnsTextRecordQuery()
  {
  }

public:
  void start(const TCHAR* hostDomain)
  {
    int count = dns.query(hostDomain);

    _tprintf(_T("All DNS_TXT_DATA(count=%d)\n"), count);        
    dns.display();
    
    //Get the first DNS_TXT_DATA
    DNS_TXT_DATA data;
    dns.getFirst(data);

    //Display a structure data of DNS_TXT_DATA 
    _tprintf(_T("\nFirst DNS_TXT_DATA\n"));
    DnsData dnsData;
    dnsData.display(data);

    //Display an object of DnsRecordT<DNS_TXT_DATA> 
    DnsRecordT<DNS_TXT_DATA> record;
    dns.getNth(0, record);
    _tprintf(_T("\nFirst DnsRecordT<DNS_TXT_DAT>\n"));
    record.display();
  }
};

}



void _tmain(int argc, TCHAR** argv)
{
  if (argc !=2) {
    _tprintf(_T("Usage:%s hostDomain\n"), argv[0]);
    _tprintf(_T("Ex: %s google.com\n"), argv[0]);
    return;
  }
  WSAInitializer initializer;
  Locale locale;
  try {
    DnsTextRecordQuery 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.