From ed982c0efdf83d0c2357abced4b8ad48857179ea Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Sat, 30 Jan 2016 15:15:37 +0100
Subject: [PATCH] rdpcap() calls _rdpcap() or _rdpcapng() to handle both format

---
 scapy/utils.py | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/scapy/utils.py b/scapy/utils.py
index d3c57899..de29b160 100644
--- a/scapy/utils.py
+++ b/scapy/utils.py
@@ -527,14 +527,36 @@ endianness: "<" or ">", force endianness"""
 
 @conf.commands.register
 def rdpcap(filename, count=-1):
+    """Read a pcap or pcapng file and return a packet list
+
+count: read only <count> packets
+
+    """
+    try:
+        return _rdpcap(filename, count=count)
+    except Scapy_Exception:
+        pass
+    try:
+        return _rdpcapng(filename, count=count)
+    except Scapy_Exception:
+        raise Scapy_Exception("Not a valid pcap or pcapng file")
+
+
+def _rdpcap(filename, count=-1):
     """Read a pcap file and return a packet list
-count: read only <count> packets"""
+
+count: read only <count> packets
+
+    """
     with PcapReader(filename) as fdesc:
         return fdesc.read_all(count=count)
 
-def rdpcapng(filename, count=-1):
+def _rdpcapng(filename, count=-1):
     """Read a pcapng file and return a packet list
-count: read only <count> packets"""
+
+count: read only <count> packets
+
+    """
     with PcapNgReader(filename) as fdesc:
         return fdesc.read_all(count=count)
 
-- 
GitLab