|
|
@ -11,7 +11,7 @@ void NATRouter::initalizeNatTable() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
natTable = new NATItem[65536]; |
|
|
|
natTable = new NATItem[NAT_TABLE_LEN]; |
|
|
|
} |
|
|
|
catch (bad_alloc &ba) |
|
|
|
{ |
|
|
@ -42,7 +42,7 @@ NATRouter::NATRouter(string hostname, string ip, string mask, string gatewayIp) |
|
|
|
|
|
|
|
int NATRouter::getFreePort() |
|
|
|
{ |
|
|
|
for (int i=1; i<65536; ++i) |
|
|
|
for (int i=1; i<NAT_TABLE_LEN; ++i) |
|
|
|
if (this->natTable[i].isFree()) |
|
|
|
return i; |
|
|
|
|
|
|
@ -209,13 +209,40 @@ string NATRouter::getWanNetwork() |
|
|
|
*/ |
|
|
|
int NATRouter::getAllocatedPort(string srcIp, int srcPort) |
|
|
|
{ |
|
|
|
for (int i=1; i<65536; ++i) |
|
|
|
for (int i=1; i<NAT_TABLE_LEN; ++i) |
|
|
|
if (this->natTable[i].getIp() == srcIp && this->natTable[i].getPort() == srcPort) |
|
|
|
return i; |
|
|
|
|
|
|
|
return -1; // nic nie znaleziono
|
|
|
|
} |
|
|
|
|
|
|
|
void NATRouter::freePorts() |
|
|
|
{ |
|
|
|
stringstream ss; |
|
|
|
int i, ports; |
|
|
|
|
|
|
|
Log portsLog; |
|
|
|
string name = "NAT"; |
|
|
|
portsLog.setLogParams(10, BLUE, "\t\t"); |
|
|
|
portsLog.setObjectName(&name); |
|
|
|
|
|
|
|
while(true) |
|
|
|
{ |
|
|
|
ports = 0; |
|
|
|
ss.str(""); |
|
|
|
|
|
|
|
for (i=1; i<NAT_TABLE_LEN; ++i) |
|
|
|
if (this->natTable[i].isFree()) |
|
|
|
++ports; |
|
|
|
|
|
|
|
ss << "Free:\t" << ports << "\t\tReserved:\t" << (NAT_TABLE_LEN-ports-1); // poprawka na nieuzywany port 0
|
|
|
|
|
|
|
|
portsLog.print(ss.str()); |
|
|
|
portsLog.delay(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
string NATRouter::getWanGatewayIp() |
|
|
|
{ |
|
|
|
return this->netWanConf.gatewayIp; |
|
|
|