Browse files

removed tabs and trailing whitespace from source

  • Loading branch information...
1 parent 47bd7d7 commit 3e748f4b50224e43b916dda5de438c785bdcd49d @bagder bagder committed Oct 6, 2004
Showing with 1,037 additions and 1,037 deletions.
  1. +172 −172 adig.c
  2. +8 −8 ahost.c
  3. +49 −49 ares.h
  4. +58 −58 ares__get_hostent.c
  5. +7 −7 ares__read_line.c
  6. +47 −47 ares_dns.h
  7. +50 −50 ares_expand_name.c
  8. +12 −12 ares_fds.c
  9. +40 −40 ares_gethostbyaddr.c
  10. +58 −58 ares_gethostbyname.c
  11. +88 −88 ares_init.c
  12. +24 −24 ares_mkquery.c
  13. +46 −46 ares_parse_a_reply.c
  14. +55 −55 ares_parse_ptr_reply.c
  15. +7 −7 ares_private.h
  16. +216 −216 ares_process.c
  17. +22 −22 ares_query.c
  18. +73 −73 ares_search.c
  19. +1 −1 ares_send.c
  20. +4 −4 ares_timeout.c
View
344 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,88 +146,88 @@ 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;
options.nservers = 0;
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,44 +519,44 @@ 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:
/* The RR data is one or more length-counted character
* 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,14 +608,14 @@ 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)";
}
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);
}
View
16 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);
View
98 ares.h
@@ -37,49 +37,49 @@
#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);
View
116 ares__get_hostent.c
@@ -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;
}
View
14 ares__read_line.c
@@ -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;
}
View
94 ares_dns.h
@@ -18,64 +18,64 @@
#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 */
View
100 ares_expand_name.c
@@ -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
View
24 ares_fds.c
@@ -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;
}
View
80 ares_gethostbyaddr.c
@@ -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);
View
116 ares_gethostbyname.c
@@ -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;
}
View
176 ares_init.c
@@ -50,17 +50,17 @@
#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);
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,15 +232,15 @@ 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");
if (res_options)
{
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,21 +735,21 @@ 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);
return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
}
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;
View
48 ares_mkquery.c
@@ -47,15 +47,15 @@
*
* 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;
}
<