1 #include <stdio.h> 2 #include <string.h> 3 #include <netinet/in.h> 4 #include <arpa/nameser.h> 5 #include <resolv.h> 6 #include <pthread.h> 7 8 void* fn(void* arg) 9 { 10 char* dn = (char*)arg; 11 12 unsigned char buff[8000]; 13 14 if(-1 == res_search(dn, 1, 1, buff, 8000)) 15 { 16 printf("Error: res_search()\n"); 17 } 18 else 19 { 20 printf("Success!\n"); 21 } 22 return 0; 23 } 24 25 int main(int argc, char** argv) 26 { 27 pthread_t pid; 28 if(2 != argc) 29 { 30 printf("Usage: %s <domain>\n", argv[0]); 31 return 1; 32 } 33 34 _res.options |= RES_DEBUG; 35 if(0 != res_init()) 36 { 37 printf("Error: res_init()\n"); 38 return(1); 39 } 40 #if 1 41 /* Test it in a different thread -- the failure case */ 42 if(0 != pthread_create(&pid, 0, fn, (void*)argv[1])) 43 { 44 printf("Failed to create thread.\n"); 45 return 1; 46 } 47 48 pthread_join(pid, 0); 49 #else 50 { 51 unsigned char buff[8000]; 52 53 if(-1 == res_search(argv[1], 1, 1, buff, 8000)) 54 { 55 printf("Error: res_search()\n"); 56 } 57 else 58 { 59 printf("Success!\n"); 60 } 61 } 62 #endif 63 return 0; 64 } 65 66 67