diff --git a/.gitignore b/.gitignore index 8f3f28f..0ec54b2 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,15 @@ *.exe *.out *.app +/build/ +/dist/ + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +.nb-gradle/ diff --git a/1T1NAT.cbp b/1T1NAT.cbp deleted file mode 100644 index 593597a..0000000 --- a/1T1NAT.cbp +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - diff --git a/1T1NAT.depend b/1T1NAT.depend deleted file mode 100644 index c2ffe37..0000000 --- a/1T1NAT.depend +++ /dev/null @@ -1,35 +0,0 @@ -# depslib dependency file v1.0 -1439147884 source:/home/dev/projects/1T1NAT/main.cpp - - - - -1439937901 source:/home/dev/projects/1T1NAT/src/map/natmap.cpp - "natmap.h" - -1439938543 /home/dev/projects/1T1NAT/src/map/natmap.h - - - - - -1439326884 source:/home/dev/projects/1T1NAT/test/unittest_main.cpp - "UnitTest++/UnitTest++.h" - "../src/map/natmap.h" - - - -1439500558 source:/home/dev/projects/1T1NAT/test/case/testcaseipcalc.cpp - "UnitTest++/UnitTest++.h" - "../../src/map/natmap.h" - - - -1439325103 source:/home/dev/projects/1T1NAT/test/suite/testsuitearp.cpp - -1439325103 source:/home/dev/projects/1T1NAT/test/suite/testsuiteip.cpp - -1439327293 source:/home/dev/projects/1T1NAT/test/suite/testsuitenat.cpp - "UnitTest++/UnitTest++.h" - "../../src/map/natmap.h" - diff --git a/1T1NAT.layout b/1T1NAT.layout deleted file mode 100644 index c0aba56..0000000 --- a/1T1NAT.layout +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 0b0ecc6..0000000 --- a/main.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include -#include -#include - -using namespace std; -using namespace Tins; - -const IPv4Address calcAdress(const IPv4Address & ip) -{ - IPv4Address incommingIp = IPv4Address(ip); - IPv4Address networkStartIp = IPv4Address("10.0.0.0"); - IPv4Address subnetp = IPv4Address("255.255.240.0"); - - uint32_t ipInt = (incommingIp & ~subnetp) | networkStartIp; - IPv4Address result = IPv4Address(ipInt); - std::cout << "Destination address: " << incommingIp << std::endl; - std::cout << "new Destination address: " << result<< std::endl; - std::cout << "####"<< std::endl; - return result; -} - -bool arpm(const PDU &pdu) -{ - // Retrieve the ARP layer - const ARP &arp = pdu.rfind_pdu(); - std::cout << arp.opcode()<< std::endl; - if (arp.opcode() == ARP::REQUEST) - { - PacketSender sender; - const NetworkInterface iface("vboxnet0"); - EthernetII req = ARP::make_arp_request(calcAdress(arp.target_ip_addr()),"10.0.3.42","08:00:27:d3:ef:1e"); - sender.send(req, iface); - } - - return true; -} - -bool arpm2(const PDU &pdu) -{ - // Retrieve the ARP layer - const ARP &arp = pdu.rfind_pdu(); - - std::cout << arp.opcode()<< std::endl; - if (arp.opcode() == ARP::REPLY) - { - PacketSender sender; - const NetworkInterface iface("vboxnet1"); - EthernetII rep = ARP::make_arp_reply("172.16.3.42","172.17.0.20","08:00:27:d3:ef:1e","08:00:27:29:f2:55"); - sender.send(rep, iface); - } else if (arp.target_ip_addr().to_string() == "10.0.3.42") - { - PacketSender sender; - const NetworkInterface iface("vboxnet0"); - EthernetII rep = ARP::make_arp_reply("10.0.0.20","10.0.3.42","08:00:27:29:f2:55","08:00:27:d3:ef:1e"); - sender.send(rep, iface); - } - - return true; -} - -bool doo(PDU &some_pdu) -{ - //PacketWriter writer("before.pcap", PacketWriter::ETH2); - //writer.write(some_pdu); - - IP &ip = some_pdu.rfind_pdu(); - ip.dst_addr(calcAdress(ip.dst_addr())); - ip.src_addr("10.0.3.42"); - //writer = PacketWriter("after.pcap", PacketWriter::ETH2); - //writer.write(some_pdu); - PacketSender sender; - some_pdu.send(sender,"vboxnet0"); - return true; -} - - - -void test1() -{ - SnifferConfiguration config; - config.set_promisc_mode(true); - config.set_immediate_mode(true); - //config.set_filter("ip src 192.168.0.100"); - Sniffer sniffer("vboxnet1", config); - sniffer.sniff_loop(arpm); -} - -void test2() -{ - SnifferConfiguration config; - config.set_promisc_mode(true); - config.set_immediate_mode(true); - //config.set_filter("ip src 192.168.0.100"); - Sniffer sniffer("vboxnet0", config); - sniffer.sniff_loop(arpm2); -} - -void test3() -{ - SnifferConfiguration config; - config.set_promisc_mode(true); - config.set_immediate_mode(true); - //config.set_filter("ip src 192.168.0.100"); - Sniffer sniffer("vboxnet1", config); - sniffer.sniff_loop(doo); -} - -int main() -{ - thread t1(test1); - thread t2(test2); - thread t3(test3); - t1.join(); - t2.join(); - t3.join(); - return 0; -} - diff --git a/test/case/testcaseipcalc.cpp b/test/case/testcaseipcalc.cpp deleted file mode 100644 index 2a90cb2..0000000 --- a/test/case/testcaseipcalc.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "UnitTest++/UnitTest++.h" -#include "../../src/map/natmap.h" -#include -#include - -SUITE(NatTests) -{ - class NatTestFixure - { - public: - otonat::NatMap natMap = otonat::NatMap(); - - Tins::IPv4Address deviceIpEth0 = Tins::IPv4Address("10.0.3.40"); - - Tins::IPv4Address deviceIpEth1 = Tins::IPv4Address("192.168.23.42"); - - Tins::IPv4Address deviceIpEth2 = Tins::IPv4Address("172.27.123.4"); - - Tins::NetworkInterface::Info eth0Info = - { - .ip_addr = Tins::IPv4Address("10.0.0.2"), - .netmask = Tins::IPv4Address("255.0.0.0"), - .bcast_addr = Tins::IPv4Address("10.255.255.255"), - .hw_addr = Tins::HWAddress<6>("00:00:00:00:00:01"), - .is_up = true - }; - - Tins::NetworkInterface::Info eth1Info = - { - .ip_addr = Tins::IPv4Address("192.168.23.42"), - .netmask = Tins::IPv4Address("255.255.255.0"), - .bcast_addr = Tins::IPv4Address("192.168.23.255"), - .hw_addr = Tins::HWAddress<6>("00:00:00:00:00:02"), - .is_up = true - }; - - Tins::NetworkInterface::Info eth2Info = - { - .ip_addr = Tins::IPv4Address("172.16.47.11"), - .netmask = Tins::IPv4Address("255.240.0.0"), - .bcast_addr = Tins::IPv4Address("172.31.255.255"), - .hw_addr = Tins::HWAddress<6>("00:00:00:00:00:03"), - .is_up = true - }; - }; - - TEST_FIXTURE(NatTestFixure, NetworkInterfaces) - { - CHECK(!natMap.interfaces.empty()); - } - - TEST_FIXTURE(NatTestFixure, IpCalcEth0) - { - Tins::IPv4Address expetedIp = deviceIpEth0; - Tins::IPv4Address resultIp = natMap.mapIPv4Address(deviceIpEth0, eth0Info); - CHECK_EQUAL(expetedIp,resultIp); - - expetedIp = Tins::IPv4Address("10.168.23.42"); - resultIp = natMap.mapIPv4Address(deviceIpEth1, eth0Info); - CHECK_EQUAL(expetedIp,resultIp); - - expetedIp = Tins::IPv4Address("10.27.123.4"); - resultIp = natMap.mapIPv4Address(deviceIpEth2, eth0Info); - CHECK_EQUAL(expetedIp,resultIp); - } - - TEST_FIXTURE(NatTestFixure, IpCalcEth1) - { - Tins::IPv4Address expetedIp = Tins::IPv4Address("192.168.23.40"); - Tins::IPv4Address resultIp = natMap.mapIPv4Address(deviceIpEth0, eth1Info); - CHECK_EQUAL(expetedIp,resultIp); - - expetedIp = deviceIpEth1; - resultIp = natMap.mapIPv4Address(deviceIpEth1, eth1Info); - CHECK_EQUAL(expetedIp,resultIp); - - expetedIp = Tins::IPv4Address("192.168.23.4"); - resultIp = natMap.mapIPv4Address(deviceIpEth2, eth1Info); - CHECK_EQUAL(expetedIp,resultIp); - } - - TEST_FIXTURE(NatTestFixure, IpCalcEth2) - { - Tins::IPv4Address expetedIp = Tins::IPv4Address("172.16.3.40"); - Tins::IPv4Address resultIp = natMap.mapIPv4Address(deviceIpEth0, eth2Info); - CHECK_EQUAL(expetedIp,resultIp); - - expetedIp = Tins::IPv4Address("172.24.23.42"); - resultIp = natMap.mapIPv4Address(deviceIpEth1, eth2Info); - CHECK_EQUAL(expetedIp,resultIp); - - expetedIp = deviceIpEth2; - resultIp = natMap.mapIPv4Address(deviceIpEth2, eth2Info); - CHECK_EQUAL(expetedIp,resultIp); - } - - TEST(TestHandlePDU) - { - Tins::EthernetII eth = Tins::EthernetII() / Tins::IP() / Tins::TCP(); - otonat::NatMap natMap = otonat::NatMap(); - natMap.handlePdu(ð); - } - -} diff --git a/test/unittest_main.cpp b/test/unittest_main.cpp deleted file mode 100644 index e8a5055..0000000 --- a/test/unittest_main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "UnitTest++/UnitTest++.h" -#include "../src/map/natmap.h" -#include -#include - -int main(int, const char *[]) -{ - return UnitTest::RunAllTests(); -}