本文整理汇总了C++中IP类的典型用法代码示例。如果您正苦于以下问题:C++ IP类的具体用法?C++ IP怎么用?C++ IP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send_syns
// Send syns to the given ip address, using the destination ports provided.
void send_syns(const NetworkInterface &iface, IPv4Address dest_ip, const vector<string> &ips) {
// Retrieve the addresses.
NetworkInterface::Info info = iface.addresses();
PacketSender sender;
// Allocate the IP PDU
IP ip = IP(dest_ip, info.ip_addr) / TCP();
// Get the reference to the TCP PDU
TCP &tcp = ip.rfind_pdu<TCP>();
// Set the SYN flag on.
tcp.set_flag(TCP::SYN, 1);
// Just some random port.
tcp.sport(1337);
cout << "Sending SYNs..." << endl;
for(vector<string>::const_iterator it = ips.begin(); it != ips.end(); ++it) {
// Set the new port and send the packet!
tcp.dport(atoi(it->c_str()));
sender.send(ip);
}
// Wait 1 second.
sleep(1);
/* Special packet to indicate that we're done. This will be sniffed
* by our function, which will in turn return false.
*/
tcp.set_flag(TCP::RST, 1);
// Pretend we're the scanned host...
ip.src_addr(dest_ip);
// We use an ethernet pdu, otherwise the kernel will drop it.
EthernetII eth = EthernetII(info.hw_addr, info.hw_addr) / ip;
sender.send(eth, iface);
}
示例2:
IPv4Reassembler::packet_status IPv4Reassembler::process(PDU &pdu) {
IP *ip = pdu.find_pdu<IP>();
if(ip && ip->inner_pdu()) {
// There's fragmentation
if(ip->is_fragmented()) {
// Create it or look it up, it's the same
Internals::IPv4Stream &stream = streams[make_key(ip)];
stream.add_fragment(ip);
if(stream.is_complete()) {
PDU *pdu = stream.allocate_pdu();
// The packet is corrupt
if(!pdu) {
streams.erase(make_key(ip));
return FRAGMENTED;
}
ip->inner_pdu(pdu);
ip->frag_off(0);
return REASSEMBLED;
}
else
return FRAGMENTED;
}
}
return NOT_FRAGMENTED;
}
示例3: send_packets
void send_packets(PacketSender& sender) {
// ICMPs are icmp-requests by default
IP ip = IP(addr, iface.addresses().ip_addr) / ICMP();
ICMP& icmp = ip.rfind_pdu<ICMP>();
icmp.sequence(sequence);
// We'll find at most 20 hops.
for (auto i = 1; i <= 20; ++i) {
// Set this ICMP id
icmp.id(i);
// Set the time-to-live option
ip.ttl(i);
// Critical section
{
lock_guard<mutex> _(lock);
ttls[i] = i;
}
sender.send(ip);
// Give it a little time
sleep_for(milliseconds(100));
}
running = false;
sender.send(ip);
}
示例4:
const char *get_host(void *p)
{
IP *ip = (IP*)p;
if (ip && ip->host())
return ip->host();
return "";
}
示例5: get_ip
unsigned long get_ip(void *p)
{
IP *ip = (IP*)p;
if (ip)
return ip->ip();
return 0;
}
示例6: TEST_F
TEST_F(IPTest, SecOption) {
IP ip;
ip.security(IP::security_type(0x746a, 26539, 0x77ab, 0x68656c));
IP::security_type found = ip.security();
EXPECT_EQ(found.security, 0x746a);
EXPECT_EQ(found.compartments, 26539);
EXPECT_EQ(found.handling_restrictions, 0x77ab);
EXPECT_EQ(found.transmission_control, 0x68656cU);
}
示例7: CostFunction4GoodC
CostFunction4GoodC(const IP& interpol) :
interpol_(interpol) {
//must be formed only once!
Chained_.resize(interpol.getNumOfPoints(),
interpol.getOutDim() + interpol.getNumOfPoints());
concatenate(Chained_, interpol.getData(),
identity_full<BoostMatrixType> (interpol.getNumOfPoints()));
//now Chained_ = [F|I]
}
示例8: hash_value
inline std::size_t hash_value(const IP& ip)
{
size_t seed = 0;
switch (ip.family()) {
case AF_INET:
boost::hash_combine(seed, htonl(ip.in().get().s_addr));
return seed;
default:
UNREACHABLE();
}
}
示例9: TEST_F
TEST_F(PDUTest, OperatorConcat) {
std::string raw_payload = "Test";
IP ip = IP("192.168.0.1") / TCP(22, 52) / RawPDU(raw_payload);
EXPECT_EQ(ip.dst_addr(), "192.168.0.1");
ASSERT_TRUE(ip.inner_pdu() != NULL);
TCP *tcp = ip.find_pdu<TCP>();
ASSERT_TRUE(tcp != NULL);
EXPECT_EQ(tcp->dport(), 22);
EXPECT_EQ(tcp->sport(), 52);
ASSERT_TRUE(tcp->inner_pdu() != NULL);
RawPDU *raw = tcp->find_pdu<RawPDU>();
ASSERT_TRUE(raw != NULL);
ASSERT_EQ(raw->payload_size(), raw_payload.size());
EXPECT_TRUE(std::equal(raw_payload.begin(), raw_payload.end(), raw->payload().begin()));
}
示例10: 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;
}
示例11: calculateClass
char IP::calculateClass(IP p) {
int tal;
string adress;
adress = p.getIP().substr(0, p.getIP().find(".")); //tar ut sträng mellan position 0 och första punkten. 192.168.1.1 -> 192
tal = atoi(adress.c_str());
if (tal < 128)
return 'A';
else if (tal >= 128 && tal < 192)
return 'B';
else if (tal >= 192 && tal < 224)
return 'C';
else
return 'X';
}
示例12: should_intercept
static bool should_intercept(const IP& ip, const RR* rr, AITF_packet *aitf) {
if (!hosts.isEnabledHost(ip.dst_addr())) return false;
const UDP *udp = ip.find_pdu<UDP>();
if (udp != 0) {
if (udp->dport() == 11467) {
const RawPDU *raw = udp->find_pdu<RawPDU>();
*aitf = AITF_packet(&raw->payload()[0], raw->payload().size());
return true;
}
return false;
}
if (rr != 0) {
try {
UDP udp(&rr->payload()[0], rr->payload().size());
if (udp.dport() == 11467) {
const RawPDU *raw = udp.find_pdu<RawPDU>();
*aitf = AITF_packet(&raw->payload()[0], raw->payload().size());
return true;
}
} catch (malformed_packet e) { }
}
return false;
}
示例13: Hit
LRESULT CAddressBar::OnLButtonUp(WPARAM wParam, LPARAM lParam)
{
POINTS* p = (POINTS*)(&lParam);
POINT point;
point.x = p->x;
point.y = p->y;
CVSpace2 * Space = Hit(point);
if(Space){
int64 ID = Space->m_Alias;
if(ID == CM_CONNECT && m_SpaceFocused==Space){
::ReleaseCapture();
if (Space->m_State & SPACE_DISABLE)
{
return 0;
}
Space->m_State = SPACE_DISABLE;
m_AddressEdit.SetReadOnly(TRUE);
tstring ipstr = m_AddressEdit.GetEditText(false);
AnsiString ipstr2 = WStoUTF8(ipstr);
IP ip;
ip.Set(ipstr2);
SendParentMessage(CM_CONNECT,ID,ip.GetUint32(),Space);
}else if (ID == CM_DISCONNECT)
{
SendParentMessage(CM_DISCONNECT,ID,0,Space);
}
};
//如果鼠标在bnt之外放开则取消的状态
Space = m_ChildList.front();
if(Space->m_State & SPACE_SELECTED){
::ReleaseCapture();
Space->m_State = 0;
}
Invalidate();
return 0;
}
示例14: ip
IP Address::ip(IP ip) {
if(inet_aton(ip.c_str(), &this->sin_addr) == 0) {
std::stringstream error;
error << "[ip] with [ip = "<< ip <<"] invalid ip address provided";
throw SocketException(error.str());
}
return this->ip();
}
示例15: Ethernet
packetDecoder::packetDecoder()
{
//ctor
// add protocols to RegProtocol
RegProtocol.clear();
Ethernet *ethIns = new Ethernet();
RegProtocol[ethIns->getProtoId()] = ethIns;
IP *ipIns = new IP();
RegProtocol[ipIns->getProtoId()] = ipIns;
Udp *udpIns = new Udp();
RegProtocol[udpIns->getProtoId()] = udpIns;
TCP *tcpIns = new TCP();
RegProtocol[tcpIns->getProtoId()] = tcpIns;
}