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;
14 * @see <a href="http://wiki.wireshark.org/Development/LibpcapFileFormat">Source</a>
16 public class Pcap extends KaitaiStruct {
17 public static Pcap fromFile(String fileName) throws IOException {
18 return new Pcap(new ByteBufferKaitaiStream(fileName));
21 public enum Linktype {
41 IEEE802_11_PRISM(119),
44 IEEE802_11_RADIOTAP(127),
46 APPLE_IP_OVER_IEEE1394(138),
76 BLUETOOTH_HCI_H4(187),
82 BLUETOOTH_HCI_H4_WITH_PHDR(201),
89 IEEE802_15_4_NONASK_PHY(215),
90 USB_LINUX_MMAPPED(220),
92 FC_2_WITH_FRAME_DELIMS(225),
97 IEEE802_15_4_NOFCS(230),
101 STANAG_5066_D_PDU(237),
104 NETANALYZER_TRANSPARENT(241),
113 BLUETOOTH_LE_LL(251),
115 BLUETOOTH_LINUX_MONITOR(254),
116 BLUETOOTH_BREDR_BB(255),
117 BLUETOOTH_LE_LL_WITH_PHDR(256),
124 WATTSTOPPER_DLM(263),
127 private final long id;
128 Linktype(long id) { this.id = id; }
129 public long id() { return id; }
130 private static final Map<Long, Linktype> byId = new HashMap<Long, Linktype>(104);
132 for (Linktype e : Linktype.values())
135 public static Linktype byId(long id) { return byId.get(id); }
138 public Pcap(KaitaiStream _io) {
139 this(_io, null, null);
142 public Pcap(KaitaiStream _io, KaitaiStruct _parent) {
143 this(_io, _parent, null);
146 public Pcap(KaitaiStream _io, KaitaiStruct _parent, Pcap _root) {
148 this._parent = _parent;
149 this._root = _root == null ? this : _root;
152 private void _read() {
153 this.hdr = new Header(this._io, this, _root);
154 this.packets = new ArrayList<Packet>();
157 while (!this._io.isEof()) {
158 this.packets.add(new Packet(this._io, this, _root));
165 * @see <a href="https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header">Source</a>
167 public static class Header extends KaitaiStruct {
168 public static Header fromFile(String fileName) throws IOException {
169 return new Header(new ByteBufferKaitaiStream(fileName));
172 public Header(KaitaiStream _io) {
173 this(_io, null, null);
176 public Header(KaitaiStream _io, Pcap _parent) {
177 this(_io, _parent, null);
180 public Header(KaitaiStream _io, Pcap _parent, Pcap _root) {
182 this._parent = _parent;
186 private void _read() {
187 this.magicNumber = this._io.ensureFixedContents(new byte[] { -44, -61, -78, -95 });
188 this.versionMajor = this._io.readU2le();
189 this.versionMinor = this._io.readU2le();
190 this.thiszone = this._io.readS4le();
191 this.sigfigs = this._io.readU4le();
192 this.snaplen = this._io.readU4le();
193 this.network = Pcap.Linktype.byId(this._io.readU4le());
195 private byte[] magicNumber;
196 private int versionMajor;
197 private int versionMinor;
198 private int thiszone;
199 private long sigfigs;
200 private long snaplen;
201 private Linktype network;
203 private Pcap _parent;
204 public byte[] magicNumber() { return magicNumber; }
205 public int versionMajor() { return versionMajor; }
206 public int versionMinor() { return versionMinor; }
209 * Correction time in seconds between UTC and the local
210 * timezone of the following packet header timestamps.
212 public int thiszone() { return thiszone; }
215 * In theory, the accuracy of time stamps in the capture; in
216 * practice, all tools set it to 0.
218 public long sigfigs() { return sigfigs; }
221 * The "snapshot length" for the capture (typically 65535 or
222 * even more, but might be limited by the user), see: incl_len
225 public long snaplen() { return snaplen; }
228 * Link-layer header type, specifying the type of headers at
229 * the beginning of the packet.
231 public Linktype network() { return network; }
232 public Pcap _root() { return _root; }
233 public Pcap _parent() { return _parent; }
237 * @see <a href="https://wiki.wireshark.org/Development/LibpcapFileFormat#Record_.28Packet.29_Header">Source</a>
239 public static class Packet extends KaitaiStruct {
240 public static Packet fromFile(String fileName) throws IOException {
241 return new Packet(new ByteBufferKaitaiStream(fileName));
244 public Packet(KaitaiStream _io) {
245 this(_io, null, null);
248 public Packet(KaitaiStream _io, Pcap _parent) {
249 this(_io, _parent, null);
252 public Packet(KaitaiStream _io, Pcap _parent, Pcap _root) {
254 this._parent = _parent;
258 private void _read() {
259 this.tsSec = this._io.readU4le();
260 this.tsUsec = this._io.readU4le();
261 this.inclLen = this._io.readU4le();
262 this.origLen = this._io.readU4le();
263 switch (_root.hdr().network()) {
265 this._raw_body = this._io.readBytes(inclLen());
266 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
267 this.body = new PacketPpi(_io__raw_body);
271 this._raw_body = this._io.readBytes(inclLen());
272 KaitaiStream _io__raw_body = new ByteBufferKaitaiStream(_raw_body);
273 this.body = new EthernetFrame(_io__raw_body);
277 this.body = this._io.readBytes(inclLen());
284 private long inclLen;
285 private long origLen;
288 private Pcap _parent;
289 private byte[] _raw_body;
290 public long tsSec() { return tsSec; }
291 public long tsUsec() { return tsUsec; }
294 * Number of bytes of packet data actually captured and saved in the file.
296 public long inclLen() { return inclLen; }
299 * Length of the packet as it appeared on the network when it was captured.
301 public long origLen() { return origLen; }
304 * @see <a href="https://wiki.wireshark.org/Development/LibpcapFileFormat#Packet_Data">Source</a>
306 public Object body() { return body; }
307 public Pcap _root() { return _root; }
308 public Pcap _parent() { return _parent; }
309 public byte[] _raw_body() { return _raw_body; }
312 private ArrayList<Packet> packets;
314 private KaitaiStruct _parent;
315 public Header hdr() { return hdr; }
316 public ArrayList<Packet> packets() { return packets; }
317 public Pcap _root() { return _root; }
318 public KaitaiStruct _parent() { return _parent; }