DCHK Client Version 0.5.7 - Documentation DomainCheck

Example 3: Using DNS to find a DCHK server
[API Usage]

The third example again does the same thing, but uses DNS to find a suitable DCHK server and has a bit less code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <dchk.h>


int main(int argc, char **argv)
{
    int ret;
    // Define IRISLWZ_HANDLE
    IRISLWZ_HANDLE iris;
    // Assume first Parameter is the domain which should be checked
    const char *domain=argv[1];

    // find TLD in host name
    const char *tld=strrchr(domain,'.');        // Find last occurrance of '.'
    if (tld) tld++;                             // Point to first char after '.'
    else {
        printf ("No tld found!\n");
        return 1;
    }

    // Initialize IRISLWZ_HANDLE
    irislwz_Init(&iris);

    // Use compression
    irislwz_SendDeflated(&iris,1);
    irislwz_AcceptDeflated(&iris,1);

    // Set hostname automatically by using DNS
    dchk_SetHostByDNS(&iris,tld);

    // Check if connection is possible
    if (!irislwz_Connect(&iris)) {
        ret=irislwz_GetErrorCode(&iris);
        irislwz_PrintError(&iris);
        irislwz_Exit(&iris);
        return ret;
    }
    if (!dchk_QueryDomain(&iris,domain,NULL,NULL)) {
        ret=irislwz_GetErrorCode(&iris);
        irislwz_PrintError(&iris);
        irislwz_Exit(&iris);
        return ret;
    }
    // Print answer
    printf("%s\n",iris.response.beautified);
    irislwz_Exit(&iris);
    return 0;
}

// end
We don't set the Timeout manually, as the default is already 5 seconds. We use the authority default, too. Compilation:

gcc -I/usr/local/include -L/usr/local/lib example3.c -o example3 -ldchk -lxml2 -lresolv

Please note that we need the resolver library now.

Generated on Wed Aug 4 21:23:46 2010 for DCHK Client Documentation by  doxygen 1.6.3