dump: recognize LINUX_SLL link-type

refs #3061

Change-Id: Idf50a70f17a1c9ffedbed5697ca11070d35e95a3
diff --git a/tests/dump/LINUXSLL-tcp4.pcap b/tests/dump/LINUXSLL-tcp4.pcap
new file mode 100644
index 0000000..37d1c13
--- /dev/null
+++ b/tests/dump/LINUXSLL-tcp4.pcap
Binary files differ
diff --git a/tests/dump/LINUXSLL-tcp6.pcap b/tests/dump/LINUXSLL-tcp6.pcap
new file mode 100644
index 0000000..eb73d5c
--- /dev/null
+++ b/tests/dump/LINUXSLL-tcp6.pcap
Binary files differ
diff --git a/tests/dump/LINUXSLL-udp4.pcap b/tests/dump/LINUXSLL-udp4.pcap
new file mode 100644
index 0000000..45a6dc6
--- /dev/null
+++ b/tests/dump/LINUXSLL-udp4.pcap
Binary files differ
diff --git a/tests/dump/LINUXSLL-udp6.pcap b/tests/dump/LINUXSLL-udp6.pcap
new file mode 100644
index 0000000..2e68da0
--- /dev/null
+++ b/tests/dump/LINUXSLL-udp6.pcap
Binary files differ
diff --git a/tests/dump/README.md b/tests/dump/README.md
index 47fbf7f..adf5f96 100644
--- a/tests/dump/README.md
+++ b/tests/dump/README.md
@@ -27,3 +27,13 @@
   - Duplicate
   - None
   - None
+
+### 2. LINUX\_SLL link-type
+
+Trace file: `LINUXSLL-udp4.pcap` `LINUXSLL-udp6.pcap` `LINUXSLL-tcp4.pcap` `LINUXSLL-tcp6.pcap`
+
+These traces are captured inside an OpenVZ container which uses LINUX\_SLL (Linux cooked) link-type.
+
+Expected result:
+Some Interests and Data should be displayed from udp4 and tcp4 traces.
+Currently nothing is displayed from udp6 and tcp6 traces because ndndump lacks IPv6 support until [Feature 3861](https://redmine.named-data.net/issues/3861).
diff --git a/tools/dump/ndndump.cpp b/tools/dump/ndndump.cpp
index d23bf9a..91d6827 100644
--- a/tools/dump/ndndump.cpp
+++ b/tools/dump/ndndump.cpp
@@ -50,6 +50,8 @@
 } // namespace dump
 } // namespace ndn
 
+#include <pcap/sll.h>
+
 #include <boost/lexical_cast.hpp>
 
 #include <iomanip>
@@ -139,7 +141,7 @@
   }
 
   m_dataLinkType = pcap_datalink(m_pcap);
-  if (m_dataLinkType != DLT_EN10MB && m_dataLinkType != DLT_PPP) {
+  if (m_dataLinkType != DLT_EN10MB && m_dataLinkType != DLT_PPP && m_dataLinkType != DLT_LINUX_SLL) {
     BOOST_THROW_EXCEPTION(Error("Unsupported pcap format (" + to_string(m_dataLinkType) + ")"));
   }
 
@@ -297,6 +299,20 @@
 
       break;
     }
+    case DLT_LINUX_SLL: {
+      const sll_header* sllHeader = reinterpret_cast<const sll_header*>(payload);
+
+      if (payloadSize < SLL_HDR_LEN) {
+        std::cerr << "Invalid LINUX_SLL frame" << std::endl;
+        return -1;
+      }
+
+      frameType = ntohs(sllHeader->sll_protocol);
+      payloadSize -= SLL_HDR_LEN;
+      payload += SLL_HDR_LEN;
+
+      break;
+    }
   }
 
   return frameType;