本文整理汇总了C++中pdu::serialization_type类的典型用法代码示例。如果您正苦于以下问题:C++ serialization_type类的具体用法?C++ serialization_type怎么用?C++ serialization_type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了serialization_type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eth
TEST_F(EthernetIITest, SerializeSmallEthernetWithPadding) {
EthernetII eth(smallip_packet, sizeof(smallip_packet));
ASSERT_TRUE(eth.inner_pdu() != NULL);
PDU::serialization_type serialized = eth.serialize();
EXPECT_EQ(serialized.size(), sizeof(smallip_packet));
EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), smallip_packet));
}
示例2: socket_write_error
void PacketSender::send_l3(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, SocketType type) {
open_l3_socket(type);
int sock = _sockets[type];
PDU::serialization_type buffer = pdu.serialize();
if(sendto(sock, (const char*)&buffer[0], buffer.size(), 0, link_addr, len_addr) == -1)
throw socket_write_error(make_error_string());
}
示例3: sizeof
TEST_F(TCPTest, ConstructorFromBuffer) {
TCP tcp1(expected_packet, sizeof(expected_packet));
EXPECT_EQ(tcp1.dport(), 0x4f1d);
EXPECT_EQ(tcp1.sport(), 0x7f4d);
EXPECT_EQ(tcp1.seq(), 0xf1dae546);
EXPECT_EQ(tcp1.ack_seq(), 0x5faed123U);
EXPECT_EQ(tcp1.window(), 0x71da);
EXPECT_EQ(tcp1.urg_ptr(), 0x1fae);
EXPECT_EQ(tcp1.data_offset(), 0xd);
EXPECT_EQ(tcp1.timestamp(), (std::pair<uint32_t, uint32_t>(0x4fd23acb, 0x89fe1234)));
EXPECT_TRUE(tcp1.has_sack_permitted());
EXPECT_EQ(tcp1.winscale(), 0x7a);
EXPECT_EQ(tcp1.mss(), 0x98fa);
TCP::sack_type edges = tcp1.sack();
TCP::sack_type::const_iterator iter = edges.begin();
ASSERT_EQ(edges.size(), 2U);
EXPECT_EQ(*iter++, 0x00010203U);
EXPECT_EQ(*iter++, 0x04050607U);
PDU::serialization_type buffer = tcp1.serialize();
TCP tcp2(&buffer[0], buffer.size());
test_equals(tcp1, tcp2);
}
示例4: Loopback
TEST_F(LoopbackTest, MatchesResponse) {
Loopback loop1 = Loopback() / IP("192.168.0.1", "192.168.0.2") / TCP(22, 21);
loop1.family(PF_INET);
Loopback loop2 = Loopback() / IP("192.168.0.2", "192.168.0.1") / TCP(21, 22);
loop2.family(PF_INET);
PDU::serialization_type buffer = loop2.serialize();
EXPECT_TRUE(loop1.matches_response(&buffer[0], buffer.size()));
}
示例5: EthernetII
TEST_F(Dot1QTest, SerializeAfterInnerPduRemoved) {
EthernetII eth1 = EthernetII() / Dot1Q() / IP();
eth1.serialize();
eth1.rfind_pdu<Dot1Q>().inner_pdu(0);
PDU::serialization_type buffer = eth1.serialize();
EthernetII eth2(&buffer[0], buffer.size());
EXPECT_EQ(eth1.size(), eth2.size());
}
示例6: serialized
// Make sure that a big payload is not considered ICMP extensions
TEST_F(IPv6Test, BigEncapsulatedPacketIsNotConsideredToHaveExtensions) {
IPv6 encapsulated = IPv6(TINS_DEFAULT_TEST_IP) / UDP(99, 12) / RawPDU(std::string(250, 'A'));
EthernetII pkt = EthernetII() / IPv6() / ICMPv6(ICMPv6::TIME_EXCEEDED) / encapsulated;
PDU::serialization_type buffer = pkt.serialize();
EthernetII serialized(&buffer[0], buffer.size());
ASSERT_EQ(encapsulated.size(), serialized.rfind_pdu<RawPDU>().payload().size());
ASSERT_TRUE(serialized.rfind_pdu<ICMPv6>().extensions().extensions().empty());
}
示例7: sizeof
TEST_F(DHCPTest, Serialize) {
DHCP dhcp1(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = dhcp1.serialize();
ASSERT_EQ(buffer.size(), sizeof(expected_packet));
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
DHCP dhcp2(&buffer[0], (uint32_t)buffer.size());
test_equals(dhcp1, dhcp2);
}
示例8: sizeof
TEST_F(UDPTest, ChecksumCheck) {
EthernetII pkt1(checksum_packet, sizeof(checksum_packet));
const UDP &udp1 = pkt1.rfind_pdu<UDP>();
uint16_t checksum = udp1.checksum();
PDU::serialization_type buffer = pkt1.serialize();
EthernetII pkt2(&buffer[0], (uint32_t)buffer.size());
const UDP &udp2 = pkt2.rfind_pdu<UDP>();
EXPECT_EQ(checksum, udp2.checksum());
EXPECT_EQ(udp1.checksum(), udp2.checksum());
}
示例9: sizeof
TEST_F(SNAPTest, ConstructorFromBuffer) {
SNAP snap1(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = snap1.serialize();
EXPECT_EQ(3, snap1.control());
EXPECT_EQ(0xaa, snap1.dsap());
EXPECT_EQ(0xaa, snap1.ssap());
EXPECT_EQ(0x0800, snap1.eth_type());
EXPECT_EQ(1U, snap1.org_code());
SNAP snap2(&buffer[0], (uint32_t)buffer.size());
test_equals(snap1, snap2);
}
示例10: pdu
TEST_F(PPPoETest, StackedOnEthernetSerializationWithTags) {
PPPoE pdu(expected_packet, sizeof(expected_packet));
EthernetII eth = EthernetII() / pdu;
PDU::serialization_type buffer = eth.serialize();
EthernetII eth2(&buffer[0], (uint32_t)buffer.size());
PPPoE* unserialized = eth2.find_pdu<PPPoE>();
ASSERT_TRUE(unserialized != NULL);
EXPECT_EQ(
PPPoE::serialization_type(expected_packet, expected_packet + sizeof(expected_packet)),
unserialized->serialize()
);
}
示例11: extension
// Use a large buffer. This wil set the length field
TEST_F(IPv6Test, SerializePacketHavingICMPExtensionsWithLengthAndLotsOfPayload) {
IPv6 encapsulated = IPv6(TINS_DEFAULT_TEST_IP) / UDP(99, 12) / RawPDU(std::string(250, 'A'));
EthernetII pkt = EthernetII() / IPv6() / ICMPv6(ICMPv6::TIME_EXCEEDED) / encapsulated;
const uint8_t payload[] = { 24, 150, 1, 1 };
ICMPExtension extension(1, 1);
ICMPExtension::payload_type ext_payload(payload, payload + sizeof(payload));
extension.payload(ext_payload);
pkt.rfind_pdu<ICMPv6>().extensions().add_extension(extension);
PDU::serialization_type buffer = pkt.serialize();
EthernetII serialized(&buffer[0], buffer.size());
ASSERT_EQ(1, serialized.rfind_pdu<ICMPv6>().extensions().extensions().size());
EXPECT_EQ(ext_payload, serialized.rfind_pdu<ICMPv6>().extensions().extensions().begin()->payload());
}
示例12: sizeof
TEST_F(ARPTest, ConstructorFromBuffer) {
ARP arp1(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = arp1.serialize();
ARP arp2(&buffer[0], (uint32_t)buffer.size());
EXPECT_EQ(arp1.opcode(), arp2.opcode());
ASSERT_EQ(arp1.hw_addr_length(), arp2.hw_addr_length());
EXPECT_EQ(arp1.hw_addr_format(), arp2.hw_addr_format());
ASSERT_EQ(arp1.prot_addr_length(), arp2.prot_addr_length());
EXPECT_EQ(arp1.prot_addr_format(), arp2.prot_addr_format());
EXPECT_EQ(arp1.sender_ip_addr(), arp2.sender_ip_addr());
EXPECT_EQ(arp1.target_ip_addr(), arp2.target_ip_addr());
EXPECT_EQ(arp1.sender_hw_addr(), arp2.sender_hw_addr());
EXPECT_EQ(arp1.target_hw_addr(), arp2.target_hw_addr());
}
示例13: sizeof
TEST_F(UDPTest, ConstructorFromBuffer) {
UDP udp1(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = udp1.serialize();
EXPECT_EQ(buffer.size(), sizeof(expected_packet));
EXPECT_EQ(udp1.dport(), 0x47f1);
EXPECT_EQ(udp1.sport(), 0xf51a);
EXPECT_EQ(udp1.length(), 8);
UDP udp2(&buffer[0], buffer.size());
EXPECT_EQ(udp1.dport(), udp2.dport());
EXPECT_EQ(udp1.sport(), udp2.sport());
EXPECT_EQ(udp1.length(), udp2.length());
EXPECT_EQ(udp1.size(), udp2.size());
EXPECT_EQ(udp1.header_size(), udp2.header_size());
}
示例14: write
void PacketWriter::write(PDU &pdu) {
PDU::serialization_type buffer = pdu.serialize();
timeval tm;
#ifndef _WIN32
gettimeofday(&tm, 0);
#else
// fixme
tm = timeval();
#endif
struct pcap_pkthdr header = {
tm,
static_cast<bpf_u_int32>(buffer.size()),
static_cast<bpf_u_int32>(buffer.size())
};
pcap_dump((u_char*)dumper, &header, &buffer[0]);
}
示例15: tim
TEST_F(Dot11BeaconTest, PCAPLoad1) {
const uint8_t buffer[] = {
128, 0, 0, 0, 255, 255, 255, 255, 255, 255, 244, 236, 56, 254, 77,
146, 244, 236, 56, 254, 77, 146, 224, 234, 128, 209, 212, 206, 44,
0, 0, 0, 100, 0, 49, 4, 0, 7, 83, 101, 103, 117, 110, 100, 111, 1,
8, 130, 132, 139, 150, 12, 18, 24, 36, 3, 1, 1, 5, 4, 0, 1, 0, 0, 7,
6, 85, 83, 32, 1, 13, 20, 42, 1, 0, 48, 20, 1, 0, 0, 15, 172, 4, 1,
0, 0, 15, 172, 4, 1, 0, 0, 15, 172, 2, 0, 0, 50, 4, 48, 72, 96, 108,
221, 24, 0, 80, 242, 2, 1, 1, 3, 0, 3, 164, 0, 0, 39, 164, 0, 0, 66,
67, 94, 0, 98, 50, 47, 0, 221, 9, 0, 3, 127, 1, 1, 0, 0, 255, 127
};
typedef byte_array country_container;
Dot11Beacon dot11(buffer, sizeof(buffer));
float rates[] = { 1.0f, 2.0f, 5.5f, 11.0f, 6.0f, 9.0f, 12.0f, 18.0f},
ext_rates[] = { 24.0f, 36.0f, 48.0f, 54.0f };
Dot11Beacon::rates_type rates_parsed = dot11.supported_rates();
Dot11Beacon::rates_type ext_rates_parsed = dot11.extended_supported_rates();
Dot11Beacon::tim_type tim(0, 1, 0, byte_array(1)),
tim_parsed = dot11.tim();
Dot11Beacon::country_params country("US ",
country_container(1, 1),
country_container(1, 13),
country_container(1, 20)),
country_parsed = dot11.country();
EXPECT_EQ(dot11.ssid(), "Segundo");
ASSERT_EQ(rates_parsed.size(), sizeof(rates) / sizeof(float));
EXPECT_TRUE(std::equal(rates_parsed.begin(), rates_parsed.end(), rates));
ASSERT_EQ(ext_rates_parsed.size(), sizeof(ext_rates) / sizeof(float));
EXPECT_TRUE(std::equal(ext_rates_parsed.begin(), ext_rates_parsed.end(), ext_rates));
EXPECT_EQ(1, dot11.ds_parameter_set());
EXPECT_EQ(tim.dtim_count, tim_parsed.dtim_count);
EXPECT_EQ(tim.dtim_period, tim_parsed.dtim_period);
EXPECT_EQ(tim.bitmap_control, tim_parsed.bitmap_control);
EXPECT_EQ(tim.partial_virtual_bitmap, tim_parsed.partial_virtual_bitmap);
EXPECT_EQ(country.country, country_parsed.country);
EXPECT_EQ(country.first_channel, country_parsed.first_channel);
EXPECT_EQ(country.number_channels, country_parsed.number_channels);
EXPECT_EQ(country.max_transmit_power, country_parsed.max_transmit_power);
EXPECT_EQ(dot11.erp_information(), 0);
PDU::serialization_type serialized = dot11.serialize();
ASSERT_EQ(sizeof(buffer), serialized.size());
EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), buffer));
}