本文整理汇总了C++中EthernetII类的典型用法代码示例。如果您正苦于以下问题:C++ EthernetII类的具体用法?C++ EthernetII怎么用?C++ EthernetII使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EthernetII类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST_F
TEST_F(EthernetIITest, CompleteConstructor) {
EthernetII eth2;
EthernetII eth = EthernetII(dst_addr, src_addr) / eth2;
EXPECT_EQ(eth.dst_addr(), dst_addr);
EXPECT_EQ(eth.src_addr(), src_addr);
EXPECT_EQ(eth.payload_type(), 0);
}
示例2: TEST_F
// 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());
}
示例3: TEST_F
TEST_F(Dot1QTest, SerializeCraftedPacket)
{
EthernetII pkt = EthernetII() / Dot1Q(10) / IP("192.168.1.2") / TCP(23, 45) / RawPDU("asdasdasd");
PDU::serialization_type buffer = pkt.serialize();
EXPECT_EQ(buffer[12], 0x81);
EXPECT_EQ(buffer[13], 0x00);
EthernetII pkt2(&buffer[0], buffer.size());
const Dot1Q &q1 = pkt2.rfind_pdu<Dot1Q>();
EXPECT_EQ(10, q1.id());
}
示例4: TEST_F
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()
);
}
示例5: callback
bool callback(const PDU &pdu)
{
// The packet probably looks like this:
//
// EthernetII / IP / UDP / RawPDU
//
// So we retrieve each layer, and construct a
// DNS PDU from the RawPDU layer contents.
EthernetII eth = pdu.rfind_pdu<EthernetII>();
IP ip = eth.rfind_pdu<IP>();
UDP udp = ip.rfind_pdu<UDP>();
DNS dns = udp.rfind_pdu<RawPDU>().to<DNS>();
// Is it a DNS query?
if(dns.type() == DNS::QUERY) {
// Let's see if there's any query for an "A" record.
for(const auto &query : dns.queries()) {
if(query.type() == DNS::A) {
// Here's one! Let's add an answer.
dns.add_answer(
DNS::Resource(
query.dname(),
"127.0.0.1",
DNS::A,
query.query_class(),
// 777 is just a random TTL
777
)
);
}
}
// Have we added some answers?
if(dns.answers_count() > 0) {
// It's a response now
dns.type(DNS::RESPONSE);
// Recursion is available(just in case)
dns.recursion_available(1);
// Build our packet
auto pkt = EthernetII(eth.src_addr(), eth.dst_addr()) /
IP(ip.src_addr(), ip.dst_addr()) /
UDP(udp.sport(), udp.dport()) /
dns;
// Send it!
sender.send(pkt);
}
}
return true;
}
示例6: test_equals
void EthernetIITest::test_equals(const EthernetII& eth1, const EthernetII& eth2) {
EXPECT_EQ(eth1.dst_addr(), eth2.dst_addr());
EXPECT_EQ(eth1.src_addr(), eth2.src_addr());
EXPECT_EQ(eth1.payload_type(), eth2.payload_type());
EXPECT_EQ(eth1.inner_pdu() != NULL, eth2.inner_pdu() != NULL);
}