1 // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2 package edu.uci.iotproject;
4 import io.kaitai.struct.ByteBufferKaitaiStream;
5 import io.kaitai.struct.KaitaiStruct;
6 import io.kaitai.struct.KaitaiStream;
7 import java.io.IOException;
9 import java.util.HashMap;
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));
17 public enum EtherTypeEnum {
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);
32 for (EtherTypeEnum e : EtherTypeEnum.values())
35 public static EtherTypeEnum byId(long id) { return byId.get(id); }
38 public EthernetFrame(KaitaiStream _io) {
39 this(_io, null, null);
42 public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent) {
43 this(_io, _parent, null);
46 public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent, EthernetFrame _root) {
48 this._parent = _parent;
49 this._root = _root == null ? this : _root;
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()) {
62 this._raw_body = this._io.readBytesFull();
63 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
64 this.body = new Ipv4Packet(_io__raw_body);
67 // TODO: Skip IPV6 for now and perhaps do it later
69 // this._raw_body = this._io.readBytesFull();
70 // KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
71 // this.body = new Ipv6Packet(_io__raw_body);
75 this.body = this._io.readBytesFull();
81 private byte[] dstMac;
82 private byte[] srcMac;
83 private EtherTypeEnum etherType;
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; }