dump: fix compilation on CentOS 7

Refs: #4852
Change-Id: I2550d26f709f645ee3d6b2e0f63a6698525e1a76
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(