Browse Source

removed tabs and trailing whitespace from source

darwin-pinnedpubkey
Daniel Stenberg 19 years ago
parent
commit
39af394a1c
  1. 344
      ares/adig.c
  2. 16
      ares/ahost.c
  3. 98
      ares/ares.h
  4. 116
      ares/ares__get_hostent.c
  5. 14
      ares/ares__read_line.c
  6. 94
      ares/ares_dns.h
  7. 100
      ares/ares_expand_name.c
  8. 24
      ares/ares_fds.c
  9. 80
      ares/ares_gethostbyaddr.c
  10. 116
      ares/ares_gethostbyname.c
  11. 176
      ares/ares_init.c
  12. 48
      ares/ares_mkquery.c
  13. 92
      ares/ares_parse_a_reply.c
  14. 110
      ares/ares_parse_ptr_reply.c
  15. 14
      ares/ares_private.h
  16. 432
      ares/ares_process.c
  17. 44
      ares/ares_query.c
  18. 146
      ares/ares_search.c
  19. 2
      ares/ares_send.c
  20. 8
      ares/ares_timeout.c
  21. 9
      curl-style.el
  22. 4
      docs/MANUAL
  23. 572
      docs/examples/curlx.c
  24. 396
      docs/examples/fopen.c
  25. 24
      docs/examples/multi-app.c
  26. 4
      include/curl/curl.h
  27. 6
      lib/amigaos.c
  28. 8
      lib/amigaos.h
  29. 70
      lib/config-mac.h
  30. 18
      lib/config-vms.h
  31. 6
      lib/connect.c
  32. 40
      lib/cookie.c
  33. 2
      lib/cookie.h
  34. 34
      lib/dict.c
  35. 2
      lib/file.c
  36. 30
      lib/formdata.c
  37. 46
      lib/ftp.c
  38. 14
      lib/getenv.c
  39. 4
      lib/hostares.c
  40. 4
      lib/hostasyn.c
  41. 4
      lib/hostip.c
  42. 4
      lib/hostip4.c
  43. 4
      lib/hostip6.c
  44. 14
      lib/hostsyn.c
  45. 4
      lib/hostthre.c
  46. 12
      lib/http.c
  47. 2
      lib/http_digest.c
  48. 6
      lib/inet_ntop.c
  49. 48
      lib/inet_pton.c
  50. 6
      lib/krb4.c
  51. 8
      lib/ldap.c
  52. 10
      lib/memory.h
  53. 98
      lib/netrc.c
  54. 2
      lib/progress.c
  55. 18
      lib/security.c
  56. 16
      lib/security.h
  57. 12
      lib/sendf.c
  58. 20
      lib/speedcheck.c
  59. 6
      lib/ssluse.c
  60. 2
      lib/strequal.c
  61. 52
      lib/telnet.c
  62. 10
      lib/transfer.h
  63. 70
      lib/url.c
  64. 52
      lib/urldata.h
  65. 39
      src/config-amigaos.h
  66. 12
      src/config-mac.h
  67. 10
      src/getpass.c
  68. 20
      src/homedir.c
  69. 148
      src/main.c
  70. 110
      src/urlglob.c

344
ares/adig.c

@ -37,7 +37,7 @@ @@ -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 { @@ -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[] = { @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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) @@ -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) @@ -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) @@ -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);
}

16
ares/ahost.c

@ -33,7 +33,7 @@ @@ -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) @@ -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) @@ -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) @@ -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);

98
ares/ares.h

@ -37,49 +37,49 @@ @@ -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; @@ -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);

116
ares/ares__get_hostent.c

@ -42,96 +42,96 @@ int ares__get_hostent(FILE *fp, struct hostent **host) @@ -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) @@ -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;
}

14
ares/ares__read_line.c

@ -38,26 +38,26 @@ int ares__read_line(FILE *fp, char **buf, int *bufsize) @@ -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;
}

94
ares/ares_dns.h

@ -18,64 +18,64 @@ @@ -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 */

100
ares/ares_expand_name.c

@ -28,7 +28,7 @@ @@ -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, @@ -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, @@ -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, @@ -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, @@ -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

24
ares/ares_fds.c