summaryrefslogtreecommitdiffstats
path: root/net/djbdns/patches/260-dnsfilter-replace.patch
blob: b352f1c7e8a7d0f9d9149ddb940d32e32e449816 (plain)
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
--- a/dnsfilter.c
+++ b/dnsfilter.c
@@ -41,6 +41,7 @@ int inbuflen = 0;
 iopause_fd *inio;
 int flag0 = 1;
 
+int opt_replace = 0;
 iopause_fd *io;
 int iolen;
 
@@ -51,12 +52,16 @@ char name[DNS_NAME4_DOMAIN];
 void errout(int i)
 {
   int j;
-
-  if (!stralloc_copys(&x[i].middle,":")) nomem();
-  if (!stralloc_cats(&x[i].middle,error_str(errno))) nomem();
-  for (j = 0;j < x[i].middle.len;++j)
-    if (x[i].middle.s[j] == ' ')
-      x[i].middle.s[j] = '-';
+ 
+  if (opt_replace) 
+    x[i].middle.len=0;
+  else {
+    if (!stralloc_copys(&x[i].middle,":")) nomem();
+    if (!stralloc_cats(&x[i].middle,error_str(errno))) nomem();
+    for (j = 0;j < x[i].middle.len;++j)
+      if (x[i].middle.s[j] == ' ')
+        x[i].middle.s[j] = '-';
+  }
 }
 
 int main(int argc,char **argv)
@@ -69,7 +74,7 @@ int main(int argc,char **argv)
   int j;
   int r;
 
-  while ((opt = getopt(argc,argv,"c:l:")) != opteof)
+  while ((opt = getopt(argc,argv,"c:l:r")) != opteof)
     switch(opt) {
       case 'c':
 	scan_ulong(optarg,&u);
@@ -83,8 +88,11 @@ int main(int argc,char **argv)
 	if (u > 1000000) u = 1000000;
 	xmax = u;
 	break;
+      case 'r':
+	opt_replace = 1;	  
+	break;
       default:
-	strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ]");
+	strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ] [-r]");
     }
 
   x = (struct line *) alloc(xmax * sizeof(struct line));
@@ -140,8 +148,13 @@ int main(int argc,char **argv)
 	else if (r == 1) {
 	  if (dns_name_packet(&x[i].middle,x[i].dt.packet,x[i].dt.packetlen) == -1)
 	    errout(i);
-	  if (x[i].middle.len)
-	    if (!stralloc_cats(&x[i].left,"=")) nomem();
+	  if (x[i].middle.len) {
+	    if (opt_replace) {
+	      if (!stralloc_copys(&x[i].left, "")) nomem();
+	    } else {
+	      if (!stralloc_cats(&x[i].left, "=")) nomem();
+	    }
+	  }
 	  x[i].flagactive = 0;
 	  --numactive;
 	}