41
41
#define PACKETSZ 512
44
char *dnsquery(const char *domain, int qtype, unsigned int *ttl)
45
dnsquery (const char *domain, int qtype, unsigned int *ttl)
46
unsigned char answer[PACKETSZ], *answend, *pt;
49
unsigned int cttl, size, txtlen = 0;
55
logg("^res_init failed\n");
47
unsigned char answer[PACKETSZ], *answend, *pt;
50
unsigned int cttl, size, txtlen = 0;
57
logg ("^res_init failed\n");
59
logg("*Querying %s\n", domain);
61
logg ("*Querying %s\n", domain);
61
memset(answer, 0, PACKETSZ);
62
if((len = res_query(domain, C_IN, qtype, answer, PACKETSZ)) < 0 || len > PACKETSZ) {
63
memset (answer, 0, PACKETSZ);
64
if ((len = res_query (domain, C_IN, qtype, answer, PACKETSZ)) < 0
63
67
#ifdef FRESHCLAM_DNS_FIX
64
/* The DNS server in the SpeedTouch Alcatel 510 modem can't
65
* handle a TXT-query, but it can resolve an ANY-query to a
66
* TXT-record, so we try an ANY-query now. The thing we try
67
* to resolve normally only has a TXT-record anyway.
69
memset(answer, 0, PACKETSZ);
72
if((len = res_query(domain, C_IN, qtype, answer, PACKETSZ)) < 0) {
73
logg("%cCan't query %s\n", (qtype == T_TXT || qtype == T_ANY) ? '^' : '*', domain);
68
/* The DNS server in the SpeedTouch Alcatel 510 modem can't
69
* handle a TXT-query, but it can resolve an ANY-query to a
70
* TXT-record, so we try an ANY-query now. The thing we try
71
* to resolve normally only has a TXT-record anyway.
73
memset (answer, 0, PACKETSZ);
76
if ((len = res_query (domain, C_IN, qtype, answer, PACKETSZ)) < 0)
78
logg ("%cCan't query %s\n",
79
(qtype == T_TXT || qtype == T_ANY) ? '^' : '*', domain);
77
logg("%cCan't query %s\n", (qtype == T_TXT) ? '^' : '*', domain);
83
logg ("%cCan't query %s\n", (qtype == T_TXT) ? '^' : '*', domain);
81
if(qtype != T_TXT && qtype != T_ANY) {
87
if (qtype != T_TXT && qtype != T_ANY)
87
94
answend = answer + len;
88
pt = answer + sizeof(HEADER);
95
pt = answer + sizeof (HEADER);
90
if((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
91
logg("^dn_expand failed\n");
97
if ((len = dn_expand (answer, answend, pt, host, sizeof (host))) < 0)
99
logg ("^dn_expand failed\n");
97
logg("^Bad (too short) DNS reply\n");
103
logg("^Broken DNS reply.\n");
107
pt += INT16SZ; /* class */
104
if (pt > answend - 4)
106
logg ("^Bad (too short) DNS reply\n");
113
logg ("^Broken DNS reply.\n");
117
pt += INT16SZ; /* class */
109
do { /* recurse through CNAME rr's */
111
if((len = dn_expand(answer, answend, pt, host, sizeof(host))) < 0) {
112
logg("^second dn_expand failed\n");
116
if(pt > answend-10) {
117
logg("^Bad (too short) DNS reply\n");
121
pt += INT16SZ; /* class */
124
if(pt + size < answer || pt + size > answend) {
125
logg("^DNS rr overflow\n");
128
} while(type == T_CNAME);
131
logg("^Not a TXT record\n");
135
if(!size || (txtlen = *pt) >= size || !txtlen) {
136
logg("^Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size);
140
if(!(txt = (char *) malloc(txtlen + 1)))
143
memcpy(txt, pt+1, txtlen);
120
{ /* recurse through CNAME rr's */
122
if ((len = dn_expand (answer, answend, pt, host, sizeof (host))) < 0)
124
logg ("^second dn_expand failed\n");
128
if (pt > answend - 10)
130
logg ("^Bad (too short) DNS reply\n");
134
pt += INT16SZ; /* class */
137
if (pt + size < answer || pt + size > answend)
139
logg ("^DNS rr overflow\n");
143
while (type == T_CNAME);
147
logg ("^Not a TXT record\n");
151
if (!size || (txtlen = *pt) >= size || !txtlen)
153
logg ("^Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size);
157
if (!(txt = (char *) malloc (txtlen + 1)))
160
memcpy (txt, pt + 1, txtlen);
153
char *dnsquery(const char *domain, int qtype, unsigned int *ttl)
171
dnsquery (const char *domain, int qtype, unsigned int *ttl)
156
*ttl = 1; /* ttl of 1 combined with a NULL return distinguishes a failed lookup from DNS queries not being available */
174
*ttl = 1; /* ttl of 1 combined with a NULL return distinguishes a failed lookup from DNS queries not being available */