本文整理汇总了C++中IP::serialize方法的典型用法代码示例。如果您正苦于以下问题:C++ IP::serialize方法的具体用法?C++ IP::serialize怎么用?C++ IP::serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::serialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IP
TEST_F(IPTest, StackedProtocols) {
IP ip = IP() / TCP();
IP::serialization_type buffer = ip.serialize();
EXPECT_TRUE(IP(&buffer[0], buffer.size()).find_pdu<TCP>());
ip = IP() / UDP();
buffer = ip.serialize();
EXPECT_TRUE(IP(&buffer[0], buffer.size()).find_pdu<UDP>());
ip = IP() / ICMP();
buffer = ip.serialize();
EXPECT_TRUE(IP(&buffer[0], buffer.size()).find_pdu<ICMP>());
}
示例2: sizeof
TEST_F(IPTest, SpoofedOptions) {
IP pdu;
uint8_t a[] = { 1,2,3,4,5,6 };
pdu.add_option(
IP::option(IP::NOOP, 250, a, a + sizeof(a))
);
pdu.add_option(
IP::option(IP::NOOP, 250, a, a + sizeof(a))
);
pdu.add_option(
IP::option(IP::NOOP, 250, a, a + sizeof(a))
);
// probably we'd expect it to crash if it's not working, valgrind plx
EXPECT_EQ(3U, pdu.options().size());
EXPECT_EQ(pdu.serialize().size(), pdu.size());
}
示例3: cb
//.........这里部分代码省略.........
rr = ip.find_pdu<RR>();
if (is_spoof && ip.src_addr() == IP::address_type("192.168.30.10")) {
rr->route().push_back(RREntry(IP::address_type("192.168.100.20"), 42, 42));
}
}
// TODO Figure out what the magic numbers are for the source address
RREntry src_hop(ip.src_addr(), 0x0, 0x0);
RREntry last_hop = src_hop;
if (rr != 0 && rr->route().size() >= 1)
last_hop = rr->route().back();
AITF_packet aitf;
if (should_intercept(ip, rr, &aitf)) {
//cout << "Intercepting packet" << endl;
send_AITF_message(aitf, IP::address_type("192.168.10.100"));
verdict = NF_DROP;
}
else if (is_blocked(last_hop, ip.dst_addr()) || (is_shadow && rr->route().size() > 1 && is_blocked(src_hop, ip.dst_addr()))) {
//cout << "Packet blocked" << endl;
verdict = NF_DROP;
} else if (hosts.isLegacyHost(ip.dst_addr())) {
//cout << "Legacy host detected" << endl;
if (rr != 0) {
//print_route(rr->route());
strip_rr(ip, *rr);
} else {
//cout << "No RR table present" << endl;
}
} else {
NetworkInterface interface(ip.dst_addr());
rr->route().push_back(RREntry(interface_addr, hash_for_destination(ip.dst_addr(), 0), hash_for_destination(ip.dst_addr(), 1)));
if (rr->route().size() > rr->route_capacity()) {
//cout << "RR table filled. Dropping packet." << endl;
verdict = NF_DROP;
} //else print_route(rr->route());
}
} else if (mode == HOST) {
if (rr != 0) {
// Check if this is a bad packet
// TODO don't hard code attacker ip addresses
bool is_bad = false;
try {
UDP udp(&rr->payload()[0], rr->payload().size());
RawPDU* raw = udp.find_pdu<RawPDU>();
if (raw != 0) {
is_bad = raw->payload()[0] == 1;
}
} catch (malformed_packet e) { }
if (is_bad && is_victim) {
if (!last_event_set) {
printf("Attack detected\n");
gettimeofday(&last_event, NULL);
last_event_set = true;
event_delay = 500000;
} else {
struct timeval now;
gettimeofday(&now, NULL);
if ((now.tv_sec - last_event.tv_sec) * 1000000 + now.tv_usec - last_event.tv_usec > event_delay) {
printf("Enforce sent\n");
print_route(rr->route());
vector<RRFilter> filters;
filters.push_back(RRFilter(is_wildcard ? 1 : 0, ip.src_addr(), 0x0, 0x0));
for (int i = 0; i < rr->route().size(); i++) {
const RREntry& entry = rr->route().at(i);
filters.push_back(RRFilter(is_wildcard ? 1 : 0, entry.address(), entry.random_number_1(), entry.random_number_2()));
}
AITF_packet enforce(0, 0, 0, 1, filters, IP::address_type("192.168.10.10"), filters.size());
send_AITF_message(enforce, IP::address_type("192.168.10.100"));
last_event = now;
event_delay = is_aggressive ? 1000000 : 10000000;
}
}
}
//print_route(rr->route());
strip_rr(ip, *rr);
} else {
//cout << "No RR table present" << endl;
}
}
result = ip.serialize();
//cout << endl;
} catch (malformed_packet e) {
cout << "malformed packet " << e.what() << endl;
}
return nfq_set_verdict(qh, id, verdict,
verdict == NF_DROP ? 0 : result.size(),
verdict == NF_DROP ? 0 : &result[0]);
}