This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/packet/test/gtest_ipv4_helpers.cpp

59 lines
2.2 KiB
C++
Raw Normal View History

2023-12-29 15:15:18 +08:00
#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)
*/
2024-01-03 09:57:06 +08:00
unsigned char data[] = {0x45, 0x00, 0x00, 0x2c, 0xff, 0xff, 0x20, 0x00, 0x7f, 0x06, 0x4d, 0x8b, 0xc0, 0xa8, 0x24, 0x67, 0xc0, 0xa8, 0x28, 0x89};
2023-12-29 15:15:18 +08:00
2024-01-09 18:03:24 +08:00
TEST(IPV4_HELPERS, TEST)
2023-12-29 15:15:18 +08:00
{
2024-01-03 09:57:06 +08:00
const struct ip *hdr = (struct ip *)data;
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
EXPECT_TRUE(ipv4_hdr_get_hl(hdr) == 20);
EXPECT_TRUE(ipv4_hdr_get_tos(hdr) == 0);
EXPECT_TRUE(ipv4_hdr_get_len(hdr) == 44);
EXPECT_TRUE(ipv4_hdr_get_ipid(hdr) == 65535);
EXPECT_TRUE(ipv4_hdr_get_flags(hdr) == 1);
EXPECT_TRUE(ipv4_hdr_has_flag_rf(hdr) == false);
EXPECT_TRUE(ipv4_hdr_has_flag_df(hdr) == false);
EXPECT_TRUE(ipv4_hdr_has_flag_mf(hdr) == true);
EXPECT_TRUE(ipv4_hdr_get_frag_offset(hdr) == 0);
EXPECT_TRUE(ipv4_hdr_get_ttl(hdr) == 127);
EXPECT_TRUE(ipv4_hdr_get_protocol(hdr) == 6);
EXPECT_TRUE(ipv4_hdr_get_checksum(hdr) == 0x4d8b);
EXPECT_TRUE(ipv4_hdr_get_src(hdr) == 0xc0a82467);
EXPECT_TRUE(ipv4_hdr_get_dst(hdr) == 0xc0a82889);
EXPECT_TRUE(ipv4_hdr_get_opt_len(hdr) == 0);
EXPECT_TRUE(ipv4_hdr_get_opt_ptr(hdr) == data + 20);
2023-12-29 15:15:18 +08:00
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}