Skipping packets that do not have etherType, e.g. XID, EAPOL, etc.
authorrtrimana <rtrimana@uci.edu>
Wed, 25 Apr 2018 18:55:48 +0000 (11:55 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 25 Apr 2018 18:55:48 +0000 (11:55 -0700)
Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap [new file with mode: 0644]
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/EthernetFrame.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java

diff --git a/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap b/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap
new file mode 100644 (file)
index 0000000..8c945a0
Binary files /dev/null and b/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap differ
index 7c380ce62ac6b866ee6d24b55fda0e7bdfdd5f27..c575a82636026bfe3917051adf104703e1a7c514 100644 (file)
@@ -52,23 +52,29 @@ public class EthernetFrame extends KaitaiStruct {
         this.dstMac = this._io.readBytes(6);
         this.srcMac = this._io.readBytes(6);
         this.etherType = EtherTypeEnum.byId(this._io.readU2be());
-        switch (etherType()) {
-        case IPV4: {
-            this._raw_body = this._io.readBytesFull();
-            KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
-            this.body = new Ipv4Packet(_io__raw_body);
-            break;
-        }
-        case IPV6: {
-            this._raw_body = this._io.readBytesFull();
-            KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
-            this.body = new Ipv6Packet(_io__raw_body);
-            break;
-        }
-        default: {
-            this.body = this._io.readBytesFull();
-            break;
-        }
+
+        // We skip if etherType is NULL
+        // Some packets, e.g. EAPOL and XID do not have etherType
+        //      and we are not interested in these packets
+        if(etherType() != null) {
+            switch (etherType()) {
+                case IPV4: {
+                    this._raw_body = this._io.readBytesFull();
+                    KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
+                    this.body = new Ipv4Packet(_io__raw_body);
+                    break;
+                }
+                case IPV6: {
+                    this._raw_body = this._io.readBytesFull();
+                    KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
+                    this.body = new Ipv6Packet(_io__raw_body);
+                    break;
+                }
+                default: {
+                    this.body = this._io.readBytesFull();
+                    break;
+                }
+            }
         }
     }
     private byte[] dstMac;
index c724874e520cea6d3faa71dfd687f0550b57b0f2..6fb5e9fcac59bf5008bba975f1c862bb571e8e3d 100644 (file)
@@ -12,11 +12,12 @@ public class Main {
 
     public static void main(String[] args) throws Exception {
         System.out.println("it works");
-        String file = "/home/rtrimana/pcap_processing/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcapdump";
+        //String file = "/home/rtrimana/pcap_processing/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/gre-sample.pcap";
+        String file = "/home/rtrimana/pcap_processing/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap";
         
         try {
             Pcap data = Pcap.fromFile(file);
-            //data.hdr();
+            data.hdr();
         } catch (Exception e) {
             e.printStackTrace();
         }