Add functional code that loads a pcap file and constructs the IP->hostname map/dictio...
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / EthernetFrame.java
1 // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2 package edu.uci.iotproject;
3
4 import io.kaitai.struct.ByteBufferKaitaiStream;
5 import io.kaitai.struct.KaitaiStruct;
6 import io.kaitai.struct.KaitaiStream;
7 import java.io.IOException;
8 import java.util.Map;
9 import java.util.HashMap;
10
11 public class EthernetFrame extends KaitaiStruct {
12     private static int counter = 0;
13     public static EthernetFrame fromFile(String fileName) throws IOException {
14         return new EthernetFrame(new ByteBufferKaitaiStream(fileName));
15     }
16
17     public enum EtherTypeEnum {
18         IPV4(2048),
19         X_75_INTERNET(2049),
20         NBS_INTERNET(2050),
21         ECMA_INTERNET(2051),
22         CHAOSNET(2052),
23         X_25_LEVEL_3(2053),
24         ARP(2054),
25         IPV6(34525);
26
27         private final long id;
28         EtherTypeEnum(long id) { this.id = id; }
29         public long id() { return id; }
30         private static final Map<Long, EtherTypeEnum> byId = new HashMap<Long, EtherTypeEnum>(8);
31         static {
32             for (EtherTypeEnum e : EtherTypeEnum.values())
33                 byId.put(e.id(), e);
34         }
35         public static EtherTypeEnum byId(long id) { return byId.get(id); }
36     }
37
38     public EthernetFrame(KaitaiStream _io) {
39         this(_io, null, null);
40     }
41
42     public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent) {
43         this(_io, _parent, null);
44     }
45
46     public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent, EthernetFrame _root) {
47         super(_io);
48         this._parent = _parent;
49         this._root = _root == null ? this : _root;
50         _read();
51     }
52     private void _read() {
53         this.dstMac = this._io.readBytes(6);
54         this.srcMac = this._io.readBytes(6);
55         this.etherType = EtherTypeEnum.byId(this._io.readU2be());
56         // We skip if etherType is NULL
57         // Some packets, e.g. EAPOL and XID do not have etherType
58         //      and we are not interested in these packets
59         if(etherType() != null) {
60             switch (etherType()) {
61                 case IPV4: {
62                     this._raw_body = this._io.readBytesFull();
63                     KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
64                     this.body = new Ipv4Packet(_io__raw_body);
65                     break;
66                 }
67                 // TODO: Skip IPV6 for now and perhaps do it later
68                 //case IPV6: {
69                 //    this._raw_body = this._io.readBytesFull();
70                 //    KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
71                 //    this.body = new Ipv6Packet(_io__raw_body);
72                 //    break;
73                 //}
74                 default: {
75                     this.body = this._io.readBytesFull();
76                     break;
77                 }
78             }
79         }
80     }
81     private byte[] dstMac;
82     private byte[] srcMac;
83     private EtherTypeEnum etherType;
84     private Object body;
85     private EthernetFrame _root;
86     private KaitaiStruct _parent;
87     private byte[] _raw_body;
88     public byte[] dstMac() { return dstMac; }
89     public byte[] srcMac() { return srcMac; }
90     public EtherTypeEnum etherType() { return etherType; }
91     public Object body() { return body; }
92     public EthernetFrame _root() { return _root; }
93     public KaitaiStruct _parent() { return _parent; }
94     public byte[] _raw_body() { return _raw_body; }
95 }