PcapHandleReader: count and print (to std.err) the number of packets that appear...
authorJanus Varmarken <varmarken@gmail.com>
Tue, 24 Jul 2018 21:41:16 +0000 (14:41 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Tue, 24 Jul 2018 21:41:16 +0000 (14:41 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/PcapHandleReader.java

index 2c387f3cdb622982655917ccc9053ba7eb1b4ce9..e01f712546ce939e10e464c23bb1c17cc476bcd4 100644 (file)
@@ -43,12 +43,13 @@ public class PcapHandleReader {
      * @throws TimeoutException if packets are being read from a live capture and the timeout expired.
      */
     public void readFromHandle() throws PcapNativeException, NotOpenException, TimeoutException {
+        int outOfOrderPackets = 0;
         try {
             PcapPacket prevPacket = null;
             PcapPacket packet;
             while ((packet = mHandle.getNextPacketEx()) != null) {
                 if (prevPacket != null && packet.getTimestamp().isBefore(prevPacket.getTimestamp())) {
-                    System.out.println("Out-of-order (in terms of timestamp) packet detected");
+                    outOfOrderPackets++;
                     /*
                     // Fail early if assumption doesn't hold.
                     mHandle.close();
@@ -67,6 +68,11 @@ public class PcapHandleReader {
             // Reached end of file. All good.
             System.out.println(String.format("%s: finished reading pcap file", getClass().getSimpleName()));
         }
+        if (outOfOrderPackets > 0) {
+            System.err.println(
+                    String.format("[[[ %s: %d packets appeared out of order (with regards to their timestamps) ]]]",
+                            getClass().getSimpleName(), outOfOrderPackets));
+        }
         mHandle.close();
     }