DCHK Client Version 0.5.7 - Documentation |
![]() |
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
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.