dump: import code from ndndump repository

Code is copied from ndndump:commit:c266031924d723b9a73be29ebb66fd6db26aade5,
with minor changes for removing trailing whitespaces.
Build script is rewritten.

refs #2692

Change-Id: I07eec2f87542f1328b851cc2c4e5c9b6279db7da
diff --git a/tools/dump/ndndump.hpp b/tools/dump/ndndump.hpp
new file mode 100644
index 0000000..b5c3470
--- /dev/null
+++ b/tools/dump/ndndump.hpp
@@ -0,0 +1,113 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2014, Regents of the University of California,
+ *
+ * This file is part of ndndump, the packet capture and analysis tool for Named Data
+ * Networking (NDN).
+ *
+ * ndndump is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndndump 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
+ * ndndump, e.g., in COPYING file.  If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#ifndef NDNDUMP_NDNDUMP_HPP
+#define NDNDUMP_NDNDUMP_HPP
+
+#include <pcap.h>
+
+#include <ndn-cxx/name.hpp>
+#include <boost/regex.hpp>
+
+namespace ndn {
+namespace tools {
+
+class Ndndump : noncopyable
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
+  Ndndump()
+    : isVerbose(false)
+    , pcapProgram("(ether proto 0x8624) || (tcp port 6363) || (udp port 6363)")
+    // , isSuccinct(false)
+    // , isMatchInverted(false)
+    // , shouldPrintStructure(false)
+    // , isTcpOnly(false)
+    // , isUdpOnly(false)
+  {
+  }
+
+  void
+  run();
+
+private:
+  static void
+  onCapturedPacket(uint8_t* userData, const struct pcap_pkthdr* header, const uint8_t* packet)
+  {
+    reinterpret_cast<Ndndump*>(userData)->onCapturedPacket(header, packet);
+  }
+
+  void
+  onCapturedPacket(const struct pcap_pkthdr* header, const uint8_t* packet);
+
+  void
+  printInterceptTime(std::ostream& os, const struct pcap_pkthdr* header);
+
+  int
+  skipDataLinkHeaderAndGetFrameType(const uint8_t*& payload, ssize_t& payloadSize);
+
+  int
+  skipAndProcessFrameHeader(int frameType,
+                            const uint8_t*& payload, ssize_t& payloadSize,
+                            std::ostream& os);
+
+  bool
+  matchesFilter(const Name& name)
+  {
+    if (nameFilter.empty())
+      return true;
+
+    /// \todo Switch to NDN regular expressions
+
+    return boost::regex_match(name.toUri(), nameFilter);
+  }
+
+public:
+  bool isVerbose;
+  // bool isSuccinct;
+  // bool isMatchInverted;
+  // bool shouldPrintStructure;
+  // bool isTcpOnly;
+  // bool isUdpOnly;
+
+  std::string pcapProgram;
+  std::string interface;
+  boost::regex nameFilter;
+  std::string inputFile;
+  // std::string outputFile;
+
+private:
+  pcap_t* m_pcap;
+  int m_dataLinkType;
+};
+
+
+} // namespace tools
+} // namespace ndn
+
+#endif // NDNDUMP_NDNDUMP_HPP