dump: fix compilation on CentOS 7

Refs: #4852
Change-Id: I2550d26f709f645ee3d6b2e0f63a6698525e1a76
diff --git a/tests/dump/ndndump.t.cpp b/tests/dump/ndndump.t.cpp
index 8facd0e..4e55fcc 100644
--- a/tests/dump/ndndump.t.cpp
+++ b/tests/dump/ndndump.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018, University of Memphis,
+ * Copyright (c) 2014-2019, University of Memphis,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
@@ -351,14 +351,14 @@
   dump.wantTimestamp = false;
 
   tcphdr tcpHdr1{};
-  tcpHdr1.th_off = 0x2;
+  tcpHdr1.TH_OFF = 0x2;
 
   EncodingBuffer pkt1;
   this->receiveTcp4(pkt1, &tcpHdr1);
   BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, TCP bad header length 8\n"));
 
   tcphdr tcpHdr2{};
-  tcpHdr2.th_off = 0xf;
+  tcpHdr2.TH_OFF = 0xf;
 
   EncodingBuffer pkt2;
   this->receiveTcp4(pkt2, &tcpHdr2);
@@ -370,16 +370,16 @@
   dump.wantTimestamp = false;
 
   udphdr udpHdr1{};
-  udpHdr1.uh_ulen = 3;
-  endian::native_to_big_inplace(udpHdr1.uh_ulen);
+  udpHdr1.UH_LEN = 3;
+  endian::native_to_big_inplace(udpHdr1.UH_LEN);
 
   EncodingBuffer pkt1;
   this->receiveUdp4(pkt1, &udpHdr1);
   BOOST_CHECK(output.is_equal("IP 0.0.0.0 > 0.0.0.0, UDP bad length 3\n"));
 
   udphdr udpHdr2{};
-  udpHdr2.uh_ulen = 1000;
-  endian::native_to_big_inplace(udpHdr2.uh_ulen);
+  udpHdr2.UH_LEN = 1000;
+  endian::native_to_big_inplace(udpHdr2.UH_LEN);
 
   EncodingBuffer pkt2;
   this->receiveUdp4(pkt2, &udpHdr2);
diff --git a/tools/dump/ndndump.cpp b/tools/dump/ndndump.cpp
index b13b7ef..d5b6571 100644
--- a/tools/dump/ndndump.cpp
+++ b/tools/dump/ndndump.cpp
@@ -454,7 +454,7 @@
   }
 
   auto th = reinterpret_cast<const tcphdr*>(pkt);
-  size_t tcpHdrLen = th->th_off * 4;
+  size_t tcpHdrLen = th->TH_OFF * 4;
   if (tcpHdrLen < sizeof(tcphdr)) {
     out << " bad header length " << tcpHdrLen;
     return true;
@@ -483,7 +483,7 @@
   }
 
   auto uh = reinterpret_cast<const udphdr*>(pkt);
-  size_t udpLen = endian::big_to_native(uh->uh_ulen);
+  size_t udpLen = endian::big_to_native(uh->UH_LEN);
   if (udpLen < sizeof(udphdr)) {
     out << " bad length " << udpLen;
     return true;
diff --git a/tools/dump/ndndump.hpp b/tools/dump/ndndump.hpp
index 0198026..58ba032 100644
--- a/tools/dump/ndndump.hpp
+++ b/tools/dump/ndndump.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2011-2018, Regents of the University of California.
+ * Copyright (c) 2011-2019, Regents of the University of California.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -25,6 +25,18 @@
 #include <pcap.h>
 #include <regex>
 
+#ifdef HAVE_BSD_TCPHDR
+#define TH_OFF th_off
+#else
+#define TH_OFF doff
+#endif
+
+#ifdef HAVE_BSD_UDPHDR
+#define UH_LEN uh_ulen
+#else
+#define UH_LEN len
+#endif
+
 namespace ndn {
 namespace dump {
 
diff --git a/tools/dump/wscript b/tools/dump/wscript
index cd9971b..df23de9 100644
--- a/tools/dump/wscript
+++ b/tools/dump/wscript
@@ -4,6 +4,14 @@
 def configure(conf):
     conf.check_cfg(package='libpcap', uselib_store='PCAP',
                    path='pcap-config', args='--libs --cflags')
+    conf.check_cxx(msg='Checking if struct tcphdr has member th_off ',
+                   define_name='HAVE_BSD_TCPHDR', mandatory=False,
+                   fragment='''#include <netinet/tcp.h>
+                               int main() { tcphdr th; th.th_off; }''')
+    conf.check_cxx(msg='Checking if struct udphdr has member uh_ulen',
+                   define_name='HAVE_BSD_UDPHDR', mandatory=False,
+                   fragment='''#include <netinet/udp.h>
+                               int main() { udphdr uh; uh.uh_ulen; }''')
 
 def build(bld):
     bld.objects(