Browse code

w32 support

git-svn: trunk@2313

Tomasz Kojm authored on 2006/09/27 19:21:44
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Sep 27 12:20:38 CEST 2006 (tk)
2
+----------------------------------
3
+  * freshclam/dns.c: apply w32 support patch from Mark Pizzolato
4
+
1 5
 Wed Sep 27 09:32:40 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * sigtool/sigtool.c: properly handle .pdb files
... ...
@@ -16,6 +16,9 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
+#ifdef	_MSC_VER
20
+#include <winsock.h>
21
+#endif
19 22
 
20 23
 #if HAVE_CONFIG_H
21 24
 #include "clamav-config.h"
... ...
@@ -47,6 +50,7 @@ char *txtquery(const char *domain, unsigned int *ttl)
47 47
 	int len, exp, cttl, size, txtlen, type, qtype;
48 48
 
49 49
 
50
+    *ttl = 0;
50 51
     if(res_init() < 0) {
51 52
 	logg("^res_init failed\n");
52 53
 	return NULL;
... ...
@@ -106,7 +110,6 @@ char *txtquery(const char *domain, unsigned int *ttl)
106 106
 
107 107
     pt += INT16SZ; /* class */
108 108
     GETLONG(cttl, pt);
109
-    *ttl = cttl;
110 109
     GETSHORT(size, pt);
111 110
     txtlen = *pt;
112 111
 
... ...
@@ -121,6 +124,43 @@ char *txtquery(const char *domain, unsigned int *ttl)
121 121
     pt++;
122 122
     strncpy(txt, pt, txtlen);
123 123
     txt[txtlen] = 0;
124
+    *ttl = cttl;
125
+
126
+    return txt;
127
+}
128
+
129
+#elif defined(C_WINDOWS)
130
+
131
+/*
132
+ * Note: Needs to link with dnsapi.lib.  
133
+ * The dll behind this library is available from Windows 2000 onward.
134
+ * Written by Mark Pizzolato
135
+ */
136
+
137
+#include <string.h>
138
+#include <windows.h>
139
+#include <windns.h>
140
+#include "shared/memory.h"
141
+#include "shared/output.h"
142
+
143
+char *txtquery(const char *domain, unsigned int *ttl)
144
+{
145
+	PDNS_RECORD pDnsRecord;
146
+	char *txt = NULL;
147
+
148
+    *ttl = 0;
149
+    mprintf("*Querying %s\n", domain);
150
+
151
+   if(DnsQuery_UTF8(domain, DNS_TYPE_TEXT, DNS_QUERY_TREAT_AS_FQDN, NULL, &pDnsRecord, NULL) != 0)
152
+	return NULL;
153
+
154
+    if(pDnsRecord->Data.TXT.dwStringCount > 0) {
155
+	txt = mmalloc(strlen(pDnsRecord->Data.TXT.pStringArray[0]) + 1);
156
+	if(txt)
157
+	    strcpy(txt, pDnsRecord->Data.TXT.pStringArray[0]);
158
+	*ttl = pDnsRecord->dwTtl;
159
+    }
160
+    DnsRecordListFree(pDnsRecord, DnsFreeRecordList);
124 161
 
125 162
     return txt;
126 163
 }
... ...
@@ -129,6 +169,7 @@ char *txtquery(const char *domain, unsigned int *ttl)
129 129
 
130 130
 char *txtquery(const char *domain, unsigned int *ttl)
131 131
 {
132
+    *ttl = 1;  /* ttl of 1 combined with a NULL return distinguishes a failed lookup from DNS queries not being available */
132 133
     return NULL;
133 134
 }
134 135