import java.util.HashMap;
public class EthernetFrame extends KaitaiStruct {
+ private static int counter = 0;
public static EthernetFrame fromFile(String fileName) throws IOException {
return new EthernetFrame(new ByteBufferKaitaiStream(fileName));
}
this.dstMac = this._io.readBytes(6);
this.srcMac = this._io.readBytes(6);
this.etherType = EtherTypeEnum.byId(this._io.readU2be());
-
// 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
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;
- }
+ // TODO: Skip IPV6 for now and perhaps do it later
+ //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 void _read() {
this.nextHeaderType = this._io.readU1();
this.hdrExtLen = this._io.readU1();
- this.body = this._io.readBytes((hdrExtLen() - 1));
switch (nextHeaderType()) {
case 0: {
this.nextHeader = new OptionHopByHop(this._io, this, _root);
package edu.uci.iotproject;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
* @author Janus Varmarken
*/
public class Main {
+ private static int counter = 0;
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/gre-sample.pcap";
+ //String file = "/scratch/traffic_measurements/Switches-Feb2018/wemo/wlan1/wlan1.setup.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();
+ List<Pcap.Packet> listPacket = data.packets();
+ System.out.println("Number of packets: " + listPacket.size());
+ System.out.println("===================");
+ for(Pcap.Packet packet : listPacket) {
+ System.out.print("#" + counter++ + "\n");
+ if (packet._root().hdr().network() == Pcap.Linktype.ETHERNET) {
+ EthernetFrame eFrame = (EthernetFrame) packet.body();
+ if (eFrame.etherType() == EthernetFrame.EtherTypeEnum.IPV4) {
+ Ipv4Packet ip4Packet = (Ipv4Packet) eFrame.body();
+ byte[] srcIp = ip4Packet.srcIpAddr();
+ byte[] dstIp = ip4Packet.dstIpAddr();
+ System.out.println("Byte length source: " + srcIp.length + " Byte length dest: " + dstIp.length);
+ System.out.print("Source: ");
+ for(int i = 0; i < srcIp.length; i++) {
+ System.out.print(Byte.toUnsignedInt(srcIp[i]));
+ if(i < srcIp.length-1)
+ System.out.print(".");
+ }
+ System.out.print(" - Dest: ");
+ for(int i = 0; i < dstIp.length; i++) {
+ System.out.print(Byte.toUnsignedInt(dstIp[i]));
+ if(i < dstIp.length-1)
+ System.out.print(".");
+ else
+ System.out.println("\n");
+ }
+ }
+ }
+ }
+
} catch (Exception e) {
e.printStackTrace();
}
+++ /dev/null
-package edu.uci.iotproject;
-
-import java.util.Objects;
-
-/**
- * Represents a network packet.
- *
- * @author Janus Varmarken
- */
-public class Packet {
-
- /**
- * The packet's length.
- */
- private final int length;
-
- // TODO should we use hostname for src/dst such that we can map packets pertaining to the same host as similar even if they are sent to different IPs (due to load balancing)?
-
- /**
- * The packet's source (IP).
- */
- private final String source;
-
- /**
- * The packet's destination (IP).
- */
- private final String destionation;
-
- public Packet(String src, String dst, int length) {
- this.source = Objects.requireNonNull(src);
- this.destionation = Objects.requireNonNull(dst);
- this.length = length;
- }
-
-}