c05209079623858788a830419d835f533e27c046
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / Pcap.java
1 // This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2 package edu.uci.iotproject;
3
4 import io.kaitai.struct.ByteBufferKaitaiStream;
5 import io.kaitai.struct.KaitaiStruct;
6 import io.kaitai.struct.KaitaiStream;
7 import java.io.IOException;
8 import java.util.Map;
9 import java.util.HashMap;
10 import java.util.ArrayList;
11
12
13 /**
14  * @see <a href="http://wiki.wireshark.org/Development/LibpcapFileFormat">Source</a>
15  */
16 public class Pcap extends KaitaiStruct {
17     public static Pcap fromFile(String fileName) throws IOException {
18         return new Pcap(new ByteBufferKaitaiStream(fileName));
19     }
20
21     public enum Linktype {
22         NULL_LINKTYPE(0),
23         ETHERNET(1),
24         AX25(3),
25         IEEE802_5(6),
26         ARCNET_BSD(7),
27         SLIP(8),
28         PPP(9),
29         FDDI(10),
30         PPP_HDLC(50),
31         PPP_ETHER(51),
32         ATM_RFC1483(100),
33         RAW(101),
34         C_HDLC(104),
35         IEEE802_11(105),
36         FRELAY(107),
37         LOOP(108),
38         LINUX_SLL(113),
39         LTALK(114),
40         PFLOG(117),
41         IEEE802_11_PRISM(119),
42         IP_OVER_FC(122),
43         SUNATM(123),
44         IEEE802_11_RADIOTAP(127),
45         ARCNET_LINUX(129),
46         APPLE_IP_OVER_IEEE1394(138),
47         MTP2_WITH_PHDR(139),
48         MTP2(140),
49         MTP3(141),
50         SCCP(142),
51         DOCSIS(143),
52         LINUX_IRDA(144),
53         USER0(147),
54         USER1(148),
55         USER2(149),
56         USER3(150),
57         USER4(151),
58         USER5(152),
59         USER6(153),
60         USER7(154),
61         USER8(155),
62         USER9(156),
63         USER10(157),
64         USER11(158),
65         USER12(159),
66         USER13(160),
67         USER14(161),
68         USER15(162),
69         IEEE802_11_AVS(163),
70         BACNET_MS_TP(165),
71         PPP_PPPD(166),
72         GPRS_LLC(169),
73         GPF_T(170),
74         GPF_F(171),
75         LINUX_LAPD(177),
76         BLUETOOTH_HCI_H4(187),
77         USB_LINUX(189),
78         PPI(192),
79         IEEE802_15_4(195),
80         SITA(196),
81         ERF(197),
82         BLUETOOTH_HCI_H4_WITH_PHDR(201),
83         AX25_KISS(202),
84         LAPD(203),
85         PPP_WITH_DIR(204),
86         C_HDLC_WITH_DIR(205),
87         FRELAY_WITH_DIR(206),
88         IPMB_LINUX(209),
89         IEEE802_15_4_NONASK_PHY(215),
90         USB_LINUX_MMAPPED(220),
91         FC_2(224),
92         FC_2_WITH_FRAME_DELIMS(225),
93         IPNET(226),
94         CAN_SOCKETCAN(227),
95         IPV4(228),
96         IPV6(229),
97         IEEE802_15_4_NOFCS(230),
98         DBUS(231),
99         DVB_CI(235),
100         MUX27010(236),
101         STANAG_5066_D_PDU(237),
102         NFLOG(239),
103         NETANALYZER(240),
104         NETANALYZER_TRANSPARENT(241),
105         IPOIB(242),
106         MPEG_2_TS(243),
107         NG40(244),
108         NFC_LLCP(245),
109         INFINIBAND(247),
110         SCTP(248),
111         USBPCAP(249),
112         RTAC_SERIAL(250),
113         BLUETOOTH_LE_LL(251),
114         NETLINK(253),
115         BLUETOOTH_LINUX_MONITOR(254),
116         BLUETOOTH_BREDR_BB(255),
117         BLUETOOTH_LE_LL_WITH_PHDR(256),
118         PROFIBUS_DL(257),
119         PKTAP(258),
120         EPON(259),
121         IPMI_HPM_2(260),
122         ZWAVE_R1_R2(261),
123         ZWAVE_R3(262),
124         WATTSTOPPER_DLM(263),
125         ISO_14443(264);
126
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);
131         static {
132             for (Linktype e : Linktype.values())
133                 byId.put(e.id(), e);
134         }
135         public static Linktype byId(long id) { return byId.get(id); }
136     }
137
138     public Pcap(KaitaiStream _io) {
139         this(_io, null, null);
140     }
141
142     public Pcap(KaitaiStream _io, KaitaiStruct _parent) {
143         this(_io, _parent, null);
144     }
145
146     public Pcap(KaitaiStream _io, KaitaiStruct _parent, Pcap _root) {
147         super(_io);
148         this._parent = _parent;
149         this._root = _root == null ? this : _root;
150         _read();
151     }
152     private void _read() {
153         this.hdr = new Header(this._io, this, _root);
154         this.packets = new ArrayList<Packet>();
155         {
156             int i = 0;
157             while (!this._io.isEof()) {
158                 this.packets.add(new Packet(this._io, this, _root));
159                 i++;
160             }
161         }
162     }
163
164     /**
165      * @see <a href="https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header">Source</a>
166      */
167     public static class Header extends KaitaiStruct {
168         public static Header fromFile(String fileName) throws IOException {
169             return new Header(new ByteBufferKaitaiStream(fileName));
170         }
171
172         public Header(KaitaiStream _io) {
173             this(_io, null, null);
174         }
175
176         public Header(KaitaiStream _io, Pcap _parent) {
177             this(_io, _parent, null);
178         }
179
180         public Header(KaitaiStream _io, Pcap _parent, Pcap _root) {
181             super(_io);
182             this._parent = _parent;
183             this._root = _root;
184             _read();
185         }
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());
194         }
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;
202         private Pcap _root;
203         private Pcap _parent;
204         public byte[] magicNumber() { return magicNumber; }
205         public int versionMajor() { return versionMajor; }
206         public int versionMinor() { return versionMinor; }
207
208         /**
209          * Correction time in seconds between UTC and the local
210          * timezone of the following packet header timestamps.
211          */
212         public int thiszone() { return thiszone; }
213
214         /**
215          * In theory, the accuracy of time stamps in the capture; in
216          * practice, all tools set it to 0.
217          */
218         public long sigfigs() { return sigfigs; }
219
220         /**
221          * The "snapshot length" for the capture (typically 65535 or
222          * even more, but might be limited by the user), see: incl_len
223          * vs. orig_len.
224          */
225         public long snaplen() { return snaplen; }
226
227         /**
228          * Link-layer header type, specifying the type of headers at
229          * the beginning of the packet.
230          */
231         public Linktype network() { return network; }
232         public Pcap _root() { return _root; }
233         public Pcap _parent() { return _parent; }
234     }
235
236     /**
237      * @see <a href="https://wiki.wireshark.org/Development/LibpcapFileFormat#Record_.28Packet.29_Header">Source</a>
238      */
239     public static class Packet extends KaitaiStruct {
240         public static Packet fromFile(String fileName) throws IOException {
241             return new Packet(new ByteBufferKaitaiStream(fileName));
242         }
243
244         public Packet(KaitaiStream _io) {
245             this(_io, null, null);
246         }
247
248         public Packet(KaitaiStream _io, Pcap _parent) {
249             this(_io, _parent, null);
250         }
251
252         public Packet(KaitaiStream _io, Pcap _parent, Pcap _root) {
253             super(_io);
254             this._parent = _parent;
255             this._root = _root;
256             _read();
257         }
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()) {
264             case PPI: {
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);
268                 break;
269             }
270             case ETHERNET: {
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);
274                 break;
275             }
276             default: {
277                 this.body = this._io.readBytes(inclLen());
278                 break;
279             }
280             }
281         }
282         private long tsSec;
283         private long tsUsec;
284         private long inclLen;
285         private long origLen;
286         private Object body;
287         private Pcap _root;
288         private Pcap _parent;
289         private byte[] _raw_body;
290         public long tsSec() { return tsSec; }
291         public long tsUsec() { return tsUsec; }
292
293         /**
294          * Number of bytes of packet data actually captured and saved in the file.
295          */
296         public long inclLen() { return inclLen; }
297
298         /**
299          * Length of the packet as it appeared on the network when it was captured.
300          */
301         public long origLen() { return origLen; }
302
303         /**
304          * @see <a href="https://wiki.wireshark.org/Development/LibpcapFileFormat#Packet_Data">Source</a>
305          */
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; }
310     }
311     private Header hdr;
312     private ArrayList<Packet> packets;
313     private Pcap _root;
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; }
319 }