DCHK Client Version 0.5.7 - Documentation |
![]() |
The last example uses the C++ API and uses a domain list to query several domains in one step.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include <dchk.h> int main(int argc, char **argv) { int ret; #ifdef _WIN32 irislwz_InitWSA(); #endif // Instantiate CDchk-Class dchk::CDchk dchk; // Assume all parameters are domain names. Create a CDomainList instance dchk::CDomainList list; if (argc<2) { printf("Enter some domains."); return 1; } // Add the domain names for (int i=1;i<=argc;i++) list.AddDomain(argv[i]); // Use TLD of first domain to find DCHK server automatically const char *tld=strrchr(argv[1],'.'); // Find last occurrance of '.' if (tld) tld++; // Point to first char after '.' else { printf ("No tld found!\n"); return 2; } // Use compression dchk.SendDeflated(true); dchk.AcceptDeflated(true); // Set hostname automatically by using DNS if (!dchk.SetHostByDNS(tld)) { dchk.PrintError(); return dchk.GetErrorCode(); } // Check if connection is possible if (!dchk.Connect()) { dchk.PrintError(); return dchk.GetErrorCode(); } // bundle 20 domains to one query dchk.SetMaxDomainsPerQuery(20); if (!dchk.QueryDomainList(&list)) { dchk.PrintError(); return dchk.GetErrorCode(); } // Print answer dchk.PrintResults(&list); return 0; } // end
Compilation:
g++ -o example5 example5.cpp -I/usr/local/include -lstdc++ \ -ldnsapi -L/usr/local/lib -ldchk -lxml2 -L/usr/local/lib -lz -lws2_32 -ldnsapi