Vantages Logo libvdns, the Vantages DNS C++ API Internet Research Lab Logo Colorado State Logo

Home | Applications | libvdns | Download | Known Issues | Documentation | Bug Tracker & Feature Requests | People


The libvdns is a C++ library that Vantages uses to do its queries. This library is a general purpose DNS library whose API is intended to be generally usable for development.

The API is still under development, and has been used, primarily, for querying infrastructure records. Thus, while the library can send and receive queries for arbitrary DNS types, the list of classes that actually represent RR types is still being developed. For example, one can query for and receive MX records with libvdns. However, the data returned is kept as an abstract rdata BLOB in the base class DnsRR. By contrast, querying for a DNSKEY will result in an instance of the class DnsDnskey. Over time, we will be developing more support for all DNS RR types.

The major components of this API can be broken into the RR types, the message components, the resolver, and the DNSSEC verification classes. Note: these are just informal distinctions. All classes exists in the library, and the only reason for discussing them as different components is to explain their relationships at an abstract level.

Currently, headers are installed in the $(prefix)/include/vantages/ directory. In addition, the default installation process for Vantages installs both libvdns, and the vantaged daemon. In order to install just libvdns, use the following:

      $ ./configure --with-vantaged=no
      $ make
      $ sudo make install
    

libvdns classes

Core classes

  • DnsCompression: This class manages the DNS name compression of a message and its components.
  • DnsError: This class is a singleton that is used like errno, so classes that have failures can record the reason and other code can learn it.
  • DnsName: This class manages the semantics of DNS names (such as case insensitivity, appending the root, etc.).
  • DnsRrFactory: This class is a singleton that manages the RR type classes so that when an RR is received, the most specific class can be used to parse the rdata.

RR type classes

  • DnsRR: This is a base class for RR types. When an RR is received over the wire, and no more specific class exists to parse it, this class is invoked. In addition, this class contains the base logic used by derived classes to parse RRs in general.
  • DnsA: This class represents a DNS A record.
  • DnsDnskey: This class represents a DNS DNSKEY record.
  • DnsDs: This class represents a DNS DS record.
  • DnsNs: This class represents a DNS NS record.
  • DnsOpt: This class represents a DNS OPT pseudo-record.
  • DnsRrsig: This class represents a DNS RRSIG record.

Message classes

  • DnsHeader: This classes represents the DNS message header and all of the bits and flags.
  • DnsPacket: This class represents an entire DNS message (including access to all sections).

Resolver classes

  • DnsResolver: This class acts as a generic stub-resolver. Synchronous queries can be made via a simple send() method in which the user specifies the domain name, and optionally specifies the type and class. This class also supports concurrent (asynchronous) queries via an overloaded send() method that takes a DnsTask object, and can be polled via its recv() method for a response. It currently does not support TCP
  • DnsTask: This class is used as a base class to derive from if concurrent queries are used. A resolver will accept tasks via its send() method, and can be polled via its recv() method.

Verification class

  • DnsVerifier: This class is used to perform DNSSEC verification. It has a very simple interface in which two RRList_t objects (an RRset to verifiy and a list of DNSKEYs to verify with) are passed in and a boolean is returned to indicate if verification was successful. In addition, there is a method to verify DS records as well.

Example Code

#include <stdio.h>
#include <string>

#include <vantages/dns_defs.h>
#include <vantages/dns_resolver.h>
#include <vantages/dns_packet.h>
#include <vantages/dns_a.h>
#include <vantages/dns_err.h>

int main(int argc, char *argv[])
{
  DnsResolver oRes;
  DnsPacket oResp;
  std::string sA = "secspider.cs.ucla.edu";

  if (!oRes.send(sA, oResp))
  {
    fprintf(stderr, "Unable to query: '%s'\n", DnsError::getInstance().getError().c_str());
  }
  else
  {
    RRList_t oAns;
    oResp.getAnswers(oAns);
    for (RRIter_t tIter = oAns.begin();
         oAns.end() != tIter;
         tIter++)
    {
      if (DNS_RR_A == (*tIter)->type())
      {
        uint32_t uIP = ((DnsA *) (*tIter))->ip();
        fprintf(stdout, "Got IP: %d.%d.%d.%d\n", (uIP>>24)&0x00ff, (uIP>>16)&0x00ff, (uIP>>8)&0x00ff,uIP&0x00ff);
      }
    }
  }

  return 0;
}

  



(Contact us at tools@netsec.colostate.edu)