499 lines
23 KiB
C++
499 lines
23 KiB
C++
#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();
|
|
}
|