dump: capture in promisc mode by default, with an option to disable it

Change-Id: I75d9580616f0af588291897b27fe376921fef11f
diff --git a/tools/dump/main.cpp b/tools/dump/main.cpp
index 25a0226..ebec765 100644
--- a/tools/dump/main.cpp
+++ b/tools/dump/main.cpp
@@ -73,7 +73,8 @@
                     "read packets from the specified file; use \"-\" to read from standard input")
     ("filter,f",    po::value<std::string>(&nameFilter),
                     "print packet only if name matches this regular expression")
-    ("verbose,v",   po::bool_switch(&instance.isVerbose),
+    ("no-promiscuous-mode,p", po::bool_switch(), "do not put the interface into promiscuous mode")
+    ("verbose,v",   po::bool_switch(&instance.wantVerbose),
                     "print more detailed information about each packet")
     ("version,V",   "print program version and exit")
     ;
@@ -138,6 +139,8 @@
     instance.pcapFilter = os.str();
   }
 
+  instance.wantPromisc = !vm["no-promiscuous-mode"].as<bool>();
+
   try {
     instance.run();
   }
diff --git a/tools/dump/ndndump.cpp b/tools/dump/ndndump.cpp
index 4c6d814..4c43826 100644
--- a/tools/dump/ndndump.cpp
+++ b/tools/dump/ndndump.cpp
@@ -82,7 +82,7 @@
 
   std::string action;
   if (!interface.empty()) {
-    m_pcap = pcap_open_live(interface.data(), 65535, 0, 1000, errbuf);
+    m_pcap = pcap_open_live(interface.data(), 65535, wantPromisc, 1000, errbuf);
     if (m_pcap == nullptr) {
       BOOST_THROW_EXCEPTION(Error("Cannot open interface " + interface + ": " + errbuf));
     }
@@ -117,7 +117,7 @@
   }
 
   if (!pcapFilter.empty()) {
-    if (isVerbose) {
+    if (wantVerbose) {
       std::cerr << "ndndump: using pcap filter: " << pcapFilter << std::endl;
     }
 
diff --git a/tools/dump/ndndump.hpp b/tools/dump/ndndump.hpp
index 7b5e240..4de7f57 100644
--- a/tools/dump/ndndump.hpp
+++ b/tools/dump/ndndump.hpp
@@ -87,7 +87,8 @@
   std::string inputFile;
   std::string pcapFilter = getDefaultPcapFilter();
   optional<std::regex> nameFilter;
-  bool isVerbose = false;
+  bool wantPromisc = true;
+  bool wantVerbose = false;
 
 private:
   pcap_t* m_pcap = nullptr;