b1ff070916f1037027622e35795b93543259563e
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / Ipv4Packet.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 public class Ipv4Packet extends KaitaiStruct {
13     public static Ipv4Packet fromFile(String fileName) throws IOException {
14         return new Ipv4Packet(new ByteBufferKaitaiStream(fileName));
15     }
16
17     public enum ProtocolEnum {
18         HOPOPT(0),
19         ICMP(1),
20         IGMP(2),
21         GGP(3),
22         IPV4(4),
23         ST(5),
24         TCP(6),
25         CBT(7),
26         EGP(8),
27         IGP(9),
28         BBN_RCC_MON(10),
29         NVP_II(11),
30         PUP(12),
31         ARGUS(13),
32         EMCON(14),
33         XNET(15),
34         CHAOS(16),
35         UDP(17),
36         MUX(18),
37         DCN_MEAS(19),
38         HMP(20),
39         PRM(21),
40         XNS_IDP(22),
41         TRUNK_1(23),
42         TRUNK_2(24),
43         LEAF_1(25),
44         LEAF_2(26),
45         RDP(27),
46         IRTP(28),
47         ISO_TP4(29),
48         NETBLT(30),
49         MFE_NSP(31),
50         MERIT_INP(32),
51         DCCP(33),
52         X_3PC(34),
53         IDPR(35),
54         XTP(36),
55         DDP(37),
56         IDPR_CMTP(38),
57         TP_PLUS_PLUS(39),
58         IL(40),
59         IPV6(41),
60         SDRP(42),
61         IPV6_ROUTE(43),
62         IPV6_FRAG(44),
63         IDRP(45),
64         RSVP(46),
65         GRE(47),
66         DSR(48),
67         BNA(49),
68         ESP(50),
69         AH(51),
70         I_NLSP(52),
71         SWIPE(53),
72         NARP(54),
73         MOBILE(55),
74         TLSP(56),
75         SKIP(57),
76         IPV6_ICMP(58),
77         IPV6_NONXT(59),
78         IPV6_OPTS(60),
79         ANY_HOST_INTERNAL_PROTOCOL(61),
80         CFTP(62),
81         ANY_LOCAL_NETWORK(63),
82         SAT_EXPAK(64),
83         KRYPTOLAN(65),
84         RVD(66),
85         IPPC(67),
86         ANY_DISTRIBUTED_FILE_SYSTEM(68),
87         SAT_MON(69),
88         VISA(70),
89         IPCV(71),
90         CPNX(72),
91         CPHB(73),
92         WSN(74),
93         PVP(75),
94         BR_SAT_MON(76),
95         SUN_ND(77),
96         WB_MON(78),
97         WB_EXPAK(79),
98         ISO_IP(80),
99         VMTP(81),
100         SECURE_VMTP(82),
101         VINES(83),
102         IPTM(84),
103         NSFNET_IGP(85),
104         DGP(86),
105         TCF(87),
106         EIGRP(88),
107         OSPFIGP(89),
108         SPRITE_RPC(90),
109         LARP(91),
110         MTP(92),
111         AX_25(93),
112         IPIP(94),
113         MICP(95),
114         SCC_SP(96),
115         ETHERIP(97),
116         ENCAP(98),
117         ANY_PRIVATE_ENCRYPTION_SCHEME(99),
118         GMTP(100),
119         IFMP(101),
120         PNNI(102),
121         PIM(103),
122         ARIS(104),
123         SCPS(105),
124         QNX(106),
125         A_N(107),
126         IPCOMP(108),
127         SNP(109),
128         COMPAQ_PEER(110),
129         IPX_IN_IP(111),
130         VRRP(112),
131         PGM(113),
132         ANY_0_HOP(114),
133         L2TP(115),
134         DDX(116),
135         IATP(117),
136         STP(118),
137         SRP(119),
138         UTI(120),
139         SMP(121),
140         SM(122),
141         PTP(123),
142         ISIS_OVER_IPV4(124),
143         FIRE(125),
144         CRTP(126),
145         CRUDP(127),
146         SSCOPMCE(128),
147         IPLT(129),
148         SPS(130),
149         PIPE(131),
150         SCTP(132),
151         FC(133),
152         RSVP_E2E_IGNORE(134),
153         MOBILITY_HEADER(135),
154         UDPLITE(136),
155         MPLS_IN_IP(137),
156         MANET(138),
157         HIP(139),
158         SHIM6(140),
159         WESP(141),
160         ROHC(142),
161         RESERVED_255(255);
162
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);
167         static {
168             for (ProtocolEnum e : ProtocolEnum.values())
169                 byId.put(e.id(), e);
170         }
171         public static ProtocolEnum byId(long id) { return byId.get(id); }
172     }
173
174     public Ipv4Packet(KaitaiStream _io) {
175         this(_io, null, null);
176     }
177
178     public Ipv4Packet(KaitaiStream _io, KaitaiStruct _parent) {
179         this(_io, _parent, null);
180     }
181
182     public Ipv4Packet(KaitaiStream _io, KaitaiStruct _parent, Ipv4Packet _root) {
183         super(_io);
184         this._parent = _parent;
185         this._root = _root == null ? this : _root;
186         _read();
187     }
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()) {
203         case TCP: {
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);
207             break;
208         }
209         case ICMP: {
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);
213             break;
214         }
215         case UDP: {
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);
219             break;
220         }
221         case IPV6: {
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);
225             break;
226         }
227         default: {
228             this.body = this._io.readBytes((totalLength() - ihlBytes()));
229             break;
230         }
231         }
232     }
233     public static class Ipv4Options extends KaitaiStruct {
234         public static Ipv4Options fromFile(String fileName) throws IOException {
235             return new Ipv4Options(new ByteBufferKaitaiStream(fileName));
236         }
237
238         public Ipv4Options(KaitaiStream _io) {
239             this(_io, null, null);
240         }
241
242         public Ipv4Options(KaitaiStream _io, Ipv4Packet _parent) {
243             this(_io, _parent, null);
244         }
245
246         public Ipv4Options(KaitaiStream _io, Ipv4Packet _parent, Ipv4Packet _root) {
247             super(_io);
248             this._parent = _parent;
249             this._root = _root;
250             _read();
251         }
252         private void _read() {
253             this.entries = new ArrayList<Ipv4Option>();
254             {
255                 int i = 0;
256                 while (!this._io.isEof()) {
257                     this.entries.add(new Ipv4Option(this._io, this, _root));
258                     i++;
259                 }
260             }
261         }
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; }
268     }
269     public static class Ipv4Option extends KaitaiStruct {
270         public static Ipv4Option fromFile(String fileName) throws IOException {
271             return new Ipv4Option(new ByteBufferKaitaiStream(fileName));
272         }
273
274         public Ipv4Option(KaitaiStream _io) {
275             this(_io, null, null);
276         }
277
278         public Ipv4Option(KaitaiStream _io, Ipv4Packet.Ipv4Options _parent) {
279             this(_io, _parent, null);
280         }
281
282         public Ipv4Option(KaitaiStream _io, Ipv4Packet.Ipv4Options _parent, Ipv4Packet _root) {
283             super(_io);
284             this._parent = _parent;
285             this._root = _root;
286             _read();
287         }
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));
292         }
293         private Integer copy;
294         public Integer copy() {
295             if (this.copy != null)
296                 return this.copy;
297             int _tmp = (int) (((b1() & 128) >> 7));
298             this.copy = _tmp;
299             return this.copy;
300         }
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;
308         }
309         private Integer number;
310         public Integer number() {
311             if (this.number != null)
312                 return this.number;
313             int _tmp = (int) ((b1() & 31));
314             this.number = _tmp;
315             return this.number;
316         }
317         private int b1;
318         private int len;
319         private byte[] body;
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; }
327     }
328     private Integer version;
329     public Integer version() {
330         if (this.version != null)
331             return this.version;
332         int _tmp = (int) (((b1() & 240) >> 4));
333         this.version = _tmp;
334         return this.version;
335     }
336     private Integer ihl;
337     public Integer ihl() {
338         if (this.ihl != null)
339             return this.ihl;
340         int _tmp = (int) ((b1() & 15));
341         this.ihl = _tmp;
342         return this.ihl;
343     }
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;
351     }
352     private int b1;
353     private int b2;
354     private int totalLength;
355     private int identification;
356     private int b67;
357     private int ttl;
358     private ProtocolEnum protocol;
359     private int headerChecksum;
360     private byte[] srcIpAddr;
361     private byte[] dstIpAddr;
362     private Ipv4Options options;
363     private Object body;
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; }
384 }