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;
10 import java.util.ArrayList;
12 public class Ipv4Packet extends KaitaiStruct {
13 public static Ipv4Packet fromFile(String fileName) throws IOException {
14 return new Ipv4Packet(new ByteBufferKaitaiStream(fileName));
17 public enum ProtocolEnum {
79 ANY_HOST_INTERNAL_PROTOCOL(61),
81 ANY_LOCAL_NETWORK(63),
86 ANY_DISTRIBUTED_FILE_SYSTEM(68),
117 ANY_PRIVATE_ENCRYPTION_SCHEME(99),
152 RSVP_E2E_IGNORE(134),
153 MOBILITY_HEADER(135),
163 private final long id;
164 ProtocolEnum(long id) { this.id = id; }
165 public long id() { return id; }
166 private static final Map<Long, ProtocolEnum> byId = new HashMap<Long, ProtocolEnum>(144);
168 for (ProtocolEnum e : ProtocolEnum.values())
171 public static ProtocolEnum byId(long id) { return byId.get(id); }
174 public Ipv4Packet(KaitaiStream _io) {
175 this(_io, null, null);
178 public Ipv4Packet(KaitaiStream _io, KaitaiStruct _parent) {
179 this(_io, _parent, null);
182 public Ipv4Packet(KaitaiStream _io, KaitaiStruct _parent, Ipv4Packet _root) {
184 this._parent = _parent;
185 this._root = _root == null ? this : _root;
188 private void _read() {
189 this.b1 = this._io.readU1();
190 this.b2 = this._io.readU1();
191 this.totalLength = this._io.readU2be();
192 this.identification = this._io.readU2be();
193 this.b67 = this._io.readU2be();
194 this.ttl = this._io.readU1();
195 this.protocol = ProtocolEnum.byId(this._io.readU1());
196 this.headerChecksum = this._io.readU2be();
197 this.srcIpAddr = this._io.readBytes(4);
198 this.dstIpAddr = this._io.readBytes(4);
199 this._raw_options = this._io.readBytes((ihlBytes() - 20));
200 KaitaiStream _io__raw_options = new ByteBufferKaitaiStream(_raw_options);
201 this.options = new Ipv4Options(_io__raw_options, this, _root);
202 switch (protocol()) {
204 this._raw_body = this._io.readBytes((totalLength() - ihlBytes()));
205 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
206 this.body = new TcpSegment(_io__raw_body);
210 this._raw_body = this._io.readBytes((totalLength() - ihlBytes()));
211 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
212 this.body = new IcmpPacket(_io__raw_body);
216 this._raw_body = this._io.readBytes((totalLength() - ihlBytes()));
217 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
218 this.body = new UdpDatagram(_io__raw_body);
222 this._raw_body = this._io.readBytes((totalLength() - ihlBytes()));
223 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
224 this.body = new Ipv6Packet(_io__raw_body);
228 this.body = this._io.readBytes((totalLength() - ihlBytes()));
233 public static class Ipv4Options extends KaitaiStruct {
234 public static Ipv4Options fromFile(String fileName) throws IOException {
235 return new Ipv4Options(new ByteBufferKaitaiStream(fileName));
238 public Ipv4Options(KaitaiStream _io) {
239 this(_io, null, null);
242 public Ipv4Options(KaitaiStream _io, Ipv4Packet _parent) {
243 this(_io, _parent, null);
246 public Ipv4Options(KaitaiStream _io, Ipv4Packet _parent, Ipv4Packet _root) {
248 this._parent = _parent;
252 private void _read() {
253 this.entries = new ArrayList<Ipv4Option>();
256 while (!this._io.isEof()) {
257 this.entries.add(new Ipv4Option(this._io, this, _root));
262 private ArrayList<Ipv4Option> entries;
263 private Ipv4Packet _root;
264 private Ipv4Packet _parent;
265 public ArrayList<Ipv4Option> entries() { return entries; }
266 public Ipv4Packet _root() { return _root; }
267 public Ipv4Packet _parent() { return _parent; }
269 public static class Ipv4Option extends KaitaiStruct {
270 public static Ipv4Option fromFile(String fileName) throws IOException {
271 return new Ipv4Option(new ByteBufferKaitaiStream(fileName));
274 public Ipv4Option(KaitaiStream _io) {
275 this(_io, null, null);
278 public Ipv4Option(KaitaiStream _io, Ipv4Packet.Ipv4Options _parent) {
279 this(_io, _parent, null);
282 public Ipv4Option(KaitaiStream _io, Ipv4Packet.Ipv4Options _parent, Ipv4Packet _root) {
284 this._parent = _parent;
288 private void _read() {
289 this.b1 = this._io.readU1();
290 this.len = this._io.readU1();
291 this.body = this._io.readBytes((len() > 2 ? (len() - 2) : 0));
293 private Integer copy;
294 public Integer copy() {
295 if (this.copy != null)
297 int _tmp = (int) (((b1() & 128) >> 7));
301 private Integer optClass;
302 public Integer optClass() {
303 if (this.optClass != null)
304 return this.optClass;
305 int _tmp = (int) (((b1() & 96) >> 5));
306 this.optClass = _tmp;
307 return this.optClass;
309 private Integer number;
310 public Integer number() {
311 if (this.number != null)
313 int _tmp = (int) ((b1() & 31));
320 private Ipv4Packet _root;
321 private Ipv4Packet.Ipv4Options _parent;
322 public int b1() { return b1; }
323 public int len() { return len; }
324 public byte[] body() { return body; }
325 public Ipv4Packet _root() { return _root; }
326 public Ipv4Packet.Ipv4Options _parent() { return _parent; }
328 private Integer version;
329 public Integer version() {
330 if (this.version != null)
332 int _tmp = (int) (((b1() & 240) >> 4));
337 public Integer ihl() {
338 if (this.ihl != null)
340 int _tmp = (int) ((b1() & 15));
344 private Integer ihlBytes;
345 public Integer ihlBytes() {
346 if (this.ihlBytes != null)
347 return this.ihlBytes;
348 int _tmp = (int) ((ihl() * 4));
349 this.ihlBytes = _tmp;
350 return this.ihlBytes;
354 private int totalLength;
355 private int identification;
358 private ProtocolEnum protocol;
359 private int headerChecksum;
360 private byte[] srcIpAddr;
361 private byte[] dstIpAddr;
362 private Ipv4Options options;
364 private Ipv4Packet _root;
365 private KaitaiStruct _parent;
366 private byte[] _raw_options;
367 private byte[] _raw_body;
368 public int b1() { return b1; }
369 public int b2() { return b2; }
370 public int totalLength() { return totalLength; }
371 public int identification() { return identification; }
372 public int b67() { return b67; }
373 public int ttl() { return ttl; }
374 public ProtocolEnum protocol() { return protocol; }
375 public int headerChecksum() { return headerChecksum; }
376 public byte[] srcIpAddr() { return srcIpAddr; }
377 public byte[] dstIpAddr() { return dstIpAddr; }
378 public Ipv4Options options() { return options; }
379 public Object body() { return body; }
380 public Ipv4Packet _root() { return _root; }
381 public KaitaiStruct _parent() { return _parent; }
382 public byte[] _raw_options() { return _raw_options; }
383 public byte[] _raw_body() { return _raw_body; }