当前位置: 首页>>代码示例>>C++>>正文


C++ serialization_type::size方法代码示例

本文整理汇总了C++中pdu::serialization_type::size方法的典型用法代码示例。如果您正苦于以下问题:C++ serialization_type::size方法的具体用法?C++ serialization_type::size怎么用?C++ serialization_type::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pdu::serialization_type的用法示例。


在下文中一共展示了serialization_type::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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);
}
开发者ID:gtdsj,项目名称:libtins,代码行数:10,代码来源:dhcp.cpp

示例2: socket_write_error

void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr, 
  uint32_t len_addr, const NetworkInterface &iface) 
{
    int sock = get_ether_socket(iface);
    PDU::serialization_type buffer = pdu.serialize();
    if(!buffer.empty()) {
        #if defined(BSD) || defined(__FreeBSD_kernel__)
        if(::write(sock, &buffer[0], buffer.size()) == -1)
        #else
        if(::sendto(sock, &buffer[0], buffer.size(), 0, link_addr, len_addr) == -1)
        #endif
            throw socket_write_error(make_error_string());
    }
}
开发者ID:jalons,项目名称:libtins,代码行数:14,代码来源:packet_sender.cpp

示例3: 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));
}
开发者ID:CityOfSolitude,项目名称:libtins,代码行数:7,代码来源:ethernetII.cpp

示例4: 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());
}
开发者ID:JeanJoskin,项目名称:libtins,代码行数:16,代码来源:udp.cpp

示例5: 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);
}
开发者ID:Temptationx,项目名称:libtins,代码行数:30,代码来源:tcp.cpp

示例6: 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()));
}
开发者ID:UlfWetzker,项目名称:libtins,代码行数:8,代码来源:loopback_test.cpp

示例7: 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());
}
开发者ID:simple555a,项目名称:libtins,代码行数:10,代码来源:ipv6.cpp

示例8: 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());
}
开发者ID:UlfWetzker,项目名称:libtins,代码行数:9,代码来源:dot1q_test.cpp

示例9: 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());
}
开发者ID:Imva,项目名称:libtins,代码行数:11,代码来源:udp.cpp

示例10: 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);
}
开发者ID:Imva,项目名称:libtins,代码行数:13,代码来源:snap.cpp

示例11: 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()
    );

}
开发者ID:prasad24582,项目名称:libtins,代码行数:13,代码来源:pppoe.cpp

示例12: 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());
}
开发者ID:simple555a,项目名称:libtins,代码行数:15,代码来源:ipv6.cpp

示例13: 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());
}
开发者ID:CityOfSolitude,项目名称:libtins,代码行数:15,代码来源:arp.cpp

示例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]);
}
开发者ID:prasad24582,项目名称:libtins,代码行数:16,代码来源:packet_writer.cpp

示例15: pdu_from_flag

PDU *IPv4Stream::allocate_pdu() const {
    PDU::serialization_type buffer;
    buffer.reserve(total_size);
    // Check if we actually have all the data we need. Otherwise return nullptr;
    uint16_t expected = 0;
    for(fragments_type::const_iterator it = fragments.begin(); it != fragments.end(); ++it) {
        if(expected != it->offset())
            return 0;
        expected = static_cast<uint16_t>(it->offset() + it->payload().size());
        buffer.insert(buffer.end(), it->payload().begin(), it->payload().end());
    }
    return Internals::pdu_from_flag(
        static_cast<Constants::IP::e>(transport_proto),
        buffer.empty() ? 0 : &buffer[0],
        static_cast<uint32_t>(buffer.size())
    );
}
开发者ID:Imva,项目名称:libtins,代码行数:17,代码来源:ip_reassembler.cpp


注:本文中的pdu::serialization_type::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。