Add ipv4 helpers
This commit is contained in:
51
src/packet/test/gtest_ipv4_helpers.cpp
Normal file
51
src/packet/test/gtest_ipv4_helpers.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "ipv4_helpers.h"
|
||||
|
||||
/*
|
||||
* Internet Protocol Version 4, Src: 192.168.36.103, Dst: 192.168.40.137
|
||||
* 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: 44
|
||||
* Identification: 0xffff (65535)
|
||||
* 001. .... = Flags: 0x1, More fragments
|
||||
* 0... .... = Reserved bit: Not set
|
||||
* .0.. .... = Don't fragment: Not set
|
||||
* ..1. .... = More fragments: Set
|
||||
* ...0 0000 0000 0000 = Fragment Offset: 0
|
||||
* Time to Live: 127
|
||||
* Protocol: TCP (6)
|
||||
* Header Checksum: 0x4d8b [correct]
|
||||
* [Header checksum status: Good]
|
||||
* [Calculated Checksum: 0x4d8b]
|
||||
* Source Address: 192.168.36.103
|
||||
* Destination Address: 192.168.40.137
|
||||
* [Reassembled IPv4 in frame: 5]
|
||||
* Data (24 bytes)
|
||||
*/
|
||||
|
||||
unsigned char hdr[] = {0x45, 0x00, 0x00, 0x2c, 0xff, 0xff, 0x20, 0x00, 0x7f, 0x06, 0x4d, 0x8b, 0xc0, 0xa8, 0x24, 0x67, 0xc0, 0xa8, 0x28, 0x89};
|
||||
|
||||
TEST(IPV4_HELPERS, GET)
|
||||
{
|
||||
EXPECT_TRUE(ipv4_hdr_get_ipid((struct ip *)hdr) == 65535);
|
||||
EXPECT_TRUE(ipv4_hdr_get_flags((struct ip *)hdr) == 1);
|
||||
EXPECT_TRUE(ipv4_hdr_get_frag_offset((struct ip *)hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ttl((struct ip *)hdr) == 127);
|
||||
EXPECT_TRUE(ipv4_hdr_get_protocol((struct ip *)hdr) == 6);
|
||||
EXPECT_TRUE(ipv4_hdr_get_checksum((struct ip *)hdr) == 0x4d8b);
|
||||
EXPECT_TRUE(ipv4_hdr_get_src((struct ip *)hdr) == 0xc0a82467);
|
||||
EXPECT_TRUE(ipv4_hdr_get_dst((struct ip *)hdr) == 0xc0a82889);
|
||||
EXPECT_TRUE(ipv4_hdr_has_flag_rf((struct ip *)hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_has_flag_df((struct ip *)hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_has_flag_mf((struct ip *)hdr) == true);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user