branch Attitude Adjustment packages
[12.09/packages.git] / net / djbdns / patches / 260-dnsfilter-replace.patch
1 --- a/dnsfilter.c
2 +++ b/dnsfilter.c
3 @@ -41,6 +41,7 @@ int inbuflen = 0;
4  iopause_fd *inio;
5  int flag0 = 1;
6  
7 +int opt_replace = 0;
8  iopause_fd *io;
9  int iolen;
10  
11 @@ -51,12 +52,16 @@ char name[DNS_NAME4_DOMAIN];
12  void errout(int i)
13  {
14    int j;
15 -
16 -  if (!stralloc_copys(&x[i].middle,":")) nomem();
17 -  if (!stralloc_cats(&x[i].middle,error_str(errno))) nomem();
18 -  for (j = 0;j < x[i].middle.len;++j)
19 -    if (x[i].middle.s[j] == ' ')
20 -      x[i].middle.s[j] = '-';
21
22 +  if (opt_replace) 
23 +    x[i].middle.len=0;
24 +  else {
25 +    if (!stralloc_copys(&x[i].middle,":")) nomem();
26 +    if (!stralloc_cats(&x[i].middle,error_str(errno))) nomem();
27 +    for (j = 0;j < x[i].middle.len;++j)
28 +      if (x[i].middle.s[j] == ' ')
29 +        x[i].middle.s[j] = '-';
30 +  }
31  }
32  
33  int main(int argc,char **argv)
34 @@ -69,7 +74,7 @@ int main(int argc,char **argv)
35    int j;
36    int r;
37  
38 -  while ((opt = getopt(argc,argv,"c:l:")) != opteof)
39 +  while ((opt = getopt(argc,argv,"c:l:r")) != opteof)
40      switch(opt) {
41        case 'c':
42         scan_ulong(optarg,&u);
43 @@ -83,8 +88,11 @@ int main(int argc,char **argv)
44         if (u > 1000000) u = 1000000;
45         xmax = u;
46         break;
47 +      case 'r':
48 +       opt_replace = 1;          
49 +       break;
50        default:
51 -       strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ]");
52 +       strerr_die1x(111,"dnsfilter: usage: dnsfilter [ -c concurrency ] [ -l lines ] [-r]");
53      }
54  
55    x = (struct line *) alloc(xmax * sizeof(struct line));
56 @@ -140,8 +148,13 @@ int main(int argc,char **argv)
57         else if (r == 1) {
58           if (dns_name_packet(&x[i].middle,x[i].dt.packet,x[i].dt.packetlen) == -1)
59             errout(i);
60 -         if (x[i].middle.len)
61 -           if (!stralloc_cats(&x[i].left,"=")) nomem();
62 +         if (x[i].middle.len) {
63 +           if (opt_replace) {
64 +             if (!stralloc_copys(&x[i].left, "")) nomem();
65 +           } else {
66 +             if (!stralloc_cats(&x[i].left, "=")) nomem();
67 +           }
68 +         }
69           x[i].flagactive = 0;
70           --numactive;
71         }