rm old giles
This commit is contained in:
12
.gitignore
vendored
12
.gitignore
vendored
@@ -29,3 +29,15 @@
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
/build/
|
||||
/dist/
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
.nb-gradle/
|
||||
|
||||
95
1T1NAT.cbp
95
1T1NAT.cbp
@@ -1,95 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="1T1NAT" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Option extended_obj_names="1" />
|
||||
<Build>
|
||||
<Target title="UnitTest">
|
||||
<Option output="bin/UnitTest/1T1NAT" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/UnitTest/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Option host_application="sudo" />
|
||||
<Option run_host_application_in_terminal="1" />
|
||||
<Compiler>
|
||||
<Add option="-std=c++11" />
|
||||
<Add option="-Wfatal-errors" />
|
||||
<Add option="-Wextra" />
|
||||
<Add option="-Wall" />
|
||||
<Add option="-g" />
|
||||
<Add option="-pthread" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="/usr/local/lib/libtins.so.3.3" />
|
||||
<Add library="/lib/libpthread.so" />
|
||||
<Add library="/usr/local/lib/libUnitTest++.a" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/1T1NAT" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Option host_application="sudo" />
|
||||
<Option run_host_application_in_terminal="1" />
|
||||
<Compiler>
|
||||
<Add option="-std=c++11" />
|
||||
<Add option="-g" />
|
||||
<Add option="-pthread" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="/usr/local/lib/libtins.so.3.3" />
|
||||
<Add library="/lib64/libpthread.so" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/1T1NAT" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="main.cpp">
|
||||
<Option target="Debug" />
|
||||
<Option target="Release" />
|
||||
</Unit>
|
||||
<Unit filename="src/map/natmap.cpp" />
|
||||
<Unit filename="src/map/natmap.h" />
|
||||
<Unit filename="test/case/testcaseipcalc.cpp">
|
||||
<Option target="UnitTest" />
|
||||
</Unit>
|
||||
<Unit filename="test/suite/testsuitearp.cpp">
|
||||
<Option target="UnitTest" />
|
||||
</Unit>
|
||||
<Unit filename="test/suite/testsuiteip.cpp">
|
||||
<Option target="UnitTest" />
|
||||
</Unit>
|
||||
<Unit filename="test/suite/testsuitenat.cpp">
|
||||
<Option target="UnitTest" />
|
||||
</Unit>
|
||||
<Unit filename="test/unittest_main.cpp">
|
||||
<Option target="UnitTest" />
|
||||
</Unit>
|
||||
<Extensions>
|
||||
<envvars />
|
||||
<code_completion />
|
||||
<lib_finder disable_auto="1">
|
||||
<lib name="libtins" />
|
||||
</lib_finder>
|
||||
<debugger />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
@@ -1,35 +0,0 @@
|
||||
# depslib dependency file v1.0
|
||||
1439147884 source:/home/dev/projects/1T1NAT/main.cpp
|
||||
<iostream>
|
||||
<tins/tins.h>
|
||||
<thread>
|
||||
|
||||
1439937901 source:/home/dev/projects/1T1NAT/src/map/natmap.cpp
|
||||
"natmap.h"
|
||||
|
||||
1439938543 /home/dev/projects/1T1NAT/src/map/natmap.h
|
||||
<vector>
|
||||
<map>
|
||||
<queue>
|
||||
<tins/tins.h>
|
||||
|
||||
1439326884 source:/home/dev/projects/1T1NAT/test/unittest_main.cpp
|
||||
"UnitTest++/UnitTest++.h"
|
||||
"../src/map/natmap.h"
|
||||
<tins/tins.h>
|
||||
<vector>
|
||||
|
||||
1439500558 source:/home/dev/projects/1T1NAT/test/case/testcaseipcalc.cpp
|
||||
"UnitTest++/UnitTest++.h"
|
||||
"../../src/map/natmap.h"
|
||||
<tins/tins.h>
|
||||
<vector>
|
||||
|
||||
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"
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<ActiveTarget name="UnitTest" />
|
||||
<File name="src/map/natmap.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1544" topLine="21" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1963" topLine="51" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/map/natmap.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="258" topLine="138" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="test/unittest_main.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="107" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="test/suite/testsuitenat.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="87" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="test/case/testcaseipcalc.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="3433" topLine="62" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
118
main.cpp
118
main.cpp
@@ -1,118 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <tins/tins.h>
|
||||
#include <thread>
|
||||
|
||||
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<ARP>();
|
||||
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<ARP>();
|
||||
|
||||
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>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
#include "../../src/map/natmap.h"
|
||||
#include <tins/tins.h>
|
||||
#include <vector>
|
||||
|
||||
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(ð);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "UnitTest++/UnitTest++.h"
|
||||
#include "../src/map/natmap.h"
|
||||
#include <tins/tins.h>
|
||||
#include <vector>
|
||||
|
||||
int main(int, const char *[])
|
||||
{
|
||||
return UnitTest::RunAllTests();
|
||||
}
|
||||
Reference in New Issue
Block a user