コード例 #1
0
ファイル: portscan.cpp プロジェクト: charles1024/libtins
// 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
0
ファイル: ip_reassembler.cpp プロジェクト: Imva/libtins
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
0
ファイル: traceroute.cpp プロジェクト: CityOfSolitude/libtins
 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
0
const char *get_host(void *p)
{
    IP *ip = (IP*)p;
    if (ip && ip->host())
        return ip->host();
    return "";
}
コード例 #5
0
unsigned long get_ip(void *p)
{
    IP *ip = (IP*)p;
    if (ip)
        return ip->ip();
    return 0;
}
コード例 #6
0
unsigned long get_ip(Data &p)
{
    IP *ip = (IP*)p.ptr;
    if (ip)
        return ip->ip();
    return 0;
}
コード例 #7
0
const char *get_host(Data &p)
{
    IP *ip = (IP*)p.ptr;
    if (ip && ip->host())
        return ip->host();
    return "";
}
コード例 #8
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
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);
}
コード例 #9
0
ファイル: goodc.hpp プロジェクト: cheerlucy/NDInterpolator
	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]
	}
コード例 #10
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
TEST_F(IPTest, SSRROption) {
    IP ip;
    IP::ssrr_type ssrr(0x2d);
    ssrr.routes.push_back("192.168.2.3");
    ssrr.routes.push_back("192.168.5.1");
    ip.ssrr(ssrr);
    IP::ssrr_type found = ip.ssrr();
    EXPECT_EQ(found.pointer, ssrr.pointer);
    EXPECT_EQ(found.routes, ssrr.routes);
}
コード例 #11
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
TEST_F(IPTest, LSRROption) {
    IP ip;
    IP::lsrr_type lsrr(0x2d);
    lsrr.routes.push_back("192.168.2.3");
    lsrr.routes.push_back("192.168.5.1");
    ip.lsrr(lsrr);
    IP::lsrr_type found = ip.lsrr();
    EXPECT_EQ(found.pointer, lsrr.pointer);
    EXPECT_EQ(found.routes, lsrr.routes);
}
コード例 #12
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
TEST_F(IPTest, AddOption) {
    IP ip;
    const uint8_t data[] = { 0x15, 0x17, 0x94, 0x66, 0xff };
    IP::option_identifier id(IP::SEC, IP::CONTROL, 1);
    ip.add_option(IP::option(id, data, data + sizeof(data)));
    const IP::option *opt;
    ASSERT_TRUE((opt = ip.search_option(id)));
    ASSERT_EQ(opt->data_size(), sizeof(data));
    EXPECT_TRUE(memcmp(opt->data_ptr(), data, sizeof(data)) == 0);
}
コード例 #13
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
TEST_F(IPTest, RecordRouteOption) {
    IP ip;
    IP::record_route_type record_route(0x2d);
    record_route.routes.push_back("192.168.2.3");
    record_route.routes.push_back("192.168.5.1");
    ip.record_route(record_route);
    IP::record_route_type found = ip.record_route();
    EXPECT_EQ(found.pointer, record_route.pointer);
    EXPECT_EQ(found.routes, record_route.routes);
}
コード例 #14
0
ファイル: ip.hpp プロジェクト: flixster/mesos
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();
  }
}
コード例 #15
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
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>());
}
コード例 #16
0
ファイル: IPTest.cpp プロジェクト: rayfill/cpplib
	void resolveMachineName()
	{	
		try
		{
			ip.setIp("210.150.25.37");
			CPPUNIT_ASSERT_MESSAGE(ip.getHostname(),
								   ip.getHostname() == 
								   "www.goo.ne.jp");
		}
		catch (std::exception& e)
		{
			CPPUNIT_FAIL(e.what());
		}
	}
コード例 #17
0
ファイル: pdu.cpp プロジェクト: Imva/libtins
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()));
}
コード例 #18
0
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;
}
コード例 #19
0
ファイル: IP.cpp プロジェクト: uvRen/oru-simbeh131
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';
}
コード例 #20
0
ファイル: main.c プロジェクト: benmcmorran/aitf
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;
}
コード例 #21
0
ファイル: AddressBar.cpp プロジェクト: GMIS/GMIS
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;	
}
コード例 #22
0
ファイル: Address.cpp プロジェクト: lilinhan/NetLibrary
 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();
 }
コード例 #23
0
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;
}
コード例 #24
0
ファイル: traceroute.cpp プロジェクト: Temptationx/libtins
    bool sniff_callback(PDU &pdu) {
        const IP &ip = pdu.rfind_pdu<IP>();
        ttl_map::const_iterator iter;
        // Fetch the IP PDU attached to the ICMP response
        const IP inner_ip = pdu.rfind_pdu<RawPDU>().to<IP>();
        // Critical section
        {
            std::lock_guard<std::mutex> _(lock);
            iter = ttls.find(inner_ip.id());
        } 

        // It's an actual response
        if(iter != ttls.end()) {
            // Store it
            results[inner_ip.id()] = ip.src_addr();
        }
        return running;
    }
コード例 #25
0
ファイル: IPTest.hpp プロジェクト: hyassine/MKb
		void run()
		{
			// Test IP construction
			IP fromString("192.168.0.1");

			if (fromString.getOctet(0) != 192
			        || fromString.getOctet(1) != 168
			        || fromString.getOctet(2) != 0
			        || fromString.getOctet(3) != 1)
				throw TestFailedException("An IP could not be properly constructed from a string.");

			// Test provided octet construction
			IP fromOctets(192, 168, 0, 1);

			if (fromOctets.getOctet(0) != 192
			        || fromOctets.getOctet(1) != 168
			        || fromOctets.getOctet(2) != 0
			        || fromOctets.getOctet(3) != 1)
				throw TestFailedException("An IP could not be properly constructed from octets.");

			// Test string representation
			if (strcmp("192.168.0.1", fromOctets.getAsString().c_str()) != 0)
				throw TestFailedException("An IP's string representation was incorrect.");

			// Test inequality
			if (fromString != fromOctets)
				throw TestFailedException("Inequality operator failed");

			// Test equality
			IP different = (std::string) "127.0.0.1";

			if (different.getOctet(0) != 127 || different.getOctet(1) != 0
			        || different.getOctet(2) != 0 || different.getOctet(3) != 1)
				throw TestFailedException("An IP could not be constructed from a string.");

			if (fromOctets == different)
				throw TestFailedException("Equality operator failed");

			// Test assignment from string
			different = "74.125.113.99";

			if (different.getOctet(0) != 74
			        || different.getOctet(1) != 125
			        || different.getOctet(2) != 113
			        || different.getOctet(3) != 99)
				throw TestFailedException("An IP could not be assigned from a string.");

			// Test binary representation
			unsigned int binRep = (208 << 24) + (47 << 16) + (17 << 8) + 18;
			IP fromBin(binRep, IP::BO_HOST);

			if (binRep != fromBin.getAsBinary(IP::BO_HOST))
				throw TestFailedException("An IP's binary representation was incorrect.");
		}
コード例 #26
0
void IPResolver::start_resolve()
{
    if (resolver && resolver->isWorking()) return;
    if (queue.empty())
        return;
    IP *ip = *queue.begin();
    m_addr = ip->ip();
    struct in_addr inaddr;
    inaddr.s_addr = m_addr;
    log(L_DEBUG, "start resolve %s", inet_ntoa(inaddr));
#if COMPAT_QT_VERSION >= 0x030000
    if (resolver)
        delete resolver;
    resolver = new QDns(QHostAddress(htonl(m_addr)), QDns::Ptr);
    connect(resolver, SIGNAL(resultsReady()), this, SLOT(resolve_ready()));
#else
    resolver->setLabel(QHostAddress(htonl(m_addr)));
#endif
}
コード例 #27
0
ファイル: ip_reassembler.cpp プロジェクト: UlfWetzker/libtins
IPv4Reassembler::PacketStatus IPv4Reassembler::process(PDU& pdu) {
    IP* ip = pdu.find_pdu<IP>();
    if (ip && ip->inner_pdu()) {
        // There's fragmentation
        if (ip->is_fragmented()) {
            key_type key = make_key(ip);
            // Create it or look it up, it's the same
            Internals::IPv4Stream& stream = streams_[key];
            stream.add_fragment(ip);
            if (stream.is_complete()) {
                PDU* pdu = stream.allocate_pdu();
                // Use all field values from the first fragment
                *ip = stream.first_fragment();

                // Erase this stream, since it's already assembled
                streams_.erase(key);
                // The packet is corrupt
                if (!pdu) {
                    return FRAGMENTED;
                }
                ip->inner_pdu(pdu);
                ip->fragment_offset(0);
                ip->flags(static_cast<IP::Flags>(0));
                return REASSEMBLED;
            }
            else {
                return FRAGMENTED;
            }
        }
    }
    return NOT_FRAGMENTED;
}
コード例 #28
0
ファイル: ip.cpp プロジェクト: DaTrollMon/libtins
TEST_F(IPTest, DefaultConstructor) {
    IP ip;
    EXPECT_EQ(ip.dst_addr(), "0.0.0.0");
    EXPECT_EQ(ip.src_addr(), "0.0.0.0");
    EXPECT_EQ(ip.version(), 4);
    EXPECT_EQ(ip.id(), 1);
    EXPECT_EQ(ip.pdu_type(), PDU::IP);
}
コード例 #29
0
ファイル: net.hpp プロジェクト: AbheekG/mesos
// TODO(evelinad): Move this to Address.
inline struct sockaddr_storage createSockaddrStorage(const IP& ip, int port)
{
  struct sockaddr_storage storage;
  memset(&storage, 0, sizeof(storage));

  switch (ip.family()) {
    case AF_INET: {
      struct sockaddr_in addr;
      memset(&addr, 0, sizeof(addr));
      addr.sin_family = AF_INET;
      addr.sin_addr = ip.in().get();
      addr.sin_port = htons(port);

      memcpy(&storage, &addr, sizeof(addr));
      break;
    }
    default: {
      ABORT("Unsupported family type: " + stringify(ip.family()));
    }
  }

  return storage;
}
コード例 #30
0
ファイル: traceroute.cpp プロジェクト: Temptationx/libtins
 void send_packets(PacketSender &sender) {
     // ICMPs are icmp-requests by default
     IP ip = IP(addr, iface.addresses().ip_addr) / ICMP();
     // We'll find at most 10 hops.
     
     for(auto i = 1; i <= 10; ++i) {
         // Set this "unique" id
         ip.id(i);
         // Set the time-to-live option
         ip.ttl(i);
         
         // Critical section
         {
             std::lock_guard<std::mutex> _(lock);
             ttls[i] = i;
         }
         
         sender.send(ip);
         // Give him a little time
         std::this_thread::sleep_for(std::chrono::milliseconds(100));
     }
     running = false;
     sender.send(ip);
 }