|
@ -11,7 +11,7 @@ void NATRouter::initalizeNatTable() |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
natTable = new NATItem[65536]; |
|
|
|
|
|
|
|
|
natTable = new NATItem[NAT_TABLE_LEN]; |
|
|
} |
|
|
} |
|
|
catch (bad_alloc &ba) |
|
|
catch (bad_alloc &ba) |
|
|
{ |
|
|
{ |
|
@ -42,7 +42,7 @@ NATRouter::NATRouter(string hostname, string ip, string mask, string gatewayIp) |
|
|
|
|
|
|
|
|
int NATRouter::getFreePort() |
|
|
int NATRouter::getFreePort() |
|
|
{ |
|
|
{ |
|
|
for (int i=1; i<65536; ++i) |
|
|
|
|
|
|
|
|
for (int i=1; i<NAT_TABLE_LEN; ++i) |
|
|
if (this->natTable[i].isFree()) |
|
|
if (this->natTable[i].isFree()) |
|
|
return i; |
|
|
return i; |
|
|
|
|
|
|
|
@ -209,13 +209,40 @@ string NATRouter::getWanNetwork() |
|
|
*/ |
|
|
*/ |
|
|
int NATRouter::getAllocatedPort(string srcIp, int srcPort) |
|
|
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) |
|
|
if (this->natTable[i].getIp() == srcIp && this->natTable[i].getPort() == srcPort) |
|
|
return i; |
|
|
return i; |
|
|
|
|
|
|
|
|
return -1; // nic nie znaleziono
|
|
|
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() |
|
|
string NATRouter::getWanGatewayIp() |
|
|
{ |
|
|
{ |
|
|
return this->netWanConf.gatewayIp; |
|
|
return this->netWanConf.gatewayIp; |
|
|