ares_inet_ntop.3: s/socklen_t/ares_socklen_t
[platform/upstream/c-ares.git] / ahost.c
diff --git a/ahost.c b/ahost.c
index dfb51a9..fd6e50d 100644 (file)
--- a/ahost.c
+++ b/ahost.c
@@ -1,6 +1,5 @@
 /* Copyright 1998 by the Massachusetts Institute of Technology.
  *
- * $Id$
  *
  * Permission to use, copy, modify, and distribute this
  * software and its documentation for any purpose and without
  * without express or implied warranty.
  */
 
-#include "setup.h"
+#include "ares_setup.h"
 
 #if !defined(WIN32) || defined(WATT32)
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
 
 #include "ares.h"
 #include "ares_dns.h"
-#include "inet_ntop.h"
-#include "inet_net_pton.h"
 #include "ares_getopt.h"
+#include "ares_ipv6.h"
+#include "ares_nowarn.h"
 
-#ifndef optind
-extern int   optind;
-extern char *optarg;
+#ifndef HAVE_STRDUP
+#  include "ares_strdup.h"
+#  define strdup(ptr) ares_strdup(ptr)
 #endif
 
-#ifndef HAVE_STRUCT_IN6_ADDR
-struct in6_addr
-{
-  unsigned char s6_addr[16];
-};
+#ifndef HAVE_STRCASECMP
+#  include "ares_strcasecmp.h"
+#  define strcasecmp(p1,p2) ares_strcasecmp(p1,p2)
 #endif
 
-static void callback(void *arg, int status, struct hostent *host);
+#ifndef HAVE_STRNCASECMP
+#  include "ares_strcasecmp.h"
+#  define strncasecmp(p1,p2,n) ares_strncasecmp(p1,p2,n)
+#endif
+
+static void callback(void *arg, int status, int timeouts, struct hostent *host);
 static void usage(void);
 
 int main(int argc, char **argv)
@@ -62,7 +57,7 @@ int main(int argc, char **argv)
   fd_set read_fds, write_fds;
   struct timeval *tvp, tv;
   struct in_addr addr4;
-  struct in6_addr addr6;
+  struct ares_in6_addr addr6;
 
 #ifdef USE_WINSOCK
   WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
@@ -70,6 +65,13 @@ int main(int argc, char **argv)
   WSAStartup(wVersionRequested, &wsaData);
 #endif
 
+  status = ares_library_init(ARES_LIB_INIT_ALL);
+  if (status != ARES_SUCCESS)
+    {
+      fprintf(stderr, "ares_library_init: %s\n", ares_strerror(status));
+      return 1;
+    }
+
   while ((c = ares_getopt(argc,argv,"dt:h")) != -1)
     {
       switch (c)
@@ -126,7 +128,7 @@ int main(int argc, char **argv)
     }
 
   /* Wait for all queries to complete. */
-  while (1)
+  for (;;)
     {
       FD_ZERO(&read_fds);
       FD_ZERO(&write_fds);
@@ -140,6 +142,8 @@ int main(int argc, char **argv)
 
   ares_destroy(channel);
 
+  ares_library_cleanup();
+
 #ifdef USE_WINSOCK
   WSACleanup();
 #endif
@@ -147,10 +151,12 @@ int main(int argc, char **argv)
   return 0;
 }
 
-static void callback(void *arg, int status, struct hostent *host)
+static void callback(void *arg, int status, int timeouts, struct hostent *host)
 {
   char **p;
 
+  (void)timeouts;
+
   if (status != ARES_SUCCESS)
     {
       fprintf(stderr, "%s: %s\n", (char *) arg, ares_strerror(status));