1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
#include "gtest_utils.h"
#include "packet_io.h"
/*
* Frame 3: 66 bytes on wire (528 bits), 66 bytes captured (528 bits)
* Encapsulation type: Ethernet (1)
* Arrival Time: Mar 1, 2019 11:22:58.243662000 CST
* [Time shift for this packet: 0.000000000 seconds]
* Epoch Time: 1551410578.243662000 seconds
* [Time delta from previous captured frame: 0.000428000 seconds]
* [Time delta from previous displayed frame: 0.000428000 seconds]
* [Time since reference or first frame: 0.000474000 seconds]
* Frame Number: 3
* Frame Length: 66 bytes (528 bits)
* Capture Length: 66 bytes (528 bits)
* [Frame is marked: False]
* [Frame is ignored: False]
* [Protocols in frame: eth:ethertype:ip:tcp]
* [Coloring Rule Name: TCP]
* [Coloring Rule String: tcp]
* Ethernet II, Src: 76:fc:ca:ef:29:28 (76:fc:ca:ef:29:28), Dst: AdlinkTe_4b:58:64 (00:30:64:4b:58:64)
* Destination: AdlinkTe_4b:58:64 (00:30:64:4b:58:64)
* Address: AdlinkTe_4b:58:64 (00:30:64:4b:58:64)
* .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
* .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
* Source: 76:fc:ca:ef:29:28 (76:fc:ca:ef:29:28)
* Address: 76:fc:ca:ef:29:28 (76:fc:ca:ef:29:28)
* .... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
* .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
* Type: IPv4 (0x0800)
* Internet Protocol Version 4, Src: 192.168.10.250, Dst: 192.168.10.234
* 0100 .... = Version: 4
* .... 0101 = Header Length: 20 bytes (5)
* Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
* 0000 00.. = Differentiated Services Codepoint: Default (0)
* .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
* Total Length: 52
* Identification: 0x4878 (18552)
* 010. .... = Flags: 0x2, Don't fragment
* 0... .... = Reserved bit: Not set
* .1.. .... = Don't fragment: Set
* ..0. .... = More fragments: Not set
* ...0 0000 0000 0000 = Fragment Offset: 0
* Time to Live: 127
* Protocol: TCP (6)
* Header Checksum: 0x1c17 [correct]
* [Header checksum status: Good]
* [Calculated Checksum: 0x1c17]
* Source Address: 192.168.10.250
* Destination Address: 192.168.10.234
* Transmission Control Protocol, Src Port: 58725, Dst Port: 22, Seq: 1, Ack: 1, Len: 0
* Source Port: 58725
* Destination Port: 22
* [Stream index: 0]
* [Conversation completeness: Complete, WITH_DATA (31)]
* [TCP Segment Len: 0]
* Sequence Number: 1 (relative sequence number)
* Sequence Number (raw): 2587138324
* [Next Sequence Number: 1 (relative sequence number)]
* Acknowledgment Number: 1 (relative ack number)
* Acknowledgment number (raw): 2046996948
* 1000 .... = Header Length: 32 bytes (8)
* Flags: 0x010 (ACK)
* 000. .... .... = Reserved: Not set
* ...0 .... .... = Accurate ECN: Not set
* .... 0... .... = Congestion Window Reduced: Not set
* .... .0.. .... = ECN-Echo: Not set
* .... ..0. .... = Urgent: Not set
* .... ...1 .... = Acknowledgment: Set
* .... .... 0... = Push: Not set
* .... .... .0.. = Reset: Not set
* .... .... ..0. = Syn: Not set
* .... .... ...0 = Fin: Not set
* [TCP Flags: ·······A····]
* Window: 16646
* [Calculated window size: 66584]
* [Window size scaling factor: 4]
* Checksum: 0xa4ff [correct]
* [Checksum Status: Good]
* [Calculated Checksum: 0xa4ff]
* Urgent Pointer: 0
* Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
* TCP Option - No-Operation (NOP)
* Kind: No-Operation (1)
* TCP Option - No-Operation (NOP)
* Kind: No-Operation (1)
* TCP Option - Timestamps
* Kind: Time Stamp Option (8)
* Length: 10
* Timestamp value: 155719012: TSval 155719012, TSecr 1560361273
* Timestamp echo reply: 1560361273
* [Timestamps]
* [Time since first frame in this TCP stream: 0.000474000 seconds]
* [Time since previous frame in this TCP stream: 0.000428000 seconds]
* [SEQ/ACK analysis]
* [This is an ACK to the segment in frame: 2]
* [The RTT to ACK the segment was: 0.000428000 seconds]
* [iRTT: 0.000474000 seconds]
*/
static u_char data_packet1_no_vlan_layer[] = {
0x00, 0x30, 0x64, 0x4b, 0x58, 0x64, 0x76, 0xfc, 0xca, 0xef, 0x29, 0x28, 0x08, 0x00, /* ETH */
0x45, 0x00, 0x00, 0x34, 0x48, 0x78, 0x40, 0x00, 0x7f, 0x06, 0x1c, 0x17, 0xc0, 0xa8, 0x0a, 0xfa,
0xc0, 0xa8, 0x0a, 0xea, /* IPv4 */
0xe5, 0x65, 0x00, 0x16, 0x9a, 0x34, 0x99, 0x14, 0x7a, 0x02, 0xb1, 0xd4, 0x80, 0x10, 0x41, 0x06,
0xa4, 0xff, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x09, 0x48, 0x15, 0x64, 0x5d, 0x01, 0x39, 0x39 /* TCP */};
/*
* Frame 1: 70 bytes on wire (560 bits), 70 bytes captured (560 bits)
* Encapsulation type: Ethernet (1)
* Arrival Time: Nov 6, 1999 02:20:41.093005000 CST
* [Time shift for this packet: 0.000000000 seconds]
* Epoch Time: 941826041.093005000 seconds
* [Time delta from previous captured frame: 0.000000000 seconds]
* [Time delta from previous displayed frame: 0.000000000 seconds]
* [Time since reference or first frame: 0.000000000 seconds]
* Frame Number: 1
* Frame Length: 70 bytes (560 bits)
* Capture Length: 70 bytes (560 bits)
* [Frame is marked: False]
* [Frame is ignored: False]
* [Protocols in frame: eth:ethertype:vlan:ethertype:ip:tcp]
* [Coloring Rule Name: TCP]
* [Coloring Rule String: tcp]
* Ethernet II, Src: 3com_9f:b1:f3 (00:60:08:9f:b1:f3), Dst: AniCommu_40:ef:24 (00:40:05:40:ef:24)
* Destination: AniCommu_40:ef:24 (00:40:05:40:ef:24)
* Address: AniCommu_40:ef:24 (00:40:05:40:ef:24)
* .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
* .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
* Source: 3com_9f:b1:f3 (00:60:08:9f:b1:f3)
* Address: 3com_9f:b1:f3 (00:60:08:9f:b1:f3)
* .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
* .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
* Type: 802.1Q Virtual LAN (0x8100)
* 802.1Q Virtual LAN, PRI: 0, DEI: 0, ID: 32
* 000. .... .... .... = Priority: Best Effort (default) (0)
* ...0 .... .... .... = DEI: Ineligible
* .... 0000 0010 0000 = ID: 32
* Type: IPv4 (0x0800)
* Internet Protocol Version 4, Src: 131.151.32.21, Dst: 131.151.32.129
* 0100 .... = Version: 4
* .... 0101 = Header Length: 20 bytes (5)
* Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
* 0000 00.. = Differentiated Services Codepoint: Default (0)
* .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
* Total Length: 52
* Identification: 0x8a9b (35483)
* 010. .... = Flags: 0x2, Don't fragment
* 0... .... = Reserved bit: Not set
* .1.. .... = Don't fragment: Set
* ..0. .... = More fragments: Not set
* ...0 0000 0000 0000 = Fragment Offset: 0
* Time to Live: 64
* Protocol: TCP (6)
* Header Checksum: 0x6864 [correct]
* [Header checksum status: Good]
* [Calculated Checksum: 0x6864]
* Source Address: 131.151.32.21
* Destination Address: 131.151.32.129
* Transmission Control Protocol, Src Port: 6000, Dst Port: 1162, Seq: 1, Ack: 1, Len: 0
* Source Port: 6000
* Destination Port: 1162
* [Stream index: 0]
* [Conversation completeness: Incomplete (4)]
* [TCP Segment Len: 0]
* Sequence Number: 1 (relative sequence number)
* Sequence Number (raw): 1295870649
* [Next Sequence Number: 1 (relative sequence number)]
* Acknowledgment Number: 1 (relative ack number)
* Acknowledgment number (raw): 1310007649
* 1000 .... = Header Length: 32 bytes (8)
* Flags: 0x010 (ACK)
* 000. .... .... = Reserved: Not set
* ...0 .... .... = Accurate ECN: Not set
* .... 0... .... = Congestion Window Reduced: Not set
* .... .0.. .... = ECN-Echo: Not set
* .... ..0. .... = Urgent: Not set
* .... ...1 .... = Acknowledgment: Set
* .... .... 0... = Push: Not set
* .... .... .0.. = Reset: Not set
* .... .... ..0. = Syn: Not set
* .... .... ...0 = Fin: Not set
* [TCP Flags: ·······A····]
* Window: 31856
* [Calculated window size: 31856]
* [Window size scaling factor: -1 (unknown)]
* Checksum: 0xd7f9 [correct]
* [Checksum Status: Good]
* [Calculated Checksum: 0xd7f9]
* Urgent Pointer: 0
* Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
* TCP Option - No-Operation (NOP)
* Kind: No-Operation (1)
* TCP Option - No-Operation (NOP)
* Kind: No-Operation (1)
* TCP Option - Timestamps
* Kind: Time Stamp Option (8)
* Length: 10
* Timestamp value: 26846298: TSval 26846298, TSecr 323887
* Timestamp echo reply: 323887
* [Timestamps]
* [Time since first frame in this TCP stream: 0.000000000 seconds]
* [Time since previous frame in this TCP stream: 0.000000000 seconds]
*/
static u_char data_packet2_one_vlan_layer[] = {
0x00, 0x40, 0x05, 0x40, 0xef, 0x24, 0x00, 0x60, 0x08, 0x9f, 0xb1, 0xf3, 0x81, 0x00, /* ETH */
0x00, 0x20, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x34, 0x8a, 0x9b, 0x40, 0x00, 0x40, 0x06, 0x68, 0x64, 0x83, 0x97, 0x20, 0x15,
0x83, 0x97, 0x20, 0x81, /* IPv4 */
0x17, 0x70, 0x04, 0x8a, 0x4d, 0x3d, 0x6a, 0xb9, 0x4e, 0x15, 0x21, 0x61, 0x80, 0x10, 0x7c, 0x70,
0xd7, 0xf9, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x01, 0x99, 0xa4, 0x5a, 0x00, 0x04, 0xf1, 0x2f /* TCP */};
/*
* Frame 1: 122 bytes on wire (976 bits), 122 bytes captured (976 bits)
* Encapsulation type: Ethernet (1)
* Arrival Time: Jun 30, 2010 03:41:35.140128000 CST
* [Time shift for this packet: 0.000000000 seconds]
* Epoch Time: 1277840495.140128000 seconds
* [Time delta from previous captured frame: 0.000000000 seconds]
* [Time delta from previous displayed frame: 0.000000000 seconds]
* [Time since reference or first frame: 0.000000000 seconds]
* Frame Number: 1
* Frame Length: 122 bytes (976 bits)
* Capture Length: 122 bytes (976 bits)
* [Frame is marked: False]
* [Frame is ignored: False]
* [Protocols in frame: eth:ethertype:vlan:ethertype:vlan:ethertype:ip:tcp:data]
* [Coloring Rule Name: TCP]
* [Coloring Rule String: tcp]
* Ethernet II, Src: Cisco_df:ae:18 (00:13:c3:df:ae:18), Dst: Cisco_1b:a4:d8 (00:1b:d4:1b:a4:d8)
* Destination: Cisco_1b:a4:d8 (00:1b:d4:1b:a4:d8)
* Address: Cisco_1b:a4:d8 (00:1b:d4:1b:a4:d8)
* .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
* .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
* Source: Cisco_df:ae:18 (00:13:c3:df:ae:18)
* Address: Cisco_df:ae:18 (00:13:c3:df:ae:18)
* .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
* .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
* Type: 802.1Q Virtual LAN (0x8100)
* 802.1Q Virtual LAN, PRI: 0, DEI: 0, ID: 118
* 000. .... .... .... = Priority: Best Effort (default) (0)
* ...0 .... .... .... = DEI: Ineligible
* .... 0000 0111 0110 = ID: 118
* Type: 802.1Q Virtual LAN (0x8100)
* 802.1Q Virtual LAN, PRI: 0, DEI: 0, ID: 10
* 000. .... .... .... = Priority: Best Effort (default) (0)
* ...0 .... .... .... = DEI: Ineligible
* .... 0000 0000 1010 = ID: 10
* Type: IPv4 (0x0800)
* Internet Protocol Version 4, Src: 10.118.10.1, Dst: 10.118.10.2
* 0100 .... = Version: 4
* .... 0101 = Header Length: 20 bytes (5)
* Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
* 0000 00.. = Differentiated Services Codepoint: Default (0)
* .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
* Total Length: 100
* Identification: 0x0012 (18)
* 000. .... = Flags: 0x0
* 0... .... = Reserved bit: Not set
* .0.. .... = Don't fragment: Not set
* ..0. .... = More fragments: Not set
* ...0 0000 0000 0000 = Fragment Offset: 0
* Time to Live: 255
* Protocol: TCP (6)
* Header Checksum: 0x9293 [correct]
* [Header checksum status: Good]
* [Calculated Checksum: 0x9293]
* Source Address: 10.118.10.1
* Destination Address: 10.118.10.2
* Transmission Control Protocol, Src Port: 2048, Dst Port: 52912, Seq: 1, Ack: 1, Len: 60
* Source Port: 2048
* Destination Port: 52912
* [Stream index: 0]
* [Conversation completeness: Incomplete (8)]
* [TCP Segment Len: 60]
* Sequence Number: 1 (relative sequence number)
* Sequence Number (raw): 196611
* [Next Sequence Number: 61 (relative sequence number)]
* Acknowledgment Number: 1 (relative ack number)
* Acknowledgment number (raw): 0
* 0101 .... = Header Length: 20 bytes (5)
* Flags: 0x010 (ACK)
* 000. .... .... = Reserved: Not set
* ...0 .... .... = Accurate ECN: Not set
* .... 0... .... = Congestion Window Reduced: Not set
* .... .0.. .... = ECN-Echo: Not set
* .... ..0. .... = Urgent: Not set
* .... ...1 .... = Acknowledgment: Set
* .... .... 0... = Push: Not set
* .... .... .0.. = Reset: Not set
* .... .... ..0. = Syn: Not set
* .... .... ...0 = Fin: Not set
* [TCP Flags: ·······A····]
* Window: 44916
* [Calculated window size: 44916]
* [Window size scaling factor: -1 (unknown)]
* Checksum: 0x8965 [correct]
* [Checksum Status: Good]
* [Calculated Checksum: 0x8965]
* Urgent Pointer: 0
* [Timestamps]
* [Time since first frame in this TCP stream: 0.000000000 seconds]
* [Time since previous frame in this TCP stream: 0.000000000 seconds]
* [SEQ/ACK analysis]
* [Bytes in flight: 60]
* [Bytes sent since last PSH flag: 60]
* TCP payload (60 bytes)
* Data (60 bytes)
* Data: 00cdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd…
* [Length: 60]
*/
static u_char data_packet3_two_vlan_layer[] = {
0x00, 0x1b, 0xd4, 0x1b, 0xa4, 0xd8, 0x00, 0x13, 0xc3, 0xdf, 0xae, 0x18, 0x81, 0x00, /* ETH */
0x00, 0x76, 0x81, 0x00, /* VLAN */
0x00, 0x0a, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x64, 0x00, 0x12, 0x00, 0x00, 0xff, 0x06, 0x92, 0x93, 0x0a, 0x76, 0x0a, 0x01,
0x0a, 0x76, 0x0a, 0x02, /* IPv4 */
0x08, 0x00, 0xce, 0xb0, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x50, 0x10, 0xaf, 0x74,
0x89, 0x65, 0x00, 0x00, 0x00, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd /* TCP */};
static u_char expect_packet1_prepend_vlan_header[] = {
0x00, 0x30, 0x64, 0x4b, 0x58, 0x64, 0x76, 0xfc, 0xca, 0xef, 0x29, 0x28, 0x81, 0x00, /* ETH */
0x04, 0x00, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x34, 0x48, 0x78, 0x40, 0x00, 0x7f, 0x06, 0x1c, 0x17, 0xc0, 0xa8, 0x0a, 0xfa,
0xc0, 0xa8, 0x0a, 0xea, /* IPv4 */
0xe5, 0x65, 0x00, 0x16, 0x9a, 0x34, 0x99, 0x14, 0x7a, 0x02, 0xb1, 0xd4, 0x80, 0x10, 0x41, 0x06,
0xa4, 0xff, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x09, 0x48, 0x15, 0x64, 0x5d, 0x01, 0x39, 0x39 /* TCP */};
static u_char expect_packet2_prepend_vlan_header[] = {
0x00, 0x40, 0x05, 0x40, 0xef, 0x24, 0x00, 0x60, 0x08, 0x9f, 0xb1, 0xf3, 0x81, 0x00, /* ETH */
0x04, 0x00, 0x81, 0x00, /* VLAN */
0x00, 0x20, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x34, 0x8a, 0x9b, 0x40, 0x00, 0x40, 0x06, 0x68, 0x64, 0x83, 0x97, 0x20, 0x15,
0x83, 0x97, 0x20, 0x81, /* IPv4 */
0x17, 0x70, 0x04, 0x8a, 0x4d, 0x3d, 0x6a, 0xb9, 0x4e, 0x15, 0x21, 0x61, 0x80, 0x10, 0x7c, 0x70,
0xd7, 0xf9, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x01, 0x99, 0xa4, 0x5a, 0x00, 0x04, 0xf1, 0x2f /* TCP */};
static u_char expect_packet3_prepend_vlan_header[] = {
0x00, 0x1b, 0xd4, 0x1b, 0xa4, 0xd8, 0x00, 0x13, 0xc3, 0xdf, 0xae, 0x18, 0x81, 0x00, /* ETH */
0x04, 0x00, 0x81, 0x00, /* VLAN */
0x00, 0x76, 0x81, 0x00, /* VLAN */
0x00, 0x0a, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x64, 0x00, 0x12, 0x00, 0x00, 0xff, 0x06, 0x92, 0x93, 0x0a, 0x76, 0x0a, 0x01,
0x0a, 0x76, 0x0a, 0x02, /* IPv4 */
0x08, 0x00, 0xce, 0xb0, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x50, 0x10, 0xaf, 0x74,
0x89, 0x65, 0x00, 0x00, 0x00, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd /* TCP */};
static u_char expect_packet2_replace_vlan_header[] = {
0x00, 0x40, 0x05, 0x40, 0xef, 0x24, 0x00, 0x60, 0x08, 0x9f, 0xb1, 0xf3, 0x81, 0x00, /* ETH */
0x04, 0x00, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x34, 0x8a, 0x9b, 0x40, 0x00, 0x40, 0x06, 0x68, 0x64, 0x83, 0x97, 0x20, 0x15,
0x83, 0x97, 0x20, 0x81, /* IPv4 */
0x17, 0x70, 0x04, 0x8a, 0x4d, 0x3d, 0x6a, 0xb9, 0x4e, 0x15, 0x21, 0x61, 0x80, 0x10, 0x7c, 0x70,
0xd7, 0xf9, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x01, 0x99, 0xa4, 0x5a, 0x00, 0x04, 0xf1, 0x2f /* TCP */};
static u_char expect_packet3_replace_vlan_header[] = {
0x00, 0x1b, 0xd4, 0x1b, 0xa4, 0xd8, 0x00, 0x13, 0xc3, 0xdf, 0xae, 0x18, 0x81, 0x00, /* ETH */
0x04, 0x00, 0x08, 0x00, /* VLAN */
0x45, 0x00, 0x00, 0x64, 0x00, 0x12, 0x00, 0x00, 0xff, 0x06, 0x92, 0x93, 0x0a, 0x76, 0x0a, 0x01,
0x0a, 0x76, 0x0a, 0x02, /* IPv4 */
0x08, 0x00, 0xce, 0xb0, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x50, 0x10, 0xaf, 0x74,
0x89, 0x65, 0x00, 0x00, 0x00, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd,
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd /* TCP */};
static void hexdump(char *data, uint32_t len)
{
for (uint32_t i = 0; i < len; i++)
{
printf("%02X", data[i] & 0xFF);
}
printf("\n");
for (uint32_t i = 0; i < len; i++)
{
printf("0x%02X, ", data[i] & 0xFF);
}
printf("\n");
}
TEST(PACKET_IO, VLAN_ENCAPSULATE_PREPEND_HEADER_1)
{
marsio_buff_t *mbuff = NULL;
int replace_orig_vlan_header = 0;
build_mbuf_for_data_pkt(mbuff, data_packet1_no_vlan_layer, sizeof(data_packet1_no_vlan_layer), 290484492702581737, 1);
vlan_encapsulate(mbuff, 1024, replace_orig_vlan_header);
char *data = marsio_buff_mtod(mbuff);
uint32_t len = marsio_buff_datalen(mbuff);
hexdump(data, len);
EXPECT_TRUE(len == sizeof(expect_packet1_prepend_vlan_header));
EXPECT_TRUE(memcmp(data, expect_packet1_prepend_vlan_header, len) == 0);
marsio_buff_free(NULL, &mbuff, 1, 0, 0);
}
TEST(PACKET_IO, VLAN_ENCAPSULATE_PREPEND_HEADER_2)
{
marsio_buff_t *mbuff = NULL;
int replace_orig_vlan_header = 0;
build_mbuf_for_data_pkt(mbuff, data_packet2_one_vlan_layer, sizeof(data_packet2_one_vlan_layer), 290484492702581737, 1);
vlan_encapsulate(mbuff, 1024, replace_orig_vlan_header);
char *data = marsio_buff_mtod(mbuff);
uint32_t len = marsio_buff_datalen(mbuff);
hexdump(data, len);
EXPECT_TRUE(len == sizeof(expect_packet2_prepend_vlan_header));
EXPECT_TRUE(memcmp(data, expect_packet2_prepend_vlan_header, len) == 0);
marsio_buff_free(NULL, &mbuff, 1, 0, 0);
}
TEST(PACKET_IO, VLAN_ENCAPSULATE_PREPEND_HEADER_3)
{
marsio_buff_t *mbuff = NULL;
int replace_orig_vlan_header = 0;
build_mbuf_for_data_pkt(mbuff, data_packet3_two_vlan_layer, sizeof(data_packet3_two_vlan_layer), 290484492702581737, 1);
vlan_encapsulate(mbuff, 1024, replace_orig_vlan_header);
char *data = marsio_buff_mtod(mbuff);
uint32_t len = marsio_buff_datalen(mbuff);
hexdump(data, len);
EXPECT_TRUE(len == sizeof(expect_packet3_prepend_vlan_header));
EXPECT_TRUE(memcmp(data, expect_packet3_prepend_vlan_header, len) == 0);
marsio_buff_free(NULL, &mbuff, 1, 0, 0);
}
TEST(PACKET_IO, VLAN_ENCAPSULATE_PEPLACE_HEADER_1)
{
marsio_buff_t *mbuff = NULL;
int replace_orig_vlan_header = 1;
build_mbuf_for_data_pkt(mbuff, data_packet1_no_vlan_layer, sizeof(data_packet1_no_vlan_layer), 290484492702581737, 1);
vlan_encapsulate(mbuff, 1024, replace_orig_vlan_header);
char *data = marsio_buff_mtod(mbuff);
uint32_t len = marsio_buff_datalen(mbuff);
hexdump(data, len);
EXPECT_TRUE(len == sizeof(expect_packet1_prepend_vlan_header));
EXPECT_TRUE(memcmp(data, expect_packet1_prepend_vlan_header, len) == 0);
marsio_buff_free(NULL, &mbuff, 1, 0, 0);
}
TEST(PACKET_IO, VLAN_ENCAPSULATE_PEPLACE_HEADER_2)
{
marsio_buff_t *mbuff = NULL;
int replace_orig_vlan_header = 1;
build_mbuf_for_data_pkt(mbuff, data_packet2_one_vlan_layer, sizeof(data_packet2_one_vlan_layer), 290484492702581737, 1);
vlan_encapsulate(mbuff, 1024, replace_orig_vlan_header);
char *data = marsio_buff_mtod(mbuff);
uint32_t len = marsio_buff_datalen(mbuff);
hexdump(data, len);
EXPECT_TRUE(len == sizeof(expect_packet2_replace_vlan_header));
EXPECT_TRUE(memcmp(data, expect_packet2_replace_vlan_header, len) == 0);
marsio_buff_free(NULL, &mbuff, 1, 0, 0);
}
TEST(PACKET_IO, VLAN_ENCAPSULATE_PEPLACE_HEADER_3)
{
marsio_buff_t *mbuff = NULL;
int replace_orig_vlan_header = 1;
build_mbuf_for_data_pkt(mbuff, data_packet3_two_vlan_layer, sizeof(data_packet3_two_vlan_layer), 290484492702581737, 1);
vlan_encapsulate(mbuff, 1024, replace_orig_vlan_header);
char *data = marsio_buff_mtod(mbuff);
uint32_t len = marsio_buff_datalen(mbuff);
hexdump(data, len);
EXPECT_TRUE(len == sizeof(expect_packet3_replace_vlan_header));
EXPECT_TRUE(memcmp(data, expect_packet3_replace_vlan_header, len) == 0);
marsio_buff_free(NULL, &mbuff, 1, 0, 0);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|