removed tabs and trailing whitespace from source
authorDaniel Stenberg <daniel@haxx.se>
Wed, 6 Oct 2004 07:50:18 +0000 (07:50 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 6 Oct 2004 07:50:18 +0000 (07:50 +0000)
20 files changed:
adig.c
ahost.c
ares.h
ares__get_hostent.c
ares__read_line.c
ares_dns.h
ares_expand_name.c
ares_fds.c
ares_gethostbyaddr.c
ares_gethostbyname.c
ares_init.c
ares_mkquery.c
ares_parse_a_reply.c
ares_parse_ptr_reply.c
ares_private.h
ares_process.c
ares_query.c
ares_search.c
ares_send.c
ares_timeout.c

diff --git a/adig.c b/adig.c
index a14288f..27b2500 100644 (file)
--- a/adig.c
+++ b/adig.c
@@ -37,7 +37,7 @@
 #include "ares_dns.h"
 
 #ifndef INADDR_NONE
-#define        INADDR_NONE 0xffffffff
+#define INADDR_NONE 0xffffffff
 #endif
 
 /* Mac OS X portability check */
@@ -54,58 +54,58 @@ struct nv {
 };
 
 static const struct nv flags[] = {
-  { "usevc",           ARES_FLAG_USEVC },
-  { "primary",         ARES_FLAG_PRIMARY },
-  { "igntc",           ARES_FLAG_IGNTC },
-  { "norecurse",       ARES_FLAG_NORECURSE },
-  { "stayopen",                ARES_FLAG_STAYOPEN },
-  { "noaliases",       ARES_FLAG_NOALIASES }
+  { "usevc",            ARES_FLAG_USEVC },
+  { "primary",          ARES_FLAG_PRIMARY },
+  { "igntc",            ARES_FLAG_IGNTC },
+  { "norecurse",        ARES_FLAG_NORECURSE },
+  { "stayopen",         ARES_FLAG_STAYOPEN },
+  { "noaliases",        ARES_FLAG_NOALIASES }
 };
 static const int nflags = sizeof(flags) / sizeof(flags[0]);
 
 static const struct nv classes[] = {
-  { "IN",      C_IN },
-  { "CHAOS",   C_CHAOS },
-  { "HS",      C_HS },
-  { "ANY",     C_ANY }
+  { "IN",       C_IN },
+  { "CHAOS",    C_CHAOS },
+  { "HS",       C_HS },
+  { "ANY",      C_ANY }
 };
 static const int nclasses = sizeof(classes) / sizeof(classes[0]);
 
 static const struct nv types[] = {
-  { "A",       T_A },
-  { "NS",      T_NS },
-  { "MD",      T_MD },
-  { "MF",      T_MF },
-  { "CNAME",   T_CNAME },
-  { "SOA",     T_SOA },
-  { "MB",      T_MB },
-  { "MG",      T_MG },
-  { "MR",      T_MR },
-  { "NULL",    T_NULL },
-  { "WKS",     T_WKS },
-  { "PTR",     T_PTR },
-  { "HINFO",   T_HINFO },
-  { "MINFO",   T_MINFO },
-  { "MX",      T_MX },
-  { "TXT",     T_TXT },
-  { "RP",      T_RP },
-  { "AFSDB",   T_AFSDB },
-  { "X25",     T_X25 },
-  { "ISDN",    T_ISDN },
-  { "RT",      T_RT },
-  { "NSAP",    T_NSAP },
-  { "NSAP_PTR",        T_NSAP_PTR },
-  { "SIG",     T_SIG },
-  { "KEY",     T_KEY },
-  { "PX",      T_PX },
-  { "GPOS",    T_GPOS },
-  { "AAAA",    T_AAAA },
-  { "LOC",     T_LOC },
-  { "SRV",     T_SRV },
-  { "AXFR",    T_AXFR },
-  { "MAILB",   T_MAILB },
-  { "MAILA",   T_MAILA },
-  { "ANY",     T_ANY }
+  { "A",        T_A },
+  { "NS",       T_NS },
+  { "MD",       T_MD },
+  { "MF",       T_MF },
+  { "CNAME",    T_CNAME },
+  { "SOA",      T_SOA },
+  { "MB",       T_MB },
+  { "MG",       T_MG },
+  { "MR",       T_MR },
+  { "NULL",     T_NULL },
+  { "WKS",      T_WKS },
+  { "PTR",      T_PTR },
+  { "HINFO",    T_HINFO },
+  { "MINFO",    T_MINFO },
+  { "MX",       T_MX },
+  { "TXT",      T_TXT },
+  { "RP",       T_RP },
+  { "AFSDB",    T_AFSDB },
+  { "X25",      T_X25 },
+  { "ISDN",     T_ISDN },
+  { "RT",       T_RT },
+  { "NSAP",     T_NSAP },
+  { "NSAP_PTR", T_NSAP_PTR },
+  { "SIG",      T_SIG },
+  { "KEY",      T_KEY },
+  { "PX",       T_PX },
+  { "GPOS",     T_GPOS },
+  { "AAAA",     T_AAAA },
+  { "LOC",      T_LOC },
+  { "SRV",      T_SRV },
+  { "AXFR",     T_AXFR },
+  { "MAILB",    T_MAILB },
+  { "MAILA",    T_MAILA },
+  { "ANY",      T_ANY }
 };
 static const int ntypes = sizeof(types) / sizeof(types[0]);
 
@@ -124,10 +124,10 @@ static const char *rcodes[] = {
 
 static void callback(void *arg, int status, unsigned char *abuf, int alen);
 static const unsigned char *display_question(const unsigned char *aptr,
-                                            const unsigned char *abuf,
-                                            int alen);
+                                             const unsigned char *abuf,
+                                             int alen);
 static const unsigned char *display_rr(const unsigned char *aptr,
-                                      const unsigned char *abuf, int alen);
+                                       const unsigned char *abuf, int alen);
 static const char *type_name(int type);
 static const char *class_name(int dnsclass);
 static void usage(void);
@@ -146,7 +146,7 @@ int main(int argc, char **argv)
   WORD wVersionRequested = MAKEWORD(1,1);
   WSADATA wsaData;
   WSAStartup(wVersionRequested, &wsaData);
-#endif  
+#endif
 
   options.flags = ARES_FLAG_NOCHECKRESP;
   options.servers = NULL;
@@ -154,80 +154,80 @@ int main(int argc, char **argv)
   while ((c = getopt(argc, argv, "f:s:c:t:T:U:")) != -1)
     {
       switch (c)
-       {
-       case 'f':
-         /* Add a flag. */
-         for (i = 0; i < nflags; i++)
-           {
-             if (strcmp(flags[i].name, optarg) == 0)
-               break;
-           }
-         if (i == nflags)
-           usage();
-         options.flags |= flags[i].value;
-         break;
-
-       case 's':
-         /* Add a server, and specify servers in the option mask. */
-         hostent = gethostbyname(optarg);
-         if (!hostent || hostent->h_addrtype != AF_INET)
-           {
-             fprintf(stderr, "adig: server %s not found.\n", optarg);
-             return 1;
-           }
-         options.servers = realloc(options.servers, (options.nservers + 1)
-                                   * sizeof(struct in_addr));
-         if (!options.servers)
-           {
-             fprintf(stderr, "Out of memory!\n");
-             return 1;
-           }
-         memcpy(&options.servers[options.nservers], hostent->h_addr,
-                sizeof(struct in_addr));
-         options.nservers++;
-         optmask |= ARES_OPT_SERVERS;
-         break;
-
-       case 'c':
-         /* Set the query class. */
-         for (i = 0; i < nclasses; i++)
-           {
-             if (strcasecmp(classes[i].name, optarg) == 0)
-               break;
-           }
-         if (i == nclasses)
-           usage();
-         dnsclass = classes[i].value;
-         break;
-
-       case 't':
-         /* Set the query type. */
-         for (i = 0; i < ntypes; i++)
-           {
-             if (strcasecmp(types[i].name, optarg) == 0)
-               break;
-           }
-         if (i == ntypes)
-           usage();
-         type = types[i].value;
-         break;
-
-       case 'T':
-         /* Set the TCP port number. */
-         if (!isdigit((unsigned char)*optarg))
-           usage();
-         options.tcp_port = strtol(optarg, NULL, 0);
-         optmask |= ARES_OPT_TCP_PORT;
-         break;
-
-       case 'U':
-         /* Set the UDP port number. */
-         if (!isdigit((unsigned char)*optarg))
-           usage();
-         options.udp_port = strtol(optarg, NULL, 0);
-         optmask |= ARES_OPT_UDP_PORT;
-         break;
-       }
+        {
+        case 'f':
+          /* Add a flag. */
+          for (i = 0; i < nflags; i++)
+            {
+              if (strcmp(flags[i].name, optarg) == 0)
+                break;
+            }
+          if (i == nflags)
+            usage();
+          options.flags |= flags[i].value;
+          break;
+
+        case 's':
+          /* Add a server, and specify servers in the option mask. */
+          hostent = gethostbyname(optarg);
+          if (!hostent || hostent->h_addrtype != AF_INET)
+            {
+              fprintf(stderr, "adig: server %s not found.\n", optarg);
+              return 1;
+            }
+          options.servers = realloc(options.servers, (options.nservers + 1)
+                                    * sizeof(struct in_addr));
+          if (!options.servers)
+            {
+              fprintf(stderr, "Out of memory!\n");
+              return 1;
+            }
+          memcpy(&options.servers[options.nservers], hostent->h_addr,
+                 sizeof(struct in_addr));
+          options.nservers++;
+          optmask |= ARES_OPT_SERVERS;
+          break;
+
+        case 'c':
+          /* Set the query class. */
+          for (i = 0; i < nclasses; i++)
+            {
+              if (strcasecmp(classes[i].name, optarg) == 0)
+                break;
+            }
+          if (i == nclasses)
+            usage();
+          dnsclass = classes[i].value;
+          break;
+
+        case 't':
+          /* Set the query type. */
+          for (i = 0; i < ntypes; i++)
+            {
+              if (strcasecmp(types[i].name, optarg) == 0)
+                break;
+            }
+          if (i == ntypes)
+            usage();
+          type = types[i].value;
+          break;
+
+        case 'T':
+          /* Set the TCP port number. */
+          if (!isdigit((unsigned char)*optarg))
+            usage();
+          options.tcp_port = strtol(optarg, NULL, 0);
+          optmask |= ARES_OPT_TCP_PORT;
+          break;
+
+        case 'U':
+          /* Set the UDP port number. */
+          if (!isdigit((unsigned char)*optarg))
+            usage();
+          options.udp_port = strtol(optarg, NULL, 0);
+          optmask |= ARES_OPT_UDP_PORT;
+          break;
+        }
     }
   argc -= optind;
   argv += optind;
@@ -239,7 +239,7 @@ int main(int argc, char **argv)
   if (status != ARES_SUCCESS)
     {
       fprintf(stderr, "ares_init_options: %s\n",
-             ares_strerror(status));
+              ares_strerror(status));
       return 1;
     }
 
@@ -253,7 +253,7 @@ int main(int argc, char **argv)
   else
     {
       for (; *argv; argv++)
-       ares_query(channel, *argv, dnsclass, type, callback, *argv);
+        ares_query(channel, *argv, dnsclass, type, callback, *argv);
     }
 
   /* Wait for all queries to complete. */
@@ -263,14 +263,14 @@ int main(int argc, char **argv)
       FD_ZERO(&write_fds);
       nfds = ares_fds(channel, &read_fds, &write_fds);
       if (nfds == 0)
-       break;
+        break;
       tvp = ares_timeout(channel, NULL, &tv);
       count = select(nfds, &read_fds, &write_fds, NULL, tvp);
       if (count < 0 && errno != EINVAL)
-       {
-         perror("select");
-         return 1;
-       }
+        {
+          perror("select");
+          return 1;
+        }
       ares_process(channel, &read_fds, &write_fds);
     }
 
@@ -296,7 +296,7 @@ static void callback(void *arg, int status, unsigned char *abuf, int alen)
     {
       printf("%s\n", ares_strerror(status));
       if (!abuf)
-       return;
+        return;
     }
 
   /* Won't happen, but check anyway, for safety. */
@@ -320,11 +320,11 @@ static void callback(void *arg, int status, unsigned char *abuf, int alen)
   /* Display the answer header. */
   printf("id: %d\n", id);
   printf("flags: %s%s%s%s%s\n",
-        qr ? "qr " : "",
-        aa ? "aa " : "",
-        tc ? "tc " : "",
-        rd ? "rd " : "",
-        ra ? "ra " : "");
+         qr ? "qr " : "",
+         aa ? "aa " : "",
+         tc ? "tc " : "",
+         rd ? "rd " : "",
+         ra ? "ra " : "");
   printf("opcode: %s\n", opcodes[opcode]);
   printf("rcode: %s\n", rcodes[rcode]);
 
@@ -335,7 +335,7 @@ static void callback(void *arg, int status, unsigned char *abuf, int alen)
     {
       aptr = display_question(aptr, abuf, alen);
       if (aptr == NULL)
-       return;
+        return;
     }
 
   /* Display the answers. */
@@ -344,7 +344,7 @@ static void callback(void *arg, int status, unsigned char *abuf, int alen)
     {
       aptr = display_rr(aptr, abuf, alen);
       if (aptr == NULL)
-       return;
+        return;
     }
 
   /* Display the NS records. */
@@ -353,7 +353,7 @@ static void callback(void *arg, int status, unsigned char *abuf, int alen)
     {
       aptr = display_rr(aptr, abuf, alen);
       if (aptr == NULL)
-       return;
+        return;
     }
 
   /* Display the additional records. */
@@ -362,13 +362,13 @@ static void callback(void *arg, int status, unsigned char *abuf, int alen)
     {
       aptr = display_rr(aptr, abuf, alen);
       if (aptr == NULL)
-       return;
+        return;
     }
 }
 
 static const unsigned char *display_question(const unsigned char *aptr,
-                                            const unsigned char *abuf,
-                                            int alen)
+                                             const unsigned char *abuf,
+                                             int alen)
 {
   char *name;
   int type, dnsclass, status;
@@ -406,7 +406,7 @@ static const unsigned char *display_question(const unsigned char *aptr,
 }
 
 static const unsigned char *display_rr(const unsigned char *aptr,
-                                      const unsigned char *abuf, int alen)
+                                       const unsigned char *abuf, int alen)
 {
   const unsigned char *p;
   char *name;
@@ -463,7 +463,7 @@ static const unsigned char *display_rr(const unsigned char *aptr,
       /* For these types, the RR data is just a domain name. */
       status = ares_expand_name(aptr, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
-       return NULL;
+        return NULL;
       printf("\t%s.", name);
       free(name);
       break;
@@ -473,12 +473,12 @@ static const unsigned char *display_rr(const unsigned char *aptr,
       p = aptr;
       len = *p;
       if (p + len + 1 > aptr + dlen)
-       return NULL;
+        return NULL;
       printf("\t%.*s", len, p + 1);
       p += len + 1;
       len = *p;
       if (p + len + 1 > aptr + dlen)
-       return NULL;
+        return NULL;
       printf("\t%.*s", len, p + 1);
       break;
 
@@ -487,13 +487,13 @@ static const unsigned char *display_rr(const unsigned char *aptr,
       p = aptr;
       status = ares_expand_name(p, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
-       return NULL;
+        return NULL;
       printf("\t%s.", name);
       free(name);
       p += len;
       status = ares_expand_name(p, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
-       return NULL;
+        return NULL;
       printf("\t%s.", name);
       free(name);
       break;
@@ -503,11 +503,11 @@ static const unsigned char *display_rr(const unsigned char *aptr,
        * then a domain name.
        */
       if (dlen < 2)
-       return NULL;
+        return NULL;
       printf("\t%d", (aptr[0] << 8) | aptr[1]);
       status = ares_expand_name(aptr + 2, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
-       return NULL;
+        return NULL;
       printf("\t%s.", name);
       free(name);
       break;
@@ -519,24 +519,24 @@ static const unsigned char *display_rr(const unsigned char *aptr,
       p = aptr;
       status = ares_expand_name(p, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
-       return NULL;
+        return NULL;
       printf("\t%s.\n", name);
       free(name);
       p += len;
       status = ares_expand_name(p, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
-       return NULL;
+        return NULL;
       printf("\t\t\t\t\t\t%s.\n", name);
       free(name);
       p += len;
       if (p + 20 > aptr + dlen)
-       return NULL;
+        return NULL;
       printf("\t\t\t\t\t\t( %d %d %d %d %d )",
-            (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3],
-            (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7],
-            (p[8] << 24) | (p[9] << 16) | (p[10] << 8) | p[11],
-            (p[12] << 24) | (p[13] << 16) | (p[14] << 8) | p[15],
-            (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]);
+             (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3],
+             (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7],
+             (p[8] << 24) | (p[9] << 16) | (p[10] << 8) | p[11],
+             (p[12] << 24) | (p[13] << 16) | (p[14] << 8) | p[15],
+             (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]);
       break;
 
     case T_TXT:
@@ -544,19 +544,19 @@ static const unsigned char *display_rr(const unsigned char *aptr,
        * strings. */
       p = aptr;
       while (p < aptr + dlen)
-       {
-         len = *p;
-         if (p + len + 1 > aptr + dlen)
-           return NULL;
-         printf("\t%.*s", len, p + 1);
-         p += len + 1;
-       }
+        {
+          len = *p;
+          if (p + len + 1 > aptr + dlen)
+            return NULL;
+          printf("\t%.*s", len, p + 1);
+          p += len + 1;
+        }
       break;
 
     case T_A:
       /* The RR data is a four-byte Internet address. */
       if (dlen != 4)
-       return NULL;
+        return NULL;
       memcpy(&addr, aptr, sizeof(struct in_addr));
       printf("\t%s", inet_ntoa(addr));
       break;
@@ -569,18 +569,18 @@ static const unsigned char *display_rr(const unsigned char *aptr,
       /* The RR data is three two-byte numbers representing the
        * priority, weight, and port, followed by a domain name.
        */
-      
+
       printf("\t%d", DNS__16BIT(aptr));
       printf(" %d", DNS__16BIT(aptr + 2));
       printf(" %d", DNS__16BIT(aptr + 4));
-      
+
       status = ares_expand_name(aptr + 6, abuf, alen, &name, &len);
       if (status != ARES_SUCCESS)
         return NULL;
       printf("\t%s.", name);
       free(name);
       break;
-      
+
     default:
       printf("\t[Unknown RR; cannot parse]");
     }
@@ -596,7 +596,7 @@ static const char *type_name(int type)
   for (i = 0; i < ntypes; i++)
     {
       if (types[i].value == type)
-       return types[i].name;
+        return types[i].name;
     }
   return "(unknown)";
 }
@@ -608,7 +608,7 @@ static const char *class_name(int dnsclass)
   for (i = 0; i < nclasses; i++)
     {
       if (classes[i].value == dnsclass)
-       return classes[i].name;
+        return classes[i].name;
     }
   return "(unknown)";
 }
@@ -616,6 +616,6 @@ static const char *class_name(int dnsclass)
 static void usage(void)
 {
   fprintf(stderr, "usage: adig [-f flag] [-s server] [-c class] "
-         "[-t type] [-p port] name ...\n");
+          "[-t type] [-p port] name ...\n");
   exit(1);
 }
diff --git a/ahost.c b/ahost.c
index 7ec0e4a..f27b1c4 100644 (file)
--- a/ahost.c
+++ b/ahost.c
@@ -33,7 +33,7 @@
 #include "ares_dns.h"
 
 #ifndef INADDR_NONE
-#define        INADDR_NONE 0xffffffff
+#define INADDR_NONE 0xffffffff
 #endif
 
 static void callback(void *arg, int status, struct hostent *host);
@@ -51,7 +51,7 @@ int main(int argc, char **argv)
   WORD wVersionRequested = MAKEWORD(1,1);
   WSADATA wsaData;
   WSAStartup(wVersionRequested, &wsaData);
-#endif  
+#endif
 
   if (argc <= 1)
     usage();
@@ -68,12 +68,12 @@ int main(int argc, char **argv)
     {
       addr.s_addr = inet_addr(*argv);
       if (addr.s_addr == INADDR_NONE)
-       ares_gethostbyname(channel, *argv, AF_INET, callback, *argv);
+        ares_gethostbyname(channel, *argv, AF_INET, callback, *argv);
       else
-       {
-         ares_gethostbyaddr(channel, &addr, sizeof(addr), AF_INET, callback,
-                            *argv);
-       }
+        {
+          ares_gethostbyaddr(channel, &addr, sizeof(addr), AF_INET, callback,
+                             *argv);
+        }
     }
 
   /* Wait for all queries to complete. */
@@ -83,7 +83,7 @@ int main(int argc, char **argv)
       FD_ZERO(&write_fds);
       nfds = ares_fds(channel, &read_fds, &write_fds);
       if (nfds == 0)
-       break;
+        break;
       tvp = ares_timeout(channel, NULL, &tv);
       select(nfds, &read_fds, &write_fds, NULL, tvp);
       ares_process(channel, &read_fds, &write_fds);
diff --git a/ares.h b/ares.h
index 44a9d08..745b233 100644 (file)
--- a/ares.h
+++ b/ares.h
   #include <netinet/in.h>
 #endif
 
-#define ARES_SUCCESS           0
+#define ARES_SUCCESS            0
 
 /* Server error codes (ARES_ENODATA indicates no relevant answer) */
-#define ARES_ENODATA           1
-#define ARES_EFORMERR          2
-#define ARES_ESERVFAIL         3
-#define ARES_ENOTFOUND         4
-#define ARES_ENOTIMP           5
-#define ARES_EREFUSED          6
+#define ARES_ENODATA            1
+#define ARES_EFORMERR           2
+#define ARES_ESERVFAIL          3
+#define ARES_ENOTFOUND          4
+#define ARES_ENOTIMP            5
+#define ARES_EREFUSED           6
 
 /* Locally generated error codes */
-#define ARES_EBADQUERY         7
-#define ARES_EBADNAME          8
-#define ARES_EBADFAMILY                9
-#define ARES_EBADRESP          10
-#define ARES_ECONNREFUSED      11
-#define ARES_ETIMEOUT          12
-#define ARES_EOF               13
-#define ARES_EFILE             14
-#define ARES_ENOMEM            15
-#define ARES_EDESTRUCTION      16
-#define ARES_EBADSTR           17
+#define ARES_EBADQUERY          7
+#define ARES_EBADNAME           8
+#define ARES_EBADFAMILY         9
+#define ARES_EBADRESP           10
+#define ARES_ECONNREFUSED       11
+#define ARES_ETIMEOUT           12
+#define ARES_EOF                13
+#define ARES_EFILE              14
+#define ARES_ENOMEM             15
+#define ARES_EDESTRUCTION       16
+#define ARES_EBADSTR            17
 
 /* Flag values */
-#define ARES_FLAG_USEVC                (1 << 0)
-#define ARES_FLAG_PRIMARY      (1 << 1)
-#define ARES_FLAG_IGNTC                (1 << 2)
-#define ARES_FLAG_NORECURSE    (1 << 3)
-#define ARES_FLAG_STAYOPEN     (1 << 4)
-#define ARES_FLAG_NOSEARCH     (1 << 5)
-#define ARES_FLAG_NOALIASES    (1 << 6)
-#define ARES_FLAG_NOCHECKRESP  (1 << 7)
+#define ARES_FLAG_USEVC         (1 << 0)
+#define ARES_FLAG_PRIMARY       (1 << 1)
+#define ARES_FLAG_IGNTC         (1 << 2)
+#define ARES_FLAG_NORECURSE     (1 << 3)
+#define ARES_FLAG_STAYOPEN      (1 << 4)
+#define ARES_FLAG_NOSEARCH      (1 << 5)
+#define ARES_FLAG_NOALIASES     (1 << 6)
+#define ARES_FLAG_NOCHECKRESP   (1 << 7)
 
 /* Option mask values */
-#define ARES_OPT_FLAGS         (1 << 0)
-#define ARES_OPT_TIMEOUT       (1 << 1)
-#define ARES_OPT_TRIES         (1 << 2)
-#define ARES_OPT_NDOTS         (1 << 3)
-#define ARES_OPT_UDP_PORT      (1 << 4)
-#define ARES_OPT_TCP_PORT      (1 << 5)
-#define ARES_OPT_SERVERS       (1 << 6)
-#define ARES_OPT_DOMAINS       (1 << 7)
-#define ARES_OPT_LOOKUPS       (1 << 8)
+#define ARES_OPT_FLAGS          (1 << 0)
+#define ARES_OPT_TIMEOUT        (1 << 1)
+#define ARES_OPT_TRIES          (1 << 2)
+#define ARES_OPT_NDOTS          (1 << 3)
+#define ARES_OPT_UDP_PORT       (1 << 4)
+#define ARES_OPT_TCP_PORT       (1 << 5)
+#define ARES_OPT_SERVERS        (1 << 6)
+#define ARES_OPT_DOMAINS        (1 << 7)
+#define ARES_OPT_LOOKUPS        (1 << 8)
 
 struct ares_options {
   int flags;
@@ -100,41 +100,41 @@ struct timeval;
 struct ares_channeldata;
 typedef struct ares_channeldata *ares_channel;
 typedef void (*ares_callback)(void *arg, int status, unsigned char *abuf,
-                             int alen);
+                              int alen);
 typedef void (*ares_host_callback)(void *arg, int status,
-                                  struct hostent *hostent);
+                                   struct hostent *hostent);
 
 int ares_init(ares_channel *channelptr);
 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
-                     int optmask);
+                      int optmask);
 void ares_destroy(ares_channel channel);
 void ares_cancel(ares_channel channel);
 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
-              ares_callback callback, void *arg);
+               ares_callback callback, void *arg);
 void ares_query(ares_channel channel, const char *name, int dnsclass,
-               int type, ares_callback callback, void *arg);
+                int type, ares_callback callback, void *arg);
 void ares_search(ares_channel channel, const char *name, int dnsclass,
-                int type, ares_callback callback, void *arg);
+                 int type, ares_callback callback, void *arg);
 void ares_gethostbyname(ares_channel channel, const char *name, int family,
-                       ares_host_callback callback, void *arg);
+                        ares_host_callback callback, void *arg);
 void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
-                       int family, ares_host_callback callback, void *arg);
+                        int family, ares_host_callback callback, void *arg);
 
 int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
-                            struct timeval *tv);
+                             struct timeval *tv);
 void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
 
 int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
-                int rd, unsigned char **buf, int *buflen);
+                 int rd, unsigned char **buf, int *buflen);
 int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
-                    int alen, char **s, long *enclen);
+                     int alen, char **s, long *enclen);
 int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf,
-                    int alen, unsigned char **s, long *enclen);
+                     int alen, unsigned char **s, long *enclen);
 int ares_parse_a_reply(const unsigned char *abuf, int alen,
-                      struct hostent **host);
+                       struct hostent **host);
 int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
-                        int addrlen, int family, struct hostent **host);
+                         int addrlen, int family, struct hostent **host);
 void ares_free_string(void *str);
 void ares_free_hostent(struct hostent *host);
 const char *ares_strerror(int code);
index 551b597..0b04342 100644 (file)
@@ -42,96 +42,96 @@ int ares__get_hostent(FILE *fp, struct hostent **host)
     {
       /* Skip comment lines; terminate line at comment character. */
       if (*line == '#' || !*line)
-       continue;
+        continue;
       p = strchr(line, '#');
       if (p)
-       *p = 0;
+        *p = 0;
 
       /* Get the address part. */
       p = line;
       while (*p && !isspace((unsigned char)*p))
-       p++;
+        p++;
       if (!*p)
-       continue;
+        continue;
       *p = 0;
       addr.s_addr = inet_addr(line);
       if (addr.s_addr == INADDR_NONE)
-       continue;
+        continue;
 
       /* Get the canonical hostname. */
       p++;
       while (isspace((unsigned char)*p))
-       p++;
+        p++;
       if (!*p)
-       continue;
+        continue;
       q = p;
       while (*q && !isspace((unsigned char)*q))
-       q++;
+        q++;
       end_at_hostname = (*q == 0);
       *q = 0;
       canonical = p;
 
       naliases = 0;
       if (!end_at_hostname)
-       {
-         /* Count the aliases. */
-         p = q + 1;
-         while (isspace((unsigned char)*p))
-           p++;
-         while (*p)
-           {
-             while (*p && !isspace((unsigned char)*p))
-               p++;
-             while (isspace((unsigned char)*p))
-               p++;
-             naliases++;
-           }
-       }
+        {
+          /* Count the aliases. */
+          p = q + 1;
+          while (isspace((unsigned char)*p))
+            p++;
+          while (*p)
+            {
+              while (*p && !isspace((unsigned char)*p))
+                p++;
+              while (isspace((unsigned char)*p))
+                p++;
+              naliases++;
+            }
+        }
 
       /* Allocate memory for the host structure. */
       hostent = malloc(sizeof(struct hostent));
       if (!hostent)
-       break;
+        break;
       hostent->h_aliases = NULL;
       hostent->h_addr_list = NULL;
       hostent->h_name = strdup(canonical);
       if (!hostent->h_name)
-       break;
+        break;
       hostent->h_addr_list = malloc(2 * sizeof(char *));
       if (!hostent->h_addr_list)
-       break;
+        break;
       hostent->h_addr_list[0] = malloc(sizeof(struct in_addr));
       if (!hostent->h_addr_list[0])
-       break;
+        break;
       hostent->h_aliases = malloc((naliases + 1) * sizeof(char *));
       if (!hostent->h_aliases)
-       break;
+        break;
 
       /* Copy in aliases. */
       naliases = 0;
       if (!end_at_hostname)
-       {
-         p = canonical + strlen(canonical) + 1;
-         while (isspace((unsigned char)*p))
-           p++;
-         while (*p)
-           {
-             q = p;
-             while (*q && !isspace((unsigned char)*q))
-               q++;
-             hostent->h_aliases[naliases] = malloc(q - p + 1);
-             if (hostent->h_aliases[naliases] == NULL)
-               break;
-             memcpy(hostent->h_aliases[naliases], p, q - p);
-             hostent->h_aliases[naliases][q - p] = 0;
-             p = q;
-             while (isspace((unsigned char)*p))
-               p++;
-             naliases++;
-           }
-         if (*p)
-           break;
-       }
+        {
+          p = canonical + strlen(canonical) + 1;
+          while (isspace((unsigned char)*p))
+            p++;
+          while (*p)
+            {
+              q = p;
+              while (*q && !isspace((unsigned char)*q))
+                q++;
+              hostent->h_aliases[naliases] = malloc(q - p + 1);
+              if (hostent->h_aliases[naliases] == NULL)
+                break;
+              memcpy(hostent->h_aliases[naliases], p, q - p);
+              hostent->h_aliases[naliases][q - p] = 0;
+              p = q;
+              while (isspace((unsigned char)*p))
+                p++;
+              naliases++;
+            }
+          if (*p)
+            break;
+        }
       hostent->h_aliases[naliases] = NULL;
 
       hostent->h_addrtype = AF_INET;
@@ -149,22 +149,22 @@ int ares__get_hostent(FILE *fp, struct hostent **host)
     {
       /* Memory allocation failure; clean up. */
       if (hostent)
-       {
+        {
           if(hostent->h_name)
             free((char *) hostent->h_name);
-         if (hostent->h_aliases)
-           {
-             for (alias = hostent->h_aliases; *alias; alias++)
-               free(*alias);
-           }
+          if (hostent->h_aliases)
+            {
+              for (alias = hostent->h_aliases; *alias; alias++)
+                free(*alias);
+            }
           if(hostent->h_aliases)
             free(hostent->h_aliases);
-         if (hostent->h_addr_list && hostent->h_addr_list[0])
-           free(hostent->h_addr_list[0]);
+          if (hostent->h_addr_list && hostent->h_addr_list[0])
+            free(hostent->h_addr_list[0]);
           if(hostent->h_addr_list)
             free(hostent->h_addr_list);
           free(hostent);
-       }
+        }
       return ARES_ENOMEM;
     }
 
index 8558557..5a66c63 100644 (file)
@@ -38,26 +38,26 @@ int ares__read_line(FILE *fp, char **buf, int *bufsize)
     {
       *buf = malloc(128);
       if (!*buf)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
       *bufsize = 128;
     }
 
   while (1)
     {
       if (!fgets(*buf + offset, *bufsize - (int)offset, fp))
-       return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF;
+        return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF;
       len = offset + strlen(*buf + offset);
       if ((*buf)[len - 1] == '\n')
-       {
-         (*buf)[len - 1] = 0;
-         return ARES_SUCCESS;
-       }
+        {
+          (*buf)[len - 1] = 0;
+          return ARES_SUCCESS;
+        }
       offset = len;
 
       /* Allocate more space. */
       newbuf = realloc(*buf, *bufsize * 2);
       if (!newbuf)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
       *buf = newbuf;
       *bufsize *= 2;
     }
index cfab473..adac9d6 100644 (file)
 #ifndef ARES__DNS_H
 #define ARES__DNS_H
 
-#define DNS__16BIT(p)                  (((p)[0] << 8) | (p)[1])
-#define DNS__32BIT(p)                  (((p)[0] << 24) | ((p)[1] << 16) | \
-                                        ((p)[2] << 8) | (p)[3])
-#define DNS__SET16BIT(p, v)            (((p)[0] = ((v) >> 8) & 0xff), \
-                                        ((p)[1] = (v) & 0xff))
-#define DNS__SET32BIT(p, v)            (((p)[0] = ((v) >> 24) & 0xff), \
-                                        ((p)[1] = ((v) >> 16) & 0xff), \
-                                        ((p)[2] = ((v) >> 8) & 0xff), \
-                                        ((p)[3] = (v) & 0xff))
+#define DNS__16BIT(p)                   (((p)[0] << 8) | (p)[1])
+#define DNS__32BIT(p)                   (((p)[0] << 24) | ((p)[1] << 16) | \
+                                         ((p)[2] << 8) | (p)[3])
+#define DNS__SET16BIT(p, v)             (((p)[0] = ((v) >> 8) & 0xff), \
+                                         ((p)[1] = (v) & 0xff))
+#define DNS__SET32BIT(p, v)             (((p)[0] = ((v) >> 24) & 0xff), \
+                                         ((p)[1] = ((v) >> 16) & 0xff), \
+                                         ((p)[2] = ((v) >> 8) & 0xff), \
+                                         ((p)[3] = (v) & 0xff))
 
 /* Macros for parsing a DNS header */
-#define DNS_HEADER_QID(h)              DNS__16BIT(h)
-#define DNS_HEADER_QR(h)               (((h)[2] >> 7) & 0x1)
-#define DNS_HEADER_OPCODE(h)           (((h)[2] >> 3) & 0xf)
-#define DNS_HEADER_AA(h)               (((h)[2] >> 2) & 0x1)
-#define DNS_HEADER_TC(h)               (((h)[2] >> 1) & 0x1)
-#define DNS_HEADER_RD(h)               ((h)[2] & 0x1)
-#define DNS_HEADER_RA(h)               (((h)[3] >> 7) & 0x1)
-#define DNS_HEADER_Z(h)                        (((h)[3] >> 4) & 0x7)
-#define DNS_HEADER_RCODE(h)            ((h)[3] & 0xf)
-#define DNS_HEADER_QDCOUNT(h)          DNS__16BIT((h) + 4)
-#define DNS_HEADER_ANCOUNT(h)          DNS__16BIT((h) + 6)
-#define DNS_HEADER_NSCOUNT(h)          DNS__16BIT((h) + 8)
-#define DNS_HEADER_ARCOUNT(h)          DNS__16BIT((h) + 10)
+#define DNS_HEADER_QID(h)               DNS__16BIT(h)
+#define DNS_HEADER_QR(h)                (((h)[2] >> 7) & 0x1)
+#define DNS_HEADER_OPCODE(h)            (((h)[2] >> 3) & 0xf)
+#define DNS_HEADER_AA(h)                (((h)[2] >> 2) & 0x1)
+#define DNS_HEADER_TC(h)                (((h)[2] >> 1) & 0x1)
+#define DNS_HEADER_RD(h)                ((h)[2] & 0x1)
+#define DNS_HEADER_RA(h)                (((h)[3] >> 7) & 0x1)
+#define DNS_HEADER_Z(h)                 (((h)[3] >> 4) & 0x7)
+#define DNS_HEADER_RCODE(h)             ((h)[3] & 0xf)
+#define DNS_HEADER_QDCOUNT(h)           DNS__16BIT((h) + 4)
+#define DNS_HEADER_ANCOUNT(h)           DNS__16BIT((h) + 6)
+#define DNS_HEADER_NSCOUNT(h)           DNS__16BIT((h) + 8)
+#define DNS_HEADER_ARCOUNT(h)           DNS__16BIT((h) + 10)
 
 /* Macros for constructing a DNS header */
-#define DNS_HEADER_SET_QID(h, v)       DNS__SET16BIT(h, v)
-#define DNS_HEADER_SET_QR(h, v)                ((h)[2] |= (((v) & 0x1) << 7))
-#define DNS_HEADER_SET_OPCODE(h, v)    ((h)[2] |= (((v) & 0xf) << 3))
-#define DNS_HEADER_SET_AA(h, v)                ((h)[2] |= (((v) & 0x1) << 2))
-#define DNS_HEADER_SET_TC(h, v)                ((h)[2] |= (((v) & 0x1) << 1))
-#define DNS_HEADER_SET_RD(h, v)                ((h)[2] |= (((v) & 0x1)))
-#define DNS_HEADER_SET_RA(h, v)                ((h)[3] |= (((v) & 0x1) << 7))
-#define DNS_HEADER_SET_Z(h, v)         ((h)[3] |= (((v) & 0x7) << 4))
-#define DNS_HEADER_SET_RCODE(h, v)     ((h)[3] |= (((v) & 0xf)))
-#define DNS_HEADER_SET_QDCOUNT(h, v)   DNS__SET16BIT((h) + 4, v)
-#define DNS_HEADER_SET_ANCOUNT(h, v)   DNS__SET16BIT((h) + 6, v)
-#define DNS_HEADER_SET_NSCOUNT(h, v)   DNS__SET16BIT((h) + 8, v)
-#define DNS_HEADER_SET_ARCOUNT(h, v)   DNS__SET16BIT((h) + 10, v)
+#define DNS_HEADER_SET_QID(h, v)        DNS__SET16BIT(h, v)
+#define DNS_HEADER_SET_QR(h, v)         ((h)[2] |= (((v) & 0x1) << 7))
+#define DNS_HEADER_SET_OPCODE(h, v)     ((h)[2] |= (((v) & 0xf) << 3))
+#define DNS_HEADER_SET_AA(h, v)         ((h)[2] |= (((v) & 0x1) << 2))
+#define DNS_HEADER_SET_TC(h, v)         ((h)[2] |= (((v) & 0x1) << 1))
+#define DNS_HEADER_SET_RD(h, v)         ((h)[2] |= (((v) & 0x1)))
+#define DNS_HEADER_SET_RA(h, v)         ((h)[3] |= (((v) & 0x1) << 7))
+#define DNS_HEADER_SET_Z(h, v)          ((h)[3] |= (((v) & 0x7) << 4))
+#define DNS_HEADER_SET_RCODE(h, v)      ((h)[3] |= (((v) & 0xf)))
+#define DNS_HEADER_SET_QDCOUNT(h, v)    DNS__SET16BIT((h) + 4, v)
+#define DNS_HEADER_SET_ANCOUNT(h, v)    DNS__SET16BIT((h) + 6, v)
+#define DNS_HEADER_SET_NSCOUNT(h, v)    DNS__SET16BIT((h) + 8, v)
+#define DNS_HEADER_SET_ARCOUNT(h, v)    DNS__SET16BIT((h) + 10, v)
 
 /* Macros for parsing the fixed part of a DNS question */
-#define DNS_QUESTION_TYPE(q)           DNS__16BIT(q)
-#define DNS_QUESTION_CLASS(q)          DNS__16BIT((q) + 2)
+#define DNS_QUESTION_TYPE(q)            DNS__16BIT(q)
+#define DNS_QUESTION_CLASS(q)           DNS__16BIT((q) + 2)
 
 /* Macros for constructing the fixed part of a DNS question */
-#define DNS_QUESTION_SET_TYPE(q, v)    DNS__SET16BIT(q, v)
-#define DNS_QUESTION_SET_CLASS(q, v)   DNS__SET16BIT((q) + 2, v)
+#define DNS_QUESTION_SET_TYPE(q, v)     DNS__SET16BIT(q, v)
+#define DNS_QUESTION_SET_CLASS(q, v)    DNS__SET16BIT((q) + 2, v)
 
 /* Macros for parsing the fixed part of a DNS resource record */
-#define DNS_RR_TYPE(r)                 DNS__16BIT(r)
-#define DNS_RR_CLASS(r)                        DNS__16BIT((r) + 2)
-#define DNS_RR_TTL(r)                  DNS__32BIT((r) + 4)
-#define DNS_RR_LEN(r)                  DNS__16BIT((r) + 8)
+#define DNS_RR_TYPE(r)                  DNS__16BIT(r)
+#define DNS_RR_CLASS(r)                 DNS__16BIT((r) + 2)
+#define DNS_RR_TTL(r)                   DNS__32BIT((r) + 4)
+#define DNS_RR_LEN(r)                   DNS__16BIT((r) + 8)
 
 /* Macros for constructing the fixed part of a DNS resource record */
-#define DNS_RR_SET_TYPE(r)             DNS__SET16BIT(r, v)
-#define DNS_RR_SET_CLASS(r)            DNS__SET16BIT((r) + 2, v)
-#define DNS_RR_SET_TTL(r)              DNS__SET32BIT((r) + 4, v)
-#define DNS_RR_SET_LEN(r)              DNS__SET16BIT((r) + 8, v)
+#define DNS_RR_SET_TYPE(r)              DNS__SET16BIT(r, v)
+#define DNS_RR_SET_CLASS(r)             DNS__SET16BIT((r) + 2, v)
+#define DNS_RR_SET_TTL(r)               DNS__SET32BIT((r) + 4, v)
+#define DNS_RR_SET_LEN(r)               DNS__SET16BIT((r) + 8, v)
 
 #endif /* ARES__DNS_H */
index 0f95c07..0942bfa 100644 (file)
@@ -28,7 +28,7 @@
 #include "ares_private.h" /* for the memdebug */
 
 static int name_length(const unsigned char *encoded, const unsigned char *abuf,
-                      int alen);
+                       int alen);
 
 /* Expand an RFC1035-encoded domain name given by encoded.  The
  * containing message is given by abuf and alen.  The result given by
@@ -55,7 +55,7 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
  */
 
 int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
-                    int alen, char **s, long *enclen)
+                     int alen, char **s, long *enclen)
 {
   int len, indir = 0;
   char *q;
@@ -75,27 +75,27 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
   while (*p)
     {
       if ((*p & INDIR_MASK) == INDIR_MASK)
-       {
-         if (!indir)
-           {
-             *enclen = p + 2 - encoded;
-             indir = 1;
-           }
-         p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1));
-       }
+        {
+          if (!indir)
+            {
+              *enclen = p + 2 - encoded;
+              indir = 1;
+            }
+          p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1));
+        }
       else
-       {
-         len = *p;
-         p++;
-         while (len--)
-           {
-             if (*p == '.' || *p == '\\')
-               *q++ = '\\';
-             *q++ = *p;
-             p++;
-           }
-         *q++ = '.';
-       }
+        {
+          len = *p;
+          p++;
+          while (len--)
+            {
+              if (*p == '.' || *p == '\\')
+                *q++ = '\\';
+              *q++ = *p;
+              p++;
+            }
+          *q++ = '.';
+        }
     }
   if (!indir)
     *enclen = p + 1 - encoded;
@@ -111,7 +111,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
  * -1 if the encoding is invalid.
  */
 static int name_length(const unsigned char *encoded, const unsigned char *abuf,
-                      int alen)
+                       int alen)
 {
   int n = 0, offset, indir = 0;
 
@@ -122,34 +122,34 @@ static int name_length(const unsigned char *encoded, const unsigned char *abuf,
   while (*encoded)
     {
       if ((*encoded & INDIR_MASK) == INDIR_MASK)
-       {
-         /* Check the offset and go there. */
-         if (encoded + 1 >= abuf + alen)
-           return -1;
-         offset = (*encoded & ~INDIR_MASK) << 8 | *(encoded + 1);
-         if (offset >= alen)
-           return -1;
-         encoded = abuf + offset;
-
-         /* If we've seen more indirects than the message length,
-          * then there's a loop.
-          */
-         if (++indir > alen)
-           return -1;
-       }
+        {
+          /* Check the offset and go there. */
+          if (encoded + 1 >= abuf + alen)
+            return -1;
+          offset = (*encoded & ~INDIR_MASK) << 8 | *(encoded + 1);
+          if (offset >= alen)
+            return -1;
+          encoded = abuf + offset;
+
+          /* If we've seen more indirects than the message length,
+           * then there's a loop.
+           */
+          if (++indir > alen)
+            return -1;
+        }
       else
-       {
-         offset = *encoded;
-         if (encoded + offset + 1 >= abuf + alen)
-           return -1;
-         encoded++;
-         while (offset--)
-           {
-             n += (*encoded == '.' || *encoded == '\\') ? 2 : 1;
-             encoded++;
-           }
-         n++;
-       }
+        {
+          offset = *encoded;
+          if (encoded + offset + 1 >= abuf + alen)
+            return -1;
+          encoded++;
+          while (offset--)
+            {
+              n += (*encoded == '.' || *encoded == '\\') ? 2 : 1;
+              encoded++;
+            }
+          n++;
+        }
     }
 
   /* If there were any labels at all, then the number of dots is one
index 58cf67a..dd91745 100644 (file)
@@ -37,19 +37,19 @@ int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
     {
       server = &channel->servers[i];
       if (server->udp_socket != ARES_SOCKET_BAD)
-       {
-         FD_SET(server->udp_socket, read_fds);
-         if (server->udp_socket >= nfds)
-           nfds = server->udp_socket + 1;
-       }
+        {
+          FD_SET(server->udp_socket, read_fds);
+          if (server->udp_socket >= nfds)
+            nfds = server->udp_socket + 1;
+        }
       if (server->tcp_socket != ARES_SOCKET_BAD)
-       {
-         FD_SET(server->tcp_socket, read_fds);
-         if (server->qhead)
-           FD_SET(server->tcp_socket, write_fds);
-         if (server->tcp_socket >= nfds)
-           nfds = server->tcp_socket + 1;
-       }
+        {
+          FD_SET(server->tcp_socket, read_fds);
+          if (server->qhead)
+            FD_SET(server->tcp_socket, write_fds);
+          if (server->tcp_socket >= nfds)
+            nfds = server->tcp_socket + 1;
+        }
     }
   return nfds;
 }
index 978beba..827ccfe 100644 (file)
@@ -48,13 +48,13 @@ struct addr_query {
 
 static void next_lookup(struct addr_query *aquery);
 static void addr_callback(void *arg, int status, unsigned char *abuf,
-                         int alen);
+                          int alen);
 static void end_aquery(struct addr_query *aquery, int status,
-                      struct hostent *host);
+                       struct hostent *host);
 static int file_lookup(struct in_addr *addr, struct hostent **host);
 
 void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
-                       int family, ares_host_callback callback, void *arg)
+                        int family, ares_host_callback callback, void *arg)
 {
   struct addr_query *aquery;
 
@@ -90,27 +90,27 @@ static void next_lookup(struct addr_query *aquery)
   for (p = aquery->remaining_lookups; *p; p++)
     {
       switch (*p)
-       {
-       case 'b':
-         addr = ntohl(aquery->addr.s_addr);
-         a1 = (int)((addr >> 24) & 0xff);
-         a2 = (int)((addr >> 16) & 0xff);
-         a3 = (int)((addr >> 8) & 0xff);
-         a4 = (int)(addr & 0xff);
-         sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
-         aquery->remaining_lookups = p + 1;
-         ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
-                    aquery);
-         return;
-       case 'f':
-         status = file_lookup(&aquery->addr, &host);
-         if (status != ARES_ENOTFOUND)
-           {
-             end_aquery(aquery, status, host);
-             return;
-           }
-         break;
-       }
+        {
+        case 'b':
+          addr = ntohl(aquery->addr.s_addr);
+          a1 = (int)((addr >> 24) & 0xff);
+          a2 = (int)((addr >> 16) & 0xff);
+          a3 = (int)((addr >> 8) & 0xff);
+          a4 = (int)(addr & 0xff);
+          sprintf(name, "%d.%d.%d.%d.in-addr.arpa", a4, a3, a2, a1);
+          aquery->remaining_lookups = p + 1;
+          ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback,
+                     aquery);
+          return;
+        case 'f':
+          status = file_lookup(&aquery->addr, &host);
+          if (status != ARES_ENOTFOUND)
+            {
+              end_aquery(aquery, status, host);
+              return;
+            }
+          break;
+        }
     }
   end_aquery(aquery, ARES_ENOTFOUND, NULL);
 }
@@ -123,7 +123,7 @@ static void addr_callback(void *arg, int status, unsigned char *abuf, int alen)
   if (status == ARES_SUCCESS)
     {
       status = ares_parse_ptr_reply(abuf, alen, &aquery->addr,
-                                   sizeof(struct in_addr), AF_INET, &host);
+                                    sizeof(struct in_addr), AF_INET, &host);
       end_aquery(aquery, status, host);
     }
   else if (status == ARES_EDESTRUCTION)
@@ -133,7 +133,7 @@ static void addr_callback(void *arg, int status, unsigned char *abuf, int alen)
 }
 
 static void end_aquery(struct addr_query *aquery, int status,
-                      struct hostent *host)
+                       struct hostent *host)
 {
   aquery->callback(aquery->arg, status, host);
   if (host)
@@ -150,19 +150,19 @@ static int file_lookup(struct in_addr *addr, struct hostent **host)
 
   char PATH_HOSTS[MAX_PATH];
   if (IsNT) {
-       char tmp[MAX_PATH];
-       HKEY hkeyHosts;
-
-       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
-               == ERROR_SUCCESS)
-       {
-               DWORD dwLength = MAX_PATH;
-               RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp, 
-                       &dwLength);
-               ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
-               RegCloseKey(hkeyHosts);
-       }
-  } 
+        char tmp[MAX_PATH];
+        HKEY hkeyHosts;
+
+        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
+                == ERROR_SUCCESS)
+        {
+                DWORD dwLength = MAX_PATH;
+                RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
+                        &dwLength);
+                ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
+                RegCloseKey(hkeyHosts);
+        }
+  }
   else
     GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
 
@@ -183,7 +183,7 @@ static int file_lookup(struct in_addr *addr, struct hostent **host)
   while ((status = ares__get_hostent(fp, host)) == ARES_SUCCESS)
     {
       if (memcmp((*host)->h_addr, addr, sizeof(struct in_addr)) == 0)
-       break;
+        break;
       ares_free_hostent(*host);
     }
   fclose(fp);
index decac55..adf2f78 100644 (file)
@@ -50,19 +50,19 @@ struct host_query {
 
 static void next_lookup(struct host_query *hquery);
 static void host_callback(void *arg, int status, unsigned char *abuf,
-                         int alen);
+                          int alen);
 static void end_hquery(struct host_query *hquery, int status,
-                      struct hostent *host);
+                       struct hostent *host);
 static int fake_hostent(const char *name, ares_host_callback callback,
-                       void *arg);
+                        void *arg);
 static int file_lookup(const char *name, struct hostent **host);
 static void sort_addresses(struct hostent *host, struct apattern *sortlist,
-                          int nsort);
+                           int nsort);
 static int get_address_index(struct in_addr *addr, struct apattern *sortlist,
-                            int nsort);
+                             int nsort);
 
 void ares_gethostbyname(ares_channel channel, const char *name, int family,
-                       ares_host_callback callback, void *arg)
+                        ares_host_callback callback, void *arg)
 {
   struct host_query *hquery;
 
@@ -106,26 +106,26 @@ static void next_lookup(struct host_query *hquery)
   struct hostent *host;
 
   for (p = hquery->remaining_lookups; *p; p++)
-    { 
+    {
       switch (*p)
-       {
-       case 'b':
-         /* DNS lookup */
-         hquery->remaining_lookups = p + 1;
-         ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
-                     hquery);
-         return;
-
-       case 'f':
-         /* Host file lookup */
-         status = file_lookup(hquery->name, &host);
-         if (status != ARES_ENOTFOUND)
-           {
-             end_hquery(hquery, status, host);
-             return;
-           }
-         break;
-       }
+        {
+        case 'b':
+          /* DNS lookup */
+          hquery->remaining_lookups = p + 1;
+          ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
+                      hquery);
+          return;
+
+        case 'f':
+          /* Host file lookup */
+          status = file_lookup(hquery->name, &host);
+          if (status != ARES_ENOTFOUND)
+            {
+              end_hquery(hquery, status, host);
+              return;
+            }
+          break;
+        }
     }
   end_hquery(hquery, ARES_ENOTFOUND, NULL);
 }
@@ -140,7 +140,7 @@ static void host_callback(void *arg, int status, unsigned char *abuf, int alen)
     {
       status = ares_parse_a_reply(abuf, alen, &host);
       if (host && channel->nsort)
-       sort_addresses(host, channel->sortlist, channel->nsort);
+        sort_addresses(host, channel->sortlist, channel->nsort);
       end_hquery(hquery, status, host);
     }
   else if (status == ARES_EDESTRUCTION)
@@ -150,7 +150,7 @@ static void host_callback(void *arg, int status, unsigned char *abuf, int alen)
 }
 
 static void end_hquery(struct host_query *hquery, int status,
-                      struct hostent *host)
+                       struct hostent *host)
 {
   hquery->callback(hquery->arg, status, host);
   if (host)
@@ -163,7 +163,7 @@ static void end_hquery(struct host_query *hquery, int status,
  * query immediately, and return true.  Otherwise return false.
  */
 static int fake_hostent(const char *name, ares_host_callback callback,
-                       void *arg)
+                        void *arg)
 {
   struct in_addr addr;
   struct hostent hostent;
@@ -175,7 +175,7 @@ static int fake_hostent(const char *name, ares_host_callback callback,
   for (p = name; *p; p++)
     {
       if (!isdigit((unsigned char)*p) && *p != '.')
-       return 0;
+        return 0;
     }
 
   /* It also only looks like an IP address if it's non-zero-length and
@@ -222,19 +222,19 @@ static int file_lookup(const char *name, struct hostent **host)
 #ifdef WIN32
   char PATH_HOSTS[MAX_PATH];
   if (IsNT) {
-       char tmp[MAX_PATH];
-       HKEY hkeyHosts;
-
-       if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
-               == ERROR_SUCCESS)
-       {
-               DWORD dwLength = MAX_PATH;
-               RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp, 
-                       &dwLength);
-               ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
-               RegCloseKey(hkeyHosts);
-       }
-  } 
+        char tmp[MAX_PATH];
+        HKEY hkeyHosts;
+
+        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0, KEY_READ, &hkeyHosts)
+                == ERROR_SUCCESS)
+        {
+                DWORD dwLength = MAX_PATH;
+                RegQueryValueEx(hkeyHosts, DATABASEPATH, NULL, NULL, tmp,
+                        &dwLength);
+                ExpandEnvironmentStrings(tmp, PATH_HOSTS, MAX_PATH);
+                RegCloseKey(hkeyHosts);
+        }
+  }
   else
     GetWindowsDirectory(PATH_HOSTS, MAX_PATH);
 
@@ -255,14 +255,14 @@ static int file_lookup(const char *name, struct hostent **host)
   while ((status = ares__get_hostent(fp, host)) == ARES_SUCCESS)
     {
       if (strcasecmp((*host)->h_name, name) == 0)
-       break;
+        break;
       for (alias = (*host)->h_aliases; *alias; alias++)
-       {
-         if (strcasecmp(*alias, name) == 0)
-           break;
-       }
+        {
+          if (strcasecmp(*alias, name) == 0)
+            break;
+        }
       if (*alias)
-       break;
+        break;
       ares_free_hostent(*host);
     }
   fclose(fp);
@@ -274,7 +274,7 @@ static int file_lookup(const char *name, struct hostent **host)
 }
 
 static void sort_addresses(struct hostent *host, struct apattern *sortlist,
-                          int nsort)
+                           int nsort)
 {
   struct in_addr a1, a2;
   int i1, i2, ind1, ind2;
@@ -289,13 +289,13 @@ static void sort_addresses(struct hostent *host, struct apattern *sortlist,
       memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
       ind1 = get_address_index(&a1, sortlist, nsort);
       for (i2 = i1 - 1; i2 >= 0; i2--)
-       {
-         memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
-         ind2 = get_address_index(&a2, sortlist, nsort);
-         if (ind2 <= ind1)
-           break;
-         memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
-       }
+        {
+          memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
+          ind2 = get_address_index(&a2, sortlist, nsort);
+          if (ind2 <= ind1)
+            break;
+          memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
+        }
       memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr));
     }
 }
@@ -304,14 +304,14 @@ static void sort_addresses(struct hostent *host, struct apattern *sortlist,
  * if none of them match.
  */
 static int get_address_index(struct in_addr *addr, struct apattern *sortlist,
-                            int nsort)
+                             int nsort)
 {
   int i;
 
   for (i = 0; i < nsort; i++)
     {
       if ((addr->s_addr & sortlist[i].mask.s_addr) == sortlist[i].addr.s_addr)
-       break;
+        break;
     }
   return i;
 }
index 227067e..c245233 100644 (file)
@@ -50,7 +50,7 @@
 #endif
 
 static int init_by_options(ares_channel channel, struct ares_options *options,
-                          int optmask);
+                           int optmask);
 static int init_by_environment(ares_channel channel);
 static int init_by_resolv_conf(ares_channel channel);
 static int init_by_defaults(ares_channel channel);
@@ -58,9 +58,9 @@ static int config_domain(ares_channel channel, char *str);
 static int config_lookup(ares_channel channel, const char *str,
                          const char *bindch, const char *filech);
 static int config_nameserver(struct server_state **servers, int *nservers,
-                            char *str);
+                             char *str);
 static int config_sortlist(struct apattern **sortlist, int *nsort,
-                          const char *str);
+                           const char *str);
 static int set_search(ares_channel channel, const char *str);
 static int set_options(ares_channel channel, const char *str);
 static char *try_config(char *s, const char *opt);
@@ -74,7 +74,7 @@ int ares_init(ares_channel *channelptr)
 }
 
 int ares_init_options(ares_channel *channelptr, struct ares_options *options,
-                     int optmask)
+                      int optmask)
 {
   ares_channel channel;
   int i, status;
@@ -116,15 +116,15 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
     {
       /* Something failed; clean up memory we may have allocated. */
       if (channel->nservers != -1)
-       free(channel->servers);
+        free(channel->servers);
       if (channel->domains)
-       {
-         for (i = 0; i < channel->ndomains; i++)
-           free(channel->domains[i]);
-         free(channel->domains);
-       }
+        {
+          for (i = 0; i < channel->ndomains; i++)
+            free(channel->domains[i]);
+          free(channel->domains);
+        }
       if (channel->sortlist)
-       free(channel->sortlist);
+        free(channel->sortlist);
       if(channel->lookups)
         free(channel->lookups);
       free(channel);
@@ -163,7 +163,7 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
 }
 
 static int init_by_options(ares_channel channel, struct ares_options *options,
-                          int optmask)
+                           int optmask)
 {
   int i;
 
@@ -185,11 +185,11 @@ static int init_by_options(ares_channel channel, struct ares_options *options,
   if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1)
     {
       channel->servers =
-       malloc(options->nservers * sizeof(struct server_state));
+        malloc(options->nservers * sizeof(struct server_state));
       if (!channel->servers && options->nservers != 0)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
       for (i = 0; i < options->nservers; i++)
-       channel->servers[i].addr = options->servers[i];
+        channel->servers[i].addr = options->servers[i];
       channel->nservers = options->nservers;
     }
 
@@ -200,14 +200,14 @@ static int init_by_options(ares_channel channel, struct ares_options *options,
     {
       channel->domains = malloc(options->ndomains * sizeof(char *));
       if (!channel->domains && options->ndomains != 0)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
       for (i = 0; i < options->ndomains; i++)
-       {
-         channel->ndomains = i;
-         channel->domains[i] = strdup(options->domains[i]);
-         if (!channel->domains[i])
-           return ARES_ENOMEM;
-       }
+        {
+          channel->ndomains = i;
+          channel->domains[i] = strdup(options->domains[i]);
+          if (!channel->domains[i])
+            return ARES_ENOMEM;
+        }
       channel->ndomains = options->ndomains;
     }
 
@@ -216,7 +216,7 @@ static int init_by_options(ares_channel channel, struct ares_options *options,
     {
       channel->lookups = strdup(options->lookups);
       if (!channel->lookups)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
     }
 
   return ARES_SUCCESS;
@@ -232,7 +232,7 @@ static int init_by_environment(ares_channel channel)
     {
       status = set_search(channel, localdomain);
       if (status != ARES_SUCCESS)
-       return status;
+        return status;
     }
 
   res_options = getenv("RES_OPTIONS");
@@ -240,7 +240,7 @@ static int init_by_environment(ares_channel channel)
     {
       status = set_options(channel, res_options);
       if (status != ARES_SUCCESS)
-       return status;
+        return status;
     }
 
   return ARES_SUCCESS;
@@ -392,14 +392,14 @@ static int init_by_resolv_conf(ares_channel channel)
    On Windows 9X, the DNS server can be found in:
 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer
 
-       On Windows NT/2000/XP/2003:
+        On Windows NT/2000/XP/2003:
 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer
-       or
+        or
 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
-       or
+        or
 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
 NameServer
-       or
+        or
 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
 DhcpNameServer
    */
@@ -663,7 +663,7 @@ static int init_by_defaults(ares_channel channel)
       /* If nobody specified servers, try a local named. */
       channel->servers = malloc(sizeof(struct server_state));
       if (!channel->servers)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
       channel->servers[0].addr.s_addr = htonl(INADDR_LOOPBACK);
       channel->nservers = 1;
     }
@@ -674,22 +674,22 @@ static int init_by_defaults(ares_channel channel)
        * or set it to empty if the hostname isn't helpful.
        */
       if (gethostname(hostname, sizeof(hostname)) == -1
-         || !strchr(hostname, '.'))
-       {
-         channel->domains = malloc(0);
-         channel->ndomains = 0;
-       }
+          || !strchr(hostname, '.'))
+        {
+          channel->domains = malloc(0);
+          channel->ndomains = 0;
+        }
       else
-       {
-         channel->domains = malloc(sizeof(char *));
-         if (!channel->domains)
-           return ARES_ENOMEM;
-         channel->ndomains = 0;
-         channel->domains[0] = strdup(strchr(hostname, '.') + 1);
-         if (!channel->domains[0])
-           return ARES_ENOMEM;
-         channel->ndomains = 1;
-       }
+        {
+          channel->domains = malloc(sizeof(char *));
+          if (!channel->domains)
+            return ARES_ENOMEM;
+          channel->ndomains = 0;
+          channel->domains[0] = strdup(strchr(hostname, '.') + 1);
+          if (!channel->domains[0])
+            return ARES_ENOMEM;
+          channel->ndomains = 1;
+        }
     }
 
   if (channel->nsort == -1)
@@ -702,7 +702,7 @@ static int init_by_defaults(ares_channel channel)
     {
       channel->lookups = strdup("fb");
       if (!channel->lookups)
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
     }
 
   return ARES_SUCCESS;
@@ -735,13 +735,13 @@ static int config_lookup(ares_channel channel, const char *str,
   while (*p)
     {
       if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
-       if (*p == *bindch) *l++ = 'b';
+        if (*p == *bindch) *l++ = 'b';
         else *l++ = 'f';
       }
       while (*p && !isspace((unsigned char)*p) && (*p != ','))
-       p++;
+        p++;
       while (*p && (isspace((unsigned char)*p) || (*p == ',')))
-       p++;
+        p++;
     }
   *l = 0;
   channel->lookups = strdup(lookups);
@@ -749,7 +749,7 @@ static int config_lookup(ares_channel channel, const char *str,
 }
 
 static int config_nameserver(struct server_state **servers, int *nservers,
-                            char *str)
+                             char *str)
 {
   struct in_addr addr;
   struct server_state *newserv;
@@ -810,7 +810,7 @@ static int config_nameserver(struct server_state **servers, int *nservers,
 }
 
 static int config_sortlist(struct apattern **sortlist, int *nsort,
-                          const char *str)
+                           const char *str)
 {
   struct apattern pat, *newsort;
   const char *q;
@@ -820,37 +820,37 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
     {
       q = str;
       while (*q && *q != '/' && *q != ';' && !isspace((unsigned char)*q))
-       q++;
+        q++;
       if (ip_addr(str, (int)(q - str), &pat.addr) == 0)
-       {
-         /* We have a pattern address; now determine the mask. */
-         if (*q == '/')
-           {
-             str = q + 1;
-             while (*q && *q != ';' && !isspace((unsigned char)*q))
-               q++;
-             if (ip_addr(str, (int)(q - str), &pat.mask) != 0)
-               natural_mask(&pat);
-           }
-         else
-           natural_mask(&pat);
-
-         /* Add this pattern to our list. */
-         newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
-         if (!newsort)
-           return ARES_ENOMEM;
-         newsort[*nsort] = pat;
-         *sortlist = newsort;
-         (*nsort)++;
-       }
+        {
+          /* We have a pattern address; now determine the mask. */
+          if (*q == '/')
+            {
+              str = q + 1;
+              while (*q && *q != ';' && !isspace((unsigned char)*q))
+                q++;
+              if (ip_addr(str, (int)(q - str), &pat.mask) != 0)
+                natural_mask(&pat);
+            }
+          else
+            natural_mask(&pat);
+
+          /* Add this pattern to our list. */
+          newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
+          if (!newsort)
+            return ARES_ENOMEM;
+          newsort[*nsort] = pat;
+          *sortlist = newsort;
+          (*nsort)++;
+        }
       else
-       {
-         while (*q && *q != ';' && !isspace((unsigned char)*q))
-           q++;
-       }
+        {
+          while (*q && *q != ';' && !isspace((unsigned char)*q))
+            q++;
+        }
       str = q;
       while (isspace((unsigned char)*str))
-       str++;
+        str++;
     }
 
   return ARES_SUCCESS;
@@ -875,9 +875,9 @@ static int set_search(ares_channel channel, const char *str)
   while (*p)
     {
       while (*p && !isspace((unsigned char)*p))
-       p++;
+        p++;
       while (isspace((unsigned char)*p))
-       p++;
+        p++;
       n++;
     }
 
@@ -893,15 +893,15 @@ static int set_search(ares_channel channel, const char *str)
       channel->ndomains = n;
       q = p;
       while (*q && !isspace((unsigned char)*q))
-       q++;
+        q++;
       channel->domains[n] = malloc(q - p + 1);
       if (!channel->domains[n])
-       return ARES_ENOMEM;
+        return ARES_ENOMEM;
       memcpy(channel->domains[n], p, q - p);
       channel->domains[n][q - p] = 0;
       p = q;
       while (isspace((unsigned char)*p))
-       p++;
+        p++;
       n++;
     }
   channel->ndomains = n;
@@ -918,19 +918,19 @@ static int set_options(ares_channel channel, const char *str)
     {
       q = p;
       while (*q && !isspace((unsigned char)*q))
-       q++;
+        q++;
       val = try_option(p, q, "ndots:");
       if (val && channel->ndots == -1)
-       channel->ndots = atoi(val);
+        channel->ndots = atoi(val);
       val = try_option(p, q, "retrans:");
       if (val && channel->timeout == -1)
-       channel->timeout = atoi(val);
+        channel->timeout = atoi(val);
       val = try_option(p, q, "retry:");
       if (val && channel->tries == -1)
-       channel->tries = atoi(val);
+        channel->tries = atoi(val);
       p = q;
       while (isspace((unsigned char)*p))
-       p++;
+        p++;
     }
 
   return ARES_SUCCESS;
index d2ae66b..fd9c369 100644 (file)
  *
  * AA, TC, RA, and RCODE are only set in responses.  Brief description
  * of the remaining fields:
- *     ID      Identifier to match responses with queries
- *     QR      Query (0) or response (1)
- *     Opcode  For our purposes, always QUERY
- *     RD      Recursion desired
- *     Z       Reserved (zero)
- *     QDCOUNT Number of queries
- *     ANCOUNT Number of answers
- *     NSCOUNT Number of name server records
- *     ARCOUNT Number of additional records
+ *      ID      Identifier to match responses with queries
+ *      QR      Query (0) or response (1)
+ *      Opcode  For our purposes, always QUERY
+ *      RD      Recursion desired
+ *      Z       Reserved (zero)
+ *      QDCOUNT Number of queries
+ *      ANCOUNT Number of answers
+ *      NSCOUNT Number of name server records
+ *      ARCOUNT Number of additional records
  *
  * Question format, from RFC 1035:
  *                                  1  1  1  1  1  1
@@ -77,7 +77,7 @@
  */
 
 int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
-                int rd, unsigned char **buf, int *buflen)
+                 int rd, unsigned char **buf, int *buflen)
 {
   int len;
   unsigned char *q;
@@ -89,7 +89,7 @@ int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
   for (p = name; *p; p++)
     {
       if (*p == '\\' && *(p + 1) != 0)
-       p++;
+        p++;
       len++;
     }
   /* If there are n periods in the name, there are n + 1 labels, and
@@ -121,31 +121,31 @@ int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
   while (*name)
     {
       if (*name == '.')
-       return ARES_EBADNAME;
+        return ARES_EBADNAME;
 
       /* Count the number of bytes in this label. */
       len = 0;
       for (p = name; *p && *p != '.'; p++)
-       {
-         if (*p == '\\' && *(p + 1) != 0)
-           p++;
-         len++;
-       }
+        {
+          if (*p == '\\' && *(p + 1) != 0)
+            p++;
+          len++;
+        }
       if (len > MAXLABEL)
-       return ARES_EBADNAME;
+        return ARES_EBADNAME;
 
       /* Encode the length and copy the data. */
       *q++ = len;
       for (p = name; *p && *p != '.'; p++)
-       {
-         if (*p == '\\' && *(p + 1) != 0)
-           p++;
-         *q++ = *p;
-       }
+        {
+          if (*p == '\\' && *(p + 1) != 0)
+            p++;
+          *q++ = *p;
+        }
 
       /* Go to the next label and repeat, unless we hit the end. */
       if (!*p)
-       break;
+        break;
       name = p + 1;
     }
 
index 3e55d87..2961687 100644 (file)
@@ -33,7 +33,7 @@
 #include "ares_private.h"
 
 int ares_parse_a_reply(const unsigned char *abuf, int alen,
-                      struct hostent **host)
+                       struct hostent **host)
 {
   unsigned int qdcount, ancount;
   int status, i, rr_type, rr_class, rr_len, naddrs;
@@ -92,49 +92,49 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
       /* Decode the RR up to the data field. */
       status = ares_expand_name(aptr, abuf, alen, &rr_name, &len);
       if (status != ARES_SUCCESS)
-       break;
+        break;
       aptr += len;
       if (aptr + RRFIXEDSZ > abuf + alen)
-       {
-         status = ARES_EBADRESP;
-         break;
-       }
+        {
+          status = ARES_EBADRESP;
+          break;
+        }
       rr_type = DNS_RR_TYPE(aptr);
       rr_class = DNS_RR_CLASS(aptr);
       rr_len = DNS_RR_LEN(aptr);
       aptr += RRFIXEDSZ;
 
       if (rr_class == C_IN && rr_type == T_A
-         && rr_len == sizeof(struct in_addr)
-         && strcasecmp(rr_name, hostname) == 0)
-       {
-         memcpy(&addrs[naddrs], aptr, sizeof(struct in_addr));
-         naddrs++;
-         status = ARES_SUCCESS;
-       }
+          && rr_len == sizeof(struct in_addr)
+          && strcasecmp(rr_name, hostname) == 0)
+        {
+          memcpy(&addrs[naddrs], aptr, sizeof(struct in_addr));
+          naddrs++;
+          status = ARES_SUCCESS;
+        }
 
       if (rr_class == C_IN && rr_type == T_CNAME)
-       {
-         /* Record the RR name as an alias. */
-         aliases[naliases] = rr_name;
-         naliases++;
+        {
+          /* Record the RR name as an alias. */
+          aliases[naliases] = rr_name;
+          naliases++;
 
-         /* Decode the RR data and replace the hostname with it. */
-         status = ares_expand_name(aptr, abuf, alen, &rr_data, &len);
-         if (status != ARES_SUCCESS)
-           break;
-         free(hostname);
-         hostname = rr_data;
-       }
+          /* Decode the RR data and replace the hostname with it. */
+          status = ares_expand_name(aptr, abuf, alen, &rr_data, &len);
+          if (status != ARES_SUCCESS)
+            break;
+          free(hostname);
+          hostname = rr_data;
+        }
       else
-       free(rr_name);
+        free(rr_name);
 
       aptr += rr_len;
       if (aptr > abuf + alen)
-       {
-         status = ARES_EBADRESP;
-         break;
-       }
+        {
+          status = ARES_EBADRESP;
+          break;
+        }
     }
 
   if (status == ARES_SUCCESS && naddrs == 0)
@@ -145,23 +145,23 @@ int ares_parse_a_reply(const unsigned char *abuf, int alen,
       aliases[naliases] = NULL;
       hostent = malloc(sizeof(struct hostent));
       if (hostent)
-       {
-         hostent->h_addr_list = malloc((naddrs + 1) * sizeof(char *));
-         if (hostent->h_addr_list)
-           {
-             /* Fill in the hostent and return successfully. */
-             hostent->h_name = hostname;
-             hostent->h_aliases = aliases;
-             hostent->h_addrtype = AF_INET;
-             hostent->h_length = sizeof(struct in_addr);
-             for (i = 0; i < naddrs; i++)
-               hostent->h_addr_list[i] = (char *) &addrs[i];
-             hostent->h_addr_list[naddrs] = NULL;
-             *host = hostent;
-             return ARES_SUCCESS;
-           }
-         free(hostent);
-       }
+        {
+          hostent->h_addr_list = malloc((naddrs + 1) * sizeof(char *));
+          if (hostent->h_addr_list)
+            {
+              /* Fill in the hostent and return successfully. */
+              hostent->h_name = hostname;
+              hostent->h_aliases = aliases;
+              hostent->h_addrtype = AF_INET;
+              hostent->h_length = sizeof(struct in_addr);
+              for (i = 0; i < naddrs; i++)
+                hostent->h_addr_list[i] = (char *) &addrs[i];
+              hostent->h_addr_list[naddrs] = NULL;
+              *host = hostent;
+              return ARES_SUCCESS;
+            }
+          free(hostent);
+        }
       status = ARES_ENOMEM;
     }
   for (i = 0; i < naliases; i++)
index 888b029..20df411 100644 (file)
@@ -32,7 +32,7 @@
 #include "ares_private.h"
 
 int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
-                        int addrlen, int family, struct hostent **host)
+                         int addrlen, int family, struct hostent **host)
 {
   unsigned int qdcount, ancount;
   int status, i, rr_type, rr_class, rr_len;
@@ -73,47 +73,47 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
       /* Decode the RR up to the data field. */
       status = ares_expand_name(aptr, abuf, alen, &rr_name, &len);
       if (status != ARES_SUCCESS)
-       break;
+        break;
       aptr += len;
       if (aptr + RRFIXEDSZ > abuf + alen)
-       {
-         status = ARES_EBADRESP;
-         break;
-       }
+        {
+          status = ARES_EBADRESP;
+          break;
+        }
       rr_type = DNS_RR_TYPE(aptr);
       rr_class = DNS_RR_CLASS(aptr);
       rr_len = DNS_RR_LEN(aptr);
       aptr += RRFIXEDSZ;
 
       if (rr_class == C_IN && rr_type == T_PTR
-         && strcasecmp(rr_name, ptrname) == 0)
-       {
-         /* Decode the RR data and set hostname to it. */
-         status = ares_expand_name(aptr, abuf, alen, &rr_data, &len);
-         if (status != ARES_SUCCESS)
-           break;
-         if (hostname)
-           free(hostname);
-         hostname = rr_data;
-       }
+          && strcasecmp(rr_name, ptrname) == 0)
+        {
+          /* Decode the RR data and set hostname to it. */
+          status = ares_expand_name(aptr, abuf, alen, &rr_data, &len);
+          if (status != ARES_SUCCESS)
+            break;
+          if (hostname)
+            free(hostname);
+          hostname = rr_data;
+        }
 
       if (rr_class == C_IN && rr_type == T_CNAME)
-       {
-         /* Decode the RR data and replace ptrname with it. */
-         status = ares_expand_name(aptr, abuf, alen, &rr_data, &len);
-         if (status != ARES_SUCCESS)
-           break;
-         free(ptrname);
-         ptrname = rr_data;
-       }
+        {
+          /* Decode the RR data and replace ptrname with it. */
+          status = ares_expand_name(aptr, abuf, alen, &rr_data, &len);
+          if (status != ARES_SUCCESS)
+            break;
+          free(ptrname);
+          ptrname = rr_data;
+        }
 
       free(rr_name);
       aptr += rr_len;
       if (aptr > abuf + alen)
-       {
-         status = ARES_EBADRESP;
-         break;
-       }
+        {
+          status = ARES_EBADRESP;
+          break;
+        }
     }
 
   if (status == ARES_SUCCESS && !hostname)
@@ -123,33 +123,33 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
       /* We got our answer.  Allocate memory to build the host entry. */
       hostent = malloc(sizeof(struct hostent));
       if (hostent)
-       {
-         hostent->h_addr_list = malloc(2 * sizeof(char *));
-         if (hostent->h_addr_list)
-           {
-             hostent->h_addr_list[0] = malloc(addrlen);
-             if (hostent->h_addr_list[0])
-               {
-                 hostent->h_aliases = malloc(sizeof (char *));
-                 if (hostent->h_aliases)
-                   {
-                     /* Fill in the hostent and return successfully. */
-                     hostent->h_name = hostname;
-                     hostent->h_aliases[0] = NULL;
-                     hostent->h_addrtype = family;
-                     hostent->h_length = addrlen;
-                     memcpy(hostent->h_addr_list[0], addr, addrlen);
-                     hostent->h_addr_list[1] = NULL;
-                     *host = hostent;
-                     free(ptrname);
-                     return ARES_SUCCESS;
-                   }
-                 free(hostent->h_addr_list[0]);
-               }
-             free(hostent->h_addr_list);
-           }
-         free(hostent);
-       }
+        {
+          hostent->h_addr_list = malloc(2 * sizeof(char *));
+          if (hostent->h_addr_list)
+            {
+              hostent->h_addr_list[0] = malloc(addrlen);
+              if (hostent->h_addr_list[0])
+                {
+                  hostent->h_aliases = malloc(sizeof (char *));
+                  if (hostent->h_aliases)
+                    {
+                      /* Fill in the hostent and return successfully. */
+                      hostent->h_name = hostname;
+                      hostent->h_aliases[0] = NULL;
+                      hostent->h_addrtype = family;
+                      hostent->h_length = addrlen;
+                      memcpy(hostent->h_addr_list[0], addr, addrlen);
+                      hostent->h_addr_list[1] = NULL;
+                      *host = hostent;
+                      free(ptrname);
+                      return ARES_SUCCESS;
+                    }
+                  free(hostent->h_addr_list[0]);
+                }
+              free(hostent->h_addr_list);
+            }
+          free(hostent);
+        }
       status = ARES_ENOMEM;
     }
   if (hostname)
index 06f8768..47ec402 100644 (file)
 #define writev(s,v,c)     writev_s(s,v,c)
 #endif
 
-#define        DEFAULT_TIMEOUT         5
-#define DEFAULT_TRIES          4
+#define DEFAULT_TIMEOUT         5
+#define DEFAULT_TRIES           4
 #ifndef INADDR_NONE
-#define        INADDR_NONE 0xffffffff
+#define INADDR_NONE 0xffffffff
 #endif
 
 #if defined(WIN32) && !defined(WATT32)
 #elif defined(NETWARE)
 
 #define PATH_RESOLV_CONF "sys:/etc/resolv.cfg"
-#define PATH_HOSTS             "sys:/etc/hosts"
+#define PATH_HOSTS              "sys:/etc/hosts"
 
 #else
 
-#define PATH_RESOLV_CONF       "/etc/resolv.conf"
+#define PATH_RESOLV_CONF        "/etc/resolv.conf"
 #ifdef ETC_INET
-#define PATH_HOSTS             "/etc/inet/hosts"
+#define PATH_HOSTS              "/etc/inet/hosts"
 #else
-#define PATH_HOSTS             "/etc/hosts"
+#define PATH_HOSTS              "/etc/hosts"
 #endif
 
 #endif
index 19fe082..887149e 100644 (file)
 #endif
 
 static void write_tcp_data(ares_channel channel, fd_set *write_fds,
-                          time_t now);
+                           time_t now);
 static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now);
 static void read_udp_packets(ares_channel channel, fd_set *read_fds,
-                            time_t now);
+                             time_t now);
 static void process_timeouts(ares_channel channel, time_t now);
 static void process_answer(ares_channel channel, unsigned char *abuf,
-                          int alen, int whichserver, int tcp, int now);
+                           int alen, int whichserver, int tcp, int now);
 static void handle_error(ares_channel channel, int whichserver, time_t now);
 static struct query *next_server(ares_channel channel, struct query *query, time_t now);
 static int open_tcp_socket(ares_channel channel, struct server_state *server);
 static int open_udp_socket(ares_channel channel, struct server_state *server);
 static int same_questions(const unsigned char *qbuf, int qlen,
-                         const unsigned char *abuf, int alen);
+                          const unsigned char *abuf, int alen);
 static struct query *end_query(ares_channel channel, struct query *query, int status,
-                     unsigned char *abuf, int alen);
+                      unsigned char *abuf, int alen);
 
 /* Something interesting happened on the wire, or there was a timeout.
  * See what's up and respond accordingly.
@@ -97,81 +97,81 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now)
       /* Make sure server has data to send and is selected in write_fds. */
       server = &channel->servers[i];
       if (!server->qhead || server->tcp_socket == ARES_SOCKET_BAD
-         || !FD_ISSET(server->tcp_socket, write_fds))
-       continue;
+          || !FD_ISSET(server->tcp_socket, write_fds))
+        continue;
 
       /* Count the number of send queue items. */
       n = 0;
       for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
-       n++;
+        n++;
 
       /* Allocate iovecs so we can send all our data at once. */
       vec = malloc(n * sizeof(struct iovec));
       if (vec)
-       {
-         /* Fill in the iovecs and send. */
-         n = 0;
-         for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
-           {
-             vec[n].iov_base = (char *) sendreq->data;
-             vec[n].iov_len = sendreq->len;
-             n++;
-           }
-         wcount = writev(server->tcp_socket, vec, n);
-         free(vec);
-         if (wcount < 0)
-           {
-             handle_error(channel, i, now);
-             continue;
-           }
-
-         /* Advance the send queue by as many bytes as we sent. */
-         while (wcount)
-           {
-             sendreq = server->qhead;
-             if ((size_t)wcount >= sendreq->len)
-               {
-                 wcount -= sendreq->len;
-                 server->qhead = sendreq->next;
-                 if (server->qhead == NULL)
-                   server->qtail = NULL;
-                 free(sendreq);
-               }
-             else
-               {
-                 sendreq->data += wcount;
-                 sendreq->len -= wcount;
-                 break;
-               }
-           }
-       }
+        {
+          /* Fill in the iovecs and send. */
+          n = 0;
+          for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
+            {
+              vec[n].iov_base = (char *) sendreq->data;
+              vec[n].iov_len = sendreq->len;
+              n++;
+            }
+          wcount = writev(server->tcp_socket, vec, n);
+          free(vec);
+          if (wcount < 0)
+            {
+              handle_error(channel, i, now);
+              continue;
+            }
+
+          /* Advance the send queue by as many bytes as we sent. */
+          while (wcount)
+            {
+              sendreq = server->qhead;
+              if ((size_t)wcount >= sendreq->len)
+                {
+                  wcount -= sendreq->len;
+                  server->qhead = sendreq->next;
+                  if (server->qhead == NULL)
+                    server->qtail = NULL;
+                  free(sendreq);
+                }
+              else
+                {
+                  sendreq->data += wcount;
+                  sendreq->len -= wcount;
+                  break;
+                }
+            }
+        }
       else
-       {
-         /* Can't allocate iovecs; just send the first request. */
-         sendreq = server->qhead;
+        {
+          /* Can't allocate iovecs; just send the first request. */
+          sendreq = server->qhead;
 
           scount = send(server->tcp_socket, sendreq->data, sendreq->len, 0);
 
-         if (scount < 0)
-           {
-             handle_error(channel, i, now);
-             continue;
-           }
-
-         /* Advance the send queue by as many bytes as we sent. */
-         if ((size_t)scount == sendreq->len)
-           {
-             server->qhead = sendreq->next;
-             if (server->qhead == NULL)
-               server->qtail = NULL;
-             free(sendreq);
-           }
-         else
-           {
-             sendreq->data += scount;
-             sendreq->len -= scount;
-           }
-       }
+          if (scount < 0)
+            {
+              handle_error(channel, i, now);
+              continue;
+            }
+
+          /* Advance the send queue by as many bytes as we sent. */
+          if ((size_t)scount == sendreq->len)
+            {
+              server->qhead = sendreq->next;
+              if (server->qhead == NULL)
+                server->qtail = NULL;
+              free(sendreq);
+            }
+          else
+            {
+              sendreq->data += scount;
+              sendreq->len -= scount;
+            }
+        }
     }
 }
 
@@ -190,68 +190,68 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now)
       server = &channel->servers[i];
       if (server->tcp_socket == ARES_SOCKET_BAD ||
           !FD_ISSET(server->tcp_socket, read_fds))
-       continue;
+        continue;
 
       if (server->tcp_lenbuf_pos != 2)
-       {
-         /* We haven't yet read a length word, so read that (or
-          * what's left to read of it).
-          */
+        {
+          /* We haven't yet read a length word, so read that (or
+           * what's left to read of it).
+           */
           count = recv(server->tcp_socket,
                        server->tcp_lenbuf + server->tcp_buffer_pos,
                        2 - server->tcp_buffer_pos, 0);
-         if (count <= 0)
-           {
-             handle_error(channel, i, now);
-             continue;
-           }
-
-         server->tcp_lenbuf_pos += count;
-         if (server->tcp_lenbuf_pos == 2)
-           {
-             /* We finished reading the length word.  Decode the
+          if (count <= 0)
+            {
+              handle_error(channel, i, now);
+              continue;
+            }
+
+          server->tcp_lenbuf_pos += count;
+          if (server->tcp_lenbuf_pos == 2)
+            {
+              /* We finished reading the length word.  Decode the
                * length and allocate a buffer for the data.
-              */
-             server->tcp_length = server->tcp_lenbuf[0] << 8
-               | server->tcp_lenbuf[1];
-             server->tcp_buffer = malloc(server->tcp_length);
-             if (!server->tcp_buffer)
-               handle_error(channel, i, now);
-             server->tcp_buffer_pos = 0;
-           }
-       }
+               */
+              server->tcp_length = server->tcp_lenbuf[0] << 8
+                | server->tcp_lenbuf[1];
+              server->tcp_buffer = malloc(server->tcp_length);
+              if (!server->tcp_buffer)
+                handle_error(channel, i, now);
+              server->tcp_buffer_pos = 0;
+            }
+        }
       else
-       {
-         /* Read data into the allocated buffer. */
-                 count = recv(server->tcp_socket,
-                      server->tcp_buffer + server->tcp_buffer_pos,
-                      server->tcp_length - server->tcp_buffer_pos, 0);
-         if (count <= 0)
-           {
-             handle_error(channel, i, now);
-             continue;
-           }
-
-         server->tcp_buffer_pos += count;
-         if (server->tcp_buffer_pos == server->tcp_length)
-           {
-             /* We finished reading this answer; process it and
+        {
+          /* Read data into the allocated buffer. */
+          count = recv(server->tcp_socket,
+                       server->tcp_buffer + server->tcp_buffer_pos,
+                       server->tcp_length - server->tcp_buffer_pos, 0);
+          if (count <= 0)
+            {
+              handle_error(channel, i, now);
+              continue;
+            }
+
+          server->tcp_buffer_pos += count;
+          if (server->tcp_buffer_pos == server->tcp_length)
+            {
+              /* We finished reading this answer; process it and
                * prepare to read another length word.
-              */
-             process_answer(channel, server->tcp_buffer, server->tcp_length,
-                            i, 1, now);
+               */
+              process_answer(channel, server->tcp_buffer, server->tcp_length,
+                             i, 1, now);
           if (server->tcp_buffer)
-                       free(server->tcp_buffer);
-             server->tcp_buffer = NULL;
-             server->tcp_lenbuf_pos = 0;
-           }
-       }
+                        free(server->tcp_buffer);
+              server->tcp_buffer = NULL;
+              server->tcp_lenbuf_pos = 0;
+            }
+        }
     }
 }
 
 /* If any UDP sockets select true for reading, process them. */
 static void read_udp_packets(ares_channel channel, fd_set *read_fds,
-                            time_t now)
+                             time_t now)
 {
   struct server_state *server;
   int i, count;
@@ -264,11 +264,11 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
 
       if (server->udp_socket == ARES_SOCKET_BAD ||
           !FD_ISSET(server->udp_socket, read_fds))
-       continue;
+        continue;
 
       count = recv(server->udp_socket, buf, sizeof(buf), 0);
       if (count <= 0)
-       handle_error(channel, i, now);
+        handle_error(channel, i, now);
 
       process_answer(channel, buf, count, i, 0, now);
     }
@@ -283,16 +283,16 @@ static void process_timeouts(ares_channel channel, time_t now)
     {
       next = query->next;
       if (query->timeout != 0 && now >= query->timeout)
-       {
-         query->error_status = ARES_ETIMEOUT;
-         next = next_server(channel, query, now);
-       }
+        {
+          query->error_status = ARES_ETIMEOUT;
+          next = next_server(channel, query, now);
+        }
     }
 }
 
 /* Handle an answer from a server. */
 static void process_answer(ares_channel channel, unsigned char *abuf,
-                          int alen, int whichserver, int tcp, int now)
+                           int alen, int whichserver, int tcp, int now)
 {
   int id, tc, rcode;
   struct query *query;
@@ -311,7 +311,7 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
   for (query = channel->queries; query; query = query->next)
     {
       if (query->qid == id)
-       break;
+        break;
     }
   if (!query)
     return;
@@ -323,10 +323,10 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
   if ((tc || alen > PACKETSZ) && !tcp && !(channel->flags & ARES_FLAG_IGNTC))
     {
       if (!query->using_tcp)
-       {
-         query->using_tcp = 1;
-         ares__send_query(channel, query, now);
-       }
+        {
+          query->using_tcp = 1;
+          ares__send_query(channel, query, now);
+        }
       return;
     }
 
@@ -342,18 +342,18 @@ static void process_answer(ares_channel channel, unsigned char *abuf,
   if (!(channel->flags & ARES_FLAG_NOCHECKRESP))
     {
       if (rcode == SERVFAIL || rcode == NOTIMP || rcode == REFUSED)
-       {
-         query->skip_server[whichserver] = 1;
-         if (query->server == whichserver)
-           next_server(channel, query, now);
-         return;
-       }
+        {
+          query->skip_server[whichserver] = 1;
+          if (query->server == whichserver)
+            next_server(channel, query, now);
+          return;
+        }
       if (!same_questions(query->qbuf, query->qlen, abuf, alen))
-       {
-         if (query->server == whichserver)
-           next_server(channel, query, now);
-         return;
-       }
+        {
+          if (query->server == whichserver)
+            next_server(channel, query, now);
+          return;
+        }
     }
 
   end_query(channel, query, ARES_SUCCESS, abuf, alen);
@@ -374,10 +374,10 @@ static void handle_error(ares_channel channel, int whichserver, time_t now)
     {
       next = query->next;
       if (query->server == whichserver)
-       {
-         query->skip_server[whichserver] = 1;
-         next = next_server(channel, query, now);
-       }
+        {
+          query->skip_server[whichserver] = 1;
+          next = next_server(channel, query, now);
+        }
     }
 }
 
@@ -388,18 +388,18 @@ static struct query *next_server(ares_channel channel, struct query *query, time
   for (; query->try < channel->tries; query->try++)
     {
       for (; query->server < channel->nservers; query->server++)
-       {
-         if (!query->skip_server[query->server])
-           {
-             ares__send_query(channel, query, now);
-             return (query->next);
-           }
-       }
+        {
+          if (!query->skip_server[query->server])
+            {
+              ares__send_query(channel, query, now);
+              return (query->next);
+            }
+        }
       query->server = 0;
 
       /* Only one try if we're using TCP. */
       if (query->using_tcp)
-       break;
+        break;
     }
   return end_query(channel, query, query->error_status, NULL, 0);
 }
@@ -416,50 +416,50 @@ void ares__send_query(ares_channel channel, struct query *query, time_t now)
        * a send request.
        */
       if (server->tcp_socket == ARES_SOCKET_BAD)
-       {
-         if (open_tcp_socket(channel, server) == -1)
-           {
-             query->skip_server[query->server] = 1;
-             next_server(channel, query, now);
-             return;
-           }
-       }
+        {
+          if (open_tcp_socket(channel, server) == -1)
+            {
+              query->skip_server[query->server] = 1;
+              next_server(channel, query, now);
+              return;
+            }
+        }
       sendreq = calloc(sizeof(struct send_request), 1);
       if (!sendreq)
         {
-       end_query(channel, query, ARES_ENOMEM, NULL, 0);
+        end_query(channel, query, ARES_ENOMEM, NULL, 0);
           return;
         }
       sendreq->data = query->tcpbuf;
       sendreq->len = query->tcplen;
       sendreq->next = NULL;
       if (server->qtail)
-       server->qtail->next = sendreq;
+        server->qtail->next = sendreq;
       else
-       server->qhead = sendreq;
+        server->qhead = sendreq;
       server->qtail = sendreq;
       query->timeout = 0;
     }
   else
     {
       if (server->udp_socket == ARES_SOCKET_BAD)
-       {
-         if (open_udp_socket(channel, server) == -1)
-           {
-             query->skip_server[query->server] = 1;
-             next_server(channel, query, now);
-             return;
-           }
-       }
+        {
+          if (open_udp_socket(channel, server) == -1)
+            {
+              query->skip_server[query->server] = 1;
+              next_server(channel, query, now);
+              return;
+            }
+        }
       if (send(server->udp_socket, query->qbuf, query->qlen, 0) == -1)
-       {
-         query->skip_server[query->server] = 1;
-         next_server(channel, query, now);
-         return;
-       }
+        {
+          query->skip_server[query->server] = 1;
+          next_server(channel, query, now);
+          return;
+        }
       query->timeout = now
-         + ((query->try == 0) ? channel->timeout
-            : channel->timeout << query->try / channel->nservers);
+          + ((query->try == 0) ? channel->timeout
+             : channel->timeout << query->try / channel->nservers);
     }
 }
 
@@ -540,7 +540,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
 }
 
 static int same_questions(const unsigned char *qbuf, int qlen,
-                         const unsigned char *abuf, int alen)
+                          const unsigned char *abuf, int alen)
 {
   struct {
     const unsigned char *p;
@@ -567,14 +567,14 @@ static int same_questions(const unsigned char *qbuf, int qlen,
     {
       /* Decode the question in the query. */
       if (ares_expand_name(q.p, qbuf, qlen, &q.name, &q.namelen)
-         != ARES_SUCCESS)
-       return 0;
+          != ARES_SUCCESS)
+        return 0;
       q.p += q.namelen;
       if (q.p + QFIXEDSZ > qbuf + qlen)
-       {
-         free(q.name);
-         return 0;
-       }
+        {
+          free(q.name);
+          return 0;
+        }
       q.type = DNS_QUESTION_TYPE(q.p);
       q.dnsclass = DNS_QUESTION_CLASS(q.p);
       q.p += QFIXEDSZ;
@@ -582,44 +582,44 @@ static int same_questions(const unsigned char *qbuf, int qlen,
       /* Search for this question in the answer. */
       a.p = abuf + HFIXEDSZ;
       for (j = 0; j < a.qdcount; j++)
-       {
-         /* Decode the question in the answer. */
-         if (ares_expand_name(a.p, abuf, alen, &a.name, &a.namelen)
-             != ARES_SUCCESS)
-           {
-             free(q.name);
-             return 0;
-           }
-         a.p += a.namelen;
-         if (a.p + QFIXEDSZ > abuf + alen)
-           {
-             free(q.name);
-             free(a.name);
-             return 0;
-           }
-         a.type = DNS_QUESTION_TYPE(a.p);
-         a.dnsclass = DNS_QUESTION_CLASS(a.p);
-         a.p += QFIXEDSZ;
-
-         /* Compare the decoded questions. */
-         if (strcasecmp(q.name, a.name) == 0 && q.type == a.type
-             && q.dnsclass == a.dnsclass)
-           {
-             free(a.name);
-             break;
-           }
-         free(a.name);
-       }
+        {
+          /* Decode the question in the answer. */
+          if (ares_expand_name(a.p, abuf, alen, &a.name, &a.namelen)
+              != ARES_SUCCESS)
+            {
+              free(q.name);
+              return 0;
+            }
+          a.p += a.namelen;
+          if (a.p + QFIXEDSZ > abuf + alen)
+            {
+              free(q.name);
+              free(a.name);
+              return 0;
+            }
+          a.type = DNS_QUESTION_TYPE(a.p);
+          a.dnsclass = DNS_QUESTION_CLASS(a.p);
+          a.p += QFIXEDSZ;
+
+          /* Compare the decoded questions. */
+          if (strcasecmp(q.name, a.name) == 0 && q.type == a.type
+              && q.dnsclass == a.dnsclass)
+            {
+              free(a.name);
+              break;
+            }
+          free(a.name);
+        }
 
       free(q.name);
       if (j == a.qdcount)
-       return 0;
+        return 0;
     }
   return 1;
 }
 
 static struct query *end_query (ares_channel channel, struct query *query, int status,
-                     unsigned char *abuf, int alen)
+                      unsigned char *abuf, int alen)
 {
   struct query **q, *next;
   int i;
@@ -628,7 +628,7 @@ static struct query *end_query (ares_channel channel, struct query *query, int s
   for (q = &channel->queries; *q; q = &(*q)->next)
     {
       if (*q == query)
-       break;
+        break;
     }
   *q = query->next;
   if (*q)
@@ -645,7 +645,7 @@ static struct query *end_query (ares_channel channel, struct query *query, int s
   if (!channel->queries && !(channel->flags & ARES_FLAG_STAYOPEN))
     {
       for (i = 0; i < channel->nservers; i++)
-       ares__close_sockets(&channel->servers[i]);
+        ares__close_sockets(&channel->servers[i]);
     }
   return (next);
 }
index 2b83265..b39dc6d 100644 (file)
@@ -36,7 +36,7 @@ struct qquery {
 static void qcallback(void *arg, int status, unsigned char *abuf, int alen);
 
 void ares_query(ares_channel channel, const char *name, int dnsclass,
-               int type, ares_callback callback, void *arg)
+                int type, ares_callback callback, void *arg)
 {
   struct qquery *qquery;
   unsigned char *qbuf;
@@ -45,7 +45,7 @@ void ares_query(ares_channel channel, const char *name, int dnsclass,
   /* Compose the query. */
   rd = !(channel->flags & ARES_FLAG_NORECURSE);
   status = ares_mkquery(name, dnsclass, type, channel->next_id, rd, &qbuf,
-                       &qlen);
+                        &qlen);
   channel->next_id++;
   if (status != ARES_SUCCESS)
     {
@@ -85,26 +85,26 @@ static void qcallback(void *arg, int status, unsigned char *abuf, int alen)
 
       /* Convert errors. */
       switch (rcode)
-       {
-       case NOERROR:
-         status = (ancount > 0) ? ARES_SUCCESS : ARES_ENODATA;
-         break;
-       case FORMERR:
-         status = ARES_EFORMERR;
-         break;
-       case SERVFAIL:
-         status = ARES_ESERVFAIL;
-         break;
-       case NXDOMAIN:
-         status = ARES_ENOTFOUND;
-         break;
-       case NOTIMP:
-         status = ARES_ENOTIMP;
-         break;
-       case REFUSED:
-         status = ARES_EREFUSED;
-         break;
-       }
+        {
+        case NOERROR:
+          status = (ancount > 0) ? ARES_SUCCESS : ARES_ENODATA;
+          break;
+        case FORMERR:
+          status = ARES_EFORMERR;
+          break;
+        case SERVFAIL:
+          status = ARES_ESERVFAIL;
+          break;
+        case NXDOMAIN:
+          status = ARES_ENOTFOUND;
+          break;
+        case NOTIMP:
+          status = ARES_ENOTIMP;
+          break;
+        case REFUSED:
+          status = ARES_EREFUSED;
+          break;
+        }
       qquery->callback(qquery->arg, status, abuf, alen);
     }
   free(qquery);
index 37826ee..dc416c0 100644 (file)
 struct search_query {
   /* Arguments passed to ares_search */
   ares_channel channel;
-  char *name;                  /* copied into an allocated buffer */
+  char *name;                   /* copied into an allocated buffer */
   int dnsclass;
   int type;
   ares_callback callback;
   void *arg;
 
-  int status_as_is;            /* error status from trying as-is */
-  int next_domain;             /* next search domain to try */
-  int trying_as_is;            /* current query is for name as-is */
+  int status_as_is;             /* error status from trying as-is */
+  int next_domain;              /* next search domain to try */
+  int trying_as_is;             /* current query is for name as-is */
 };
 
 static void search_callback(void *arg, int status, unsigned char *abuf,
-                           int alen);
+                            int alen);
 static void end_squery(struct search_query *squery, int status,
-                      unsigned char *abuf, int alen);
+                       unsigned char *abuf, int alen);
 static int cat_domain(const char *name, const char *domain, char **s);
 static int single_domain(ares_channel channel, const char *name, char **s);
 
 void ares_search(ares_channel channel, const char *name, int dnsclass,
-                int type, ares_callback callback, void *arg)
+                 int type, ares_callback callback, void *arg)
 {
   struct search_query *squery;
   char *s;
@@ -99,7 +99,7 @@ void ares_search(ares_channel channel, const char *name, int dnsclass,
   for (p = name; *p; p++)
     {
       if (*p == '.')
-       ndots++;
+        ndots++;
     }
 
   /* If ndots is at least the channel ndots threshold (usually 1),
@@ -120,22 +120,22 @@ void ares_search(ares_channel channel, const char *name, int dnsclass,
       squery->trying_as_is = 0;
       status = cat_domain(name, channel->domains[0], &s);
       if (status == ARES_SUCCESS)
-       {
-         ares_query(channel, s, dnsclass, type, search_callback, squery);
-         free(s);
-       }
+        {
+          ares_query(channel, s, dnsclass, type, search_callback, squery);
+          free(s);
+        }
       else
       {
         /* failed, free the malloc()ed memory */
         free(squery->name);
         free(squery);
-       callback(arg, status, NULL, 0);
+        callback(arg, status, NULL, 0);
       }
     }
 }
 
 static void search_callback(void *arg, int status, unsigned char *abuf,
-                           int alen)
+                            int alen)
 {
   struct search_query *squery = (struct search_query *) arg;
   ares_channel channel = squery->channel;
@@ -149,37 +149,37 @@ static void search_callback(void *arg, int status, unsigned char *abuf,
     {
       /* Save the status if we were trying as-is. */
       if (squery->trying_as_is)
-       squery->status_as_is = status;
+        squery->status_as_is = status;
       if (squery->next_domain < channel->ndomains)
-       {
-         /* Try the next domain. */
-         status = cat_domain(squery->name,
-                             channel->domains[squery->next_domain], &s);
-         if (status != ARES_SUCCESS)
-           end_squery(squery, status, NULL, 0);
-         else
-           {
-             squery->trying_as_is = 0;
-             squery->next_domain++;
-             ares_query(channel, s, squery->dnsclass, squery->type,
-                        search_callback, squery);
-             free(s);
-           }
-       }
+        {
+          /* Try the next domain. */
+          status = cat_domain(squery->name,
+                              channel->domains[squery->next_domain], &s);
+          if (status != ARES_SUCCESS)
+            end_squery(squery, status, NULL, 0);
+          else
+            {
+              squery->trying_as_is = 0;
+              squery->next_domain++;
+              ares_query(channel, s, squery->dnsclass, squery->type,
+                         search_callback, squery);
+              free(s);
+            }
+        }
       else if (squery->status_as_is == -1)
-       {
-         /* Try the name as-is at the end. */
-         squery->trying_as_is = 1;
-         ares_query(channel, squery->name, squery->dnsclass, squery->type,
-                    search_callback, squery);
-       }
+        {
+          /* Try the name as-is at the end. */
+          squery->trying_as_is = 1;
+          ares_query(channel, squery->name, squery->dnsclass, squery->type,
+                     search_callback, squery);
+        }
       else
-       end_squery(squery, squery->status_as_is, NULL, 0);
+        end_squery(squery, squery->status_as_is, NULL, 0);
     }
 }
 
 static void end_squery(struct search_query *squery, int status,
-                      unsigned char *abuf, int alen)
+                       unsigned char *abuf, int alen)
 {
   squery->callback(squery->arg, status, abuf, alen);
   free(squery->name);
@@ -229,41 +229,41 @@ static int single_domain(ares_channel channel, const char *name, char **s)
       /* The name might be a host alias. */
       hostaliases = getenv("HOSTALIASES");
       if (hostaliases)
-       {
-         fp = fopen(hostaliases, "r");
-         if (fp)
-           {
-             while ((status = ares__read_line(fp, &line, &linesize))
-                    == ARES_SUCCESS)
-               {
-                 if (strncasecmp(line, name, len) != 0 ||
-                     !isspace((unsigned char)line[len]))
-                   continue;
-                 p = line + len;
-                 while (isspace((unsigned char)*p))
-                   p++;
-                 if (*p)
-                   {
-                     q = p + 1;
-                     while (*q && !isspace((unsigned char)*q))
-                       q++;
-                     *s = malloc(q - p + 1);
-                     if (*s)
-                       {
-                         memcpy(*s, p, q - p);
-                         (*s)[q - p] = 0;
-                       }
-                     free(line);
-                     fclose(fp);
-                     return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
-                   }
-               }
-             free(line);
-             fclose(fp);
-             if (status != ARES_SUCCESS)
-               return status;
-           }
-       }
+        {
+          fp = fopen(hostaliases, "r");
+          if (fp)
+            {
+              while ((status = ares__read_line(fp, &line, &linesize))
+                     == ARES_SUCCESS)
+                {
+                  if (strncasecmp(line, name, len) != 0 ||
+                      !isspace((unsigned char)line[len]))
+                    continue;
+                  p = line + len;
+                  while (isspace((unsigned char)*p))
+                    p++;
+                  if (*p)
+                    {
+                      q = p + 1;
+                      while (*q && !isspace((unsigned char)*q))
+                        q++;
+                      *s = malloc(q - p + 1);
+                      if (*s)
+                        {
+                          memcpy(*s, p, q - p);
+                          (*s)[q - p] = 0;
+                        }
+                      free(line);
+                      fclose(fp);
+                      return (*s) ? ARES_SUCCESS : ARES_ENOMEM;
+                    }
+                }
+              free(line);
+              fclose(fp);
+              if (status != ARES_SUCCESS)
+                return status;
+            }
+        }
     }
 
   if (channel->flags & ARES_FLAG_NOSEARCH || channel->ndomains == 0)
index 6f0a31d..99f3039 100644 (file)
@@ -31,7 +31,7 @@
 #include "ares_private.h"
 
 void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
-              ares_callback callback, void *arg)
+               ares_callback callback, void *arg)
 {
   struct query *query;
   int i;
index 775b0a9..c550218 100644 (file)
@@ -26,7 +26,7 @@
 #include "ares_private.h"
 
 struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
-                            struct timeval *tvbuf)
+                             struct timeval *tvbuf)
 {
   struct query *query;
   time_t now;
@@ -42,12 +42,12 @@ struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
   for (query = channel->queries; query; query = query->next)
     {
       if (query->timeout == 0)
-       continue;
+        continue;
       offset = query->timeout - now;
       if (offset < 0)
-       offset = 0;
+        offset = 0;
       if (min_offset == -1 || offset < min_offset)
-       min_offset = offset;
+        min_offset = offset;
     }
 
   /* If we found a minimum timeout and it's sooner than the one