]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/dnsscan.cc
Merge pull request #7677 from rgacogne/dnsdist-logging-facility
[thirdparty/pdns.git] / pdns / dnsscan.cc
index 7a10e4a8b0a98e2777361e6c0bf7b0130b685b23..936a05dd9390707348fa20b898c9a4be03d3d51d 100644 (file)
@@ -1,3 +1,24 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -7,8 +28,6 @@
 #include "sstuff.hh"
 #include "anadns.hh"
 
-// this is needed because boost multi_index also uses 'L', as do we (which is sad enough)
-#undef L
 
 #include <set>
 #include <deque>
@@ -25,6 +44,10 @@ using namespace ::boost::multi_index;
 #include "namespaces.hh"
 StatBag S;
 
+void usage() {
+  cerr<<"syntax: dnsscan INFILE ..."<<endl;
+}
+
 int main(int argc, char** argv)
 try
 {
@@ -37,8 +60,20 @@ try
   */
 
   if(argc<2) {
-    cerr<<"Syntax: dnsscan file1 [file2 ..] "<<endl;
-    exit(1);
+    usage();
+    exit(EXIT_SUCCESS);
+  }
+
+  for(int n=1; n < argc; ++n) {
+    if ((string) argv[n] == "--help") {
+      usage();
+      return EXIT_SUCCESS;
+    }
+
+    if ((string) argv[n] == "--version") {
+      cerr<<"dnsscan "<<VERSION<<endl;
+      return EXIT_SUCCESS;
+    }
   }
 
   unsigned int counts[256];
@@ -50,27 +85,13 @@ try
     
     while(pr.getUDPPacket()) {
       try {
-        MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
+        MOADNSParser mdp(false, (const char*)pr.d_payload, pr.d_len);
         if(mdp.d_qtype < 256)
           counts[mdp.d_qtype]++;
 
-        for(unsigned int i=0; i < mdp.d_qname.length(); ++i)
-          if(!isalnum(mdp.d_qname[i]) && mdp.d_qname[i]!='.' && mdp.d_qname[i]!='-' && mdp.d_qname[i]!='_') {
-            //          cout<<mdp.d_qname<<"|"<<mdp.d_qtype<<"|"<<mdp.d_qclass<<"\n";
-            // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
-            break;
-          }
-        if(mdp.d_qtype > 256 || mdp.d_qclass!=1 ) {
-          //        sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
-          
-        }
-        for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {          
-          
-        }
-        
       }
-      catch(MOADNSException &e) {
-        cout<<"Error from remote "<<pr.getSource().toString()<<": "<<e.what()<<"\n";
+      catch(const MOADNSException &mde) {
+        cout<<"Error from remote "<<pr.getSource().toString()<<": "<<mde.what()<<"\n";
         //        sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
       }
     }