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 IcmpPacket extends KaitaiStruct {
12 public static IcmpPacket fromFile(String fileName) throws IOException {
13 return new IcmpPacket(new ByteBufferKaitaiStream(fileName));
16 public enum IcmpTypeEnum {
18 DESTINATION_UNREACHABLE(3),
24 private final long id;
25 IcmpTypeEnum(long id) { this.id = id; }
26 public long id() { return id; }
27 private static final Map<Long, IcmpTypeEnum> byId = new HashMap<Long, IcmpTypeEnum>(6);
29 for (IcmpTypeEnum e : IcmpTypeEnum.values())
32 public static IcmpTypeEnum byId(long id) { return byId.get(id); }
35 public IcmpPacket(KaitaiStream _io) {
36 this(_io, null, null);
39 public IcmpPacket(KaitaiStream _io, KaitaiStruct _parent) {
40 this(_io, _parent, null);
43 public IcmpPacket(KaitaiStream _io, KaitaiStruct _parent, IcmpPacket _root) {
45 this._parent = _parent;
46 this._root = _root == null ? this : _root;
49 private void _read() {
50 this.icmpType = IcmpTypeEnum.byId(this._io.readU1());
51 if (icmpType() == IcmpTypeEnum.DESTINATION_UNREACHABLE) {
52 this.destinationUnreachable = new DestinationUnreachableMsg(this._io, this, _root);
54 if (icmpType() == IcmpTypeEnum.TIME_EXCEEDED) {
55 this.timeExceeded = new TimeExceededMsg(this._io, this, _root);
57 if ( ((icmpType() == IcmpTypeEnum.ECHO) || (icmpType() == IcmpTypeEnum.ECHO_REPLY)) ) {
58 this.echo = new EchoMsg(this._io, this, _root);
61 public static class DestinationUnreachableMsg extends KaitaiStruct {
62 public static DestinationUnreachableMsg fromFile(String fileName) throws IOException {
63 return new DestinationUnreachableMsg(new ByteBufferKaitaiStream(fileName));
66 public enum DestinationUnreachableCode {
69 PROTOCOL_UNREACHABLE(2),
71 FRAGMENTATION_NEEDED_AND_DF_SET(4),
72 SOURCE_ROUTE_FAILED(5),
76 NET_PROHIBITED_BY_ADMIN(9),
77 HOST_PROHIBITED_BY_ADMIN(10),
78 NET_UNREACHABLE_FOR_TOS(11),
79 HOST_UNREACHABLE_FOR_TOS(12),
80 COMMUNICATION_PROHIBITED_BY_ADMIN(13),
81 HOST_PRECEDENCE_VIOLATION(14),
82 PRECEDENCE_CUTTOFF_IN_EFFECT(15);
84 private final long id;
85 DestinationUnreachableCode(long id) { this.id = id; }
86 public long id() { return id; }
87 private static final Map<Long, DestinationUnreachableCode> byId = new HashMap<Long, DestinationUnreachableCode>(16);
89 for (DestinationUnreachableCode e : DestinationUnreachableCode.values())
92 public static DestinationUnreachableCode byId(long id) { return byId.get(id); }
95 public DestinationUnreachableMsg(KaitaiStream _io) {
96 this(_io, null, null);
99 public DestinationUnreachableMsg(KaitaiStream _io, IcmpPacket _parent) {
100 this(_io, _parent, null);
103 public DestinationUnreachableMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) {
105 this._parent = _parent;
109 private void _read() {
110 this.code = DestinationUnreachableCode.byId(this._io.readU1());
111 this.checksum = this._io.readU2be();
113 private DestinationUnreachableCode code;
114 private int checksum;
115 private IcmpPacket _root;
116 private IcmpPacket _parent;
117 public DestinationUnreachableCode code() { return code; }
118 public int checksum() { return checksum; }
119 public IcmpPacket _root() { return _root; }
120 public IcmpPacket _parent() { return _parent; }
122 public static class TimeExceededMsg extends KaitaiStruct {
123 public static TimeExceededMsg fromFile(String fileName) throws IOException {
124 return new TimeExceededMsg(new ByteBufferKaitaiStream(fileName));
127 public enum TimeExceededCode {
128 TIME_TO_LIVE_EXCEEDED_IN_TRANSIT(0),
129 FRAGMENT_REASSEMBLY_TIME_EXCEEDED(1);
131 private final long id;
132 TimeExceededCode(long id) { this.id = id; }
133 public long id() { return id; }
134 private static final Map<Long, TimeExceededCode> byId = new HashMap<Long, TimeExceededCode>(2);
136 for (TimeExceededCode e : TimeExceededCode.values())
139 public static TimeExceededCode byId(long id) { return byId.get(id); }
142 public TimeExceededMsg(KaitaiStream _io) {
143 this(_io, null, null);
146 public TimeExceededMsg(KaitaiStream _io, IcmpPacket _parent) {
147 this(_io, _parent, null);
150 public TimeExceededMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) {
152 this._parent = _parent;
156 private void _read() {
157 this.code = TimeExceededCode.byId(this._io.readU1());
158 this.checksum = this._io.readU2be();
160 private TimeExceededCode code;
161 private int checksum;
162 private IcmpPacket _root;
163 private IcmpPacket _parent;
164 public TimeExceededCode code() { return code; }
165 public int checksum() { return checksum; }
166 public IcmpPacket _root() { return _root; }
167 public IcmpPacket _parent() { return _parent; }
169 public static class EchoMsg extends KaitaiStruct {
170 public static EchoMsg fromFile(String fileName) throws IOException {
171 return new EchoMsg(new ByteBufferKaitaiStream(fileName));
174 public EchoMsg(KaitaiStream _io) {
175 this(_io, null, null);
178 public EchoMsg(KaitaiStream _io, IcmpPacket _parent) {
179 this(_io, _parent, null);
182 public EchoMsg(KaitaiStream _io, IcmpPacket _parent, IcmpPacket _root) {
184 this._parent = _parent;
188 private void _read() {
189 this.code = this._io.ensureFixedContents(new byte[] { 0 });
190 this.checksum = this._io.readU2be();
191 this.identifier = this._io.readU2be();
192 this.seqNum = this._io.readU2be();
193 this.data = this._io.readBytesFull();
196 private int checksum;
197 private int identifier;
200 private IcmpPacket _root;
201 private IcmpPacket _parent;
202 public byte[] code() { return code; }
203 public int checksum() { return checksum; }
204 public int identifier() { return identifier; }
205 public int seqNum() { return seqNum; }
206 public byte[] data() { return data; }
207 public IcmpPacket _root() { return _root; }
208 public IcmpPacket _parent() { return _parent; }
210 private IcmpTypeEnum icmpType;
211 private DestinationUnreachableMsg destinationUnreachable;
212 private TimeExceededMsg timeExceeded;
213 private EchoMsg echo;
214 private IcmpPacket _root;
215 private KaitaiStruct _parent;
216 public IcmpTypeEnum icmpType() { return icmpType; }
217 public DestinationUnreachableMsg destinationUnreachable() { return destinationUnreachable; }
218 public TimeExceededMsg timeExceeded() { return timeExceeded; }
219 public EchoMsg echo() { return echo; }
220 public IcmpPacket _root() { return _root; }
221 public KaitaiStruct _parent() { return _parent; }