Commit | Line | Data |
---|---|---|
040c0f17 GMF |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
20 | ||
a72f06b6 | 21 | #define BOOST_TEST_MAIN |
040c0f17 GMF |
22 | #define BOOST_TEST_DYN_LINK |
23 | ||
24 | #include <streambuf> | |
25 | ||
26 | #include <boost/test/unit_test.hpp> | |
27 | ||
28 | #include "icmp/icmptype.h" | |
447f9ac5 CH |
29 | #include "icmp/icmpheader.h" |
30 | #include "icmp/icmpechodata.h" | |
31 | #include "icmp/icmpdestinationunreachabledata.h" | |
040c0f17 GMF |
32 | |
33 | BOOST_AUTO_TEST_SUITE( TestIcmpv6Header ) | |
34 | ||
35 | BOOST_AUTO_TEST_CASE( echo_reply ) | |
36 | { | |
37 | uint8_t raw_packet_stream[] = { | |
38 | 0x81, 0x00, 0xbf, 0x50, 0x0e, 0xbe, 0x00, 0x1a, 0x9c, 0xbb, 0x10, 0x4f, | |
39 | 0x15, 0x4d, 0x03, 0x00, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
40 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, | |
41 | 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | |
42 | 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, | |
43 | 0x34, 0x35, 0x36, 0x37 | |
44 | }; | |
45 | ||
46 | std::basic_stringbuf<uint8_t> sb; | |
47 | sb.pubsetbuf( raw_packet_stream, sizeof(raw_packet_stream) ); | |
48 | std::basic_istream<uint8_t> is( &sb ); | |
49 | ||
447f9ac5 CH |
50 | IcmpHeader icmp_header; |
51 | IcmpEchoData icmp_data(64 - 4); | |
52 | reinterpret_cast<std::istream&>(is) >> icmp_header >> icmp_data; | |
040c0f17 GMF |
53 | |
54 | BOOST_CHECK_EQUAL( icmp_header.get_type(), Icmpv6Type_EchoReply ); | |
55 | BOOST_CHECK_EQUAL( icmp_header.get_code(), 0 ); | |
56 | BOOST_CHECK_EQUAL( icmp_header.get_checksum(), 0xBF50 ); | |
447f9ac5 CH |
57 | BOOST_CHECK_EQUAL( icmp_data.get_identifier(), 0x0EBE ); |
58 | BOOST_CHECK_EQUAL( icmp_data.get_sequence_number(), 26 ); | |
040c0f17 GMF |
59 | } |
60 | ||
61 | BOOST_AUTO_TEST_CASE( echo_request ) | |
62 | { | |
63 | uint8_t raw_packet_stream[] = { | |
64 | 0x80, 0x00, 0xed, 0xa4, 0x11, 0xfd, 0x00, 0x06, 0x37, 0x03, 0x0c, 0x4f, | |
65 | 0x98, 0xc1, 0x0b, 0x00, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
66 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, | |
67 | 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | |
68 | 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, | |
69 | 0x34, 0x35, 0x36, 0x37 | |
70 | }; | |
71 | ||
72 | std::basic_stringbuf<uint8_t> sb; | |
73 | sb.pubsetbuf( raw_packet_stream, sizeof(raw_packet_stream) ); | |
74 | std::basic_istream<uint8_t> is( &sb ); | |
75 | ||
447f9ac5 CH |
76 | IcmpHeader icmp_header; |
77 | IcmpEchoData icmp_data(64 - 4); | |
78 | reinterpret_cast<std::istream&>(is) >> icmp_header >> icmp_data; | |
040c0f17 GMF |
79 | |
80 | BOOST_CHECK_EQUAL( icmp_header.get_type(), Icmpv6Type_EchoRequest ); | |
81 | BOOST_CHECK_EQUAL( icmp_header.get_code(), 0 ); | |
82 | BOOST_CHECK_EQUAL( icmp_header.get_checksum(), 0xEDA4 ); | |
447f9ac5 CH |
83 | BOOST_CHECK_EQUAL( icmp_data.get_identifier(), 0x11FD ); |
84 | BOOST_CHECK_EQUAL( icmp_data.get_sequence_number(), 6 ); | |
040c0f17 GMF |
85 | } |
86 | ||
87 | BOOST_AUTO_TEST_SUITE_END() |