NAT Operation
B-15
Network Address Translation
IPNew |= ((UINT32)GetVal(&pData)) << 16;
IPNew |= ((UINT32)GetVal(&pData)) << 8;
IPNew |= ((UINT32)GetVal(&pData));
IPNew = htonl( IPNew );
PortNew = GetVal(&pData);
PortNew = (PortNew<<8) + GetVal(&pData);
// Add a NAT mapping to client’s IP and Port
hNAT = NatNew( IPNew, PortNew, pNI–>IPForeign, 0, IPPROTO_TCP,
0, NAT_IDLE_SECONDS );
if( !hNAT )
return(0);
// Get Server IP and Mapped Port
IPNew = htonl( NatIpServer );
pNINew = NatGetPNI( hNAT );
PortNew = pNINew–>PortMapped;
// Print a repalcement string with with IP and Port
sprintf( tmpstr, ”%u,%u,%u,%u,%u,%u\r\n”,
((uint)(IPNew >> 24)),
((uint)(IPNew >> 16)&0xFF),
((uint)(IPNew >> 8)&0xFF),
((uint)(IPNew)&0xFF),
PortNew>>8, PortNew&0xFF );
// Replace the original string with ours
ProxyPacketMod( 5, Length–5, strlen(tmpstr), tmpstr );
}
return(1);
}