1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
$NetBSD: patch-ab,v 1.11 2006/04/03 18:38:58 wiz Exp $
--- dns.c.orig 2006-03-23 05:45:58.000000000 +0000
+++ dns.c
@@ -28,13 +28,20 @@
#include <sys/time.h>
#include <sys/select.h>
#include <sys/stat.h>
-#include <sys/errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#ifdef __APPLE__
+#include <arpa/nameser8_compat.h>
+#else
#include <arpa/nameser.h>
+#endif
#include <netdb.h>
+#ifdef __APPLE__
+#include <resolv8_compat.h>
+#else
#include <resolv.h>
+#endif
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
@@ -54,9 +61,6 @@ extern char *sys_errlist[];
#define strerror(errno) (((errno) >= 0 && (errno) < sys_nerr) ? sys_errlist[errno] : "unlisted error")
#endif
-/* Hmm, it seems Irix requires this */
-extern int errno;
-
extern int af;
/* Defines */
@@ -294,6 +298,17 @@ char nullstring[] = "";
int use_dns = 1;
+#ifdef res_ninit
+#define RES_INIT() res_ninit(&myres);
+#define RES_MKQUERY(a, b, c, d, e, f, g, h, i) \
+ res_nmkquery(&myres, a, b, c, d, e, f, g, h, i)
+struct __res_state myres;
+#else
+#define RES_INIT() res_init();
+#define RES_MKQUERY(a, b, c, d, e, f, g, h, i) \
+ res_mkquery(a, b, c, d, e, f, g, h, i)
+#define myres _res
+#endif
/* Code */
#ifdef CorruptCheck
@@ -468,14 +483,14 @@ void dns_open(void)
{
int option,i;
- res_init();
- if (!_res.nscount) {
+ RES_INIT();
+ if (!myres.nscount) {
fprintf(stderr,"No nameservers defined.\n");
exit(-1);
}
- _res.options|= RES_RECURSE | RES_DEFNAMES | RES_DNSRCH;
- for (i = 0;i < _res.nscount;i++)
- _res.nsaddr_list[i].sin_family = AF_INET;
+ myres.options|= RES_RECURSE | RES_DEFNAMES | RES_DNSRCH;
+ for (i = 0;i < myres.nscount;i++)
+ myres.nsaddr_list[i].sin_family = AF_INET;
resfd = socket(AF_INET, SOCK_DGRAM, 0);
if (resfd == -1) {
fprintf(stderr,"Unable to allocate socket for nameserver communication: %s\n",
@@ -858,17 +873,17 @@ void dorequest(char *s,int type,word id)
{
packetheader *hp;
int r,i;
- int buf[(MaxPacketsize/sizeof (int))+1];
+ unsigned char buf[MaxPacketsize];
- r = res_mkquery(QUERY,s,C_IN,type,NULL,0,NULL,(unsigned char*)buf,MaxPacketsize);
+ r = RES_MKQUERY(QUERY,s,C_IN,type,NULL,0,NULL,(unsigned char*)buf,MaxPacketsize);
if (r == -1) {
restell("Resolver error: Query too large.");
return;
}
hp = (packetheader *)buf;
hp->id = id; /* htons() deliberately left out (redundant) */
- for (i = 0;i < _res.nscount;i++)
- (void)sendto(resfd,buf,r,0,(struct sockaddr *)&_res.nsaddr_list[i],
+ for (i = 0;i < myres.nscount;i++)
+ (void)sendto(resfd,buf,r,0,(struct sockaddr *)&myres.nsaddr_list[i],
sizeof(struct sockaddr));
}
@@ -1224,18 +1239,18 @@ void dns_ack(void)
/* Check to see if this server is actually one we sent to */
if ( addrcmp( (void *) &(from4->sin_addr), (void *) &localhost,
(int) AF_INET ) == 0 ) {
- for (i = 0;i < _res.nscount;i++)
- if ( addrcmp( (void *) &(_res.nsaddr_list[i].sin_addr),
+ for (i = 0;i < myres.nscount;i++)
+ if ( addrcmp( (void *) &(myres.nsaddr_list[i].sin_addr),
(void *) &(from4->sin_addr), (int) AF_INET ) == 0 ||
- addrcmp( (void *) &(_res.nsaddr_list[i].sin_addr),
+ addrcmp( (void *) &(myres.nsaddr_list[i].sin_addr),
(void *) &unspec_addr, (int) AF_INET ) == 0 ) /* 0.0.0.0 replies as 127.0.0.1 */
break;
} else
- for (i = 0;i < _res.nscount;i++)
- if ( addrcmp( (void *) &(_res.nsaddr_list[i].sin_addr),
+ for (i = 0;i < myres.nscount;i++)
+ if ( addrcmp( (void *) &(myres.nsaddr_list[i].sin_addr),
(void *) &(from4->sin_addr), AF_INET ) == 0 )
break;
- if (i == _res.nscount) {
+ if (i == myres.nscount) {
sprintf(tempstring,"Resolver error: Received reply from unknown source: %s",
inet_ntoa(from4->sin_addr ));
restell(tempstring);
|