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 public static EthernetFrame fromFile(String fileName) throws IOException {
13 return new EthernetFrame(new ByteBufferKaitaiStream(fileName));
16 public enum EtherTypeEnum {
26 private final long id;
27 EtherTypeEnum(long id) { this.id = id; }
28 public long id() { return id; }
29 private static final Map<Long, EtherTypeEnum> byId = new HashMap<Long, EtherTypeEnum>(8);
31 for (EtherTypeEnum e : EtherTypeEnum.values())
34 public static EtherTypeEnum byId(long id) { return byId.get(id); }
37 public EthernetFrame(KaitaiStream _io) {
38 this(_io, null, null);
41 public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent) {
42 this(_io, _parent, null);
45 public EthernetFrame(KaitaiStream _io, KaitaiStruct _parent, EthernetFrame _root) {
47 this._parent = _parent;
48 this._root = _root == null ? this : _root;
51 private void _read() {
52 this.dstMac = this._io.readBytes(6);
53 this.srcMac = this._io.readBytes(6);
54 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);
68 this._raw_body = this._io.readBytesFull();
69 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
70 this.body = new Ipv6Packet(_io__raw_body);
74 this.body = this._io.readBytesFull();
80 private byte[] dstMac;
81 private byte[] srcMac;
82 private EtherTypeEnum etherType;
84 private EthernetFrame _root;
85 private KaitaiStruct _parent;
86 private byte[] _raw_body;
87 public byte[] dstMac() { return dstMac; }
88 public byte[] srcMac() { return srcMac; }
89 public EtherTypeEnum etherType() { return etherType; }
90 public Object body() { return body; }
91 public EthernetFrame _root() { return _root; }
92 public KaitaiStruct _parent() { return _parent; }
93 public byte[] _raw_body() { return _raw_body; }