In the NAT application, I only relay ICMP( ping ) packets
The NAT has 2 interface, one is ethernet connecting local network
, the other is PPP for internet.
It can get the packets from the client,
adn when the NAT replace the dest ip address, re-calc the checksum, and
send to MSTCP stack. We never get the response, NO data received
from the PPP adapter. Is there any problem with my code?
Another ques: when I call SendPacketToMstcp(), should I also get this packet
at PACKET_FLAG_ON_SEND at the other adapter when MSTCP send it to interface?
I tried, but not get the packet.
Below is my code.
….
// set MODE to MSTCP_FLAG_SENT_TUNNEL|MSTCP_FLAG_RECV_TUNNEL to all adapters
….
while (!bAppClose)
{
dwRe=WaitForMultipleObjects(nCount, arrEvents, FALSE , 1000);
if( ( dwRe < WAIT_OBJECT_0 )|| ( dwRe > WAIT_OBJECT_0+nCount-1) )
continue ;
hEvent=arrEvents[dwRe-WAIT_OBJECT_0];
ResetEvent(hEvent);
/// find associated Adapter
if ( !mapAdapter.Lookup( hEvent, adp ))
continue ;
ZeroMemory ( &Request, sizeof(ETH_REQUEST) );
ZeroMemory ( &PacketBuffer, sizeof(INTERMEDIATE_BUFFER) );
Request.EthPacket.Buffer = &PacketBuffer;
Request.hAdapterHandle = (HANDLE)adp.hAdpHandle;
while(api.ReadPacket(&Request))
{
/// read data
if (PacketBuffer.m_dwDeviceFlags == PACKET_FLAG_ON_SEND)
{
api.SendPacketToAdapter(&Request);
}
else
{
pEthHeader = (ether_header*)PacketBuffer.m_IBuffer;
if(ntohs(pEthHeader->h_proto) == ETH_P_IP)
{
pIpHeader=(iphdr*)(PacketBuffer.m_IBuffer +14 );
//// substitute the source ip with nat address
pIpHeader->ip_src=natAddr;
pIpHeader->ip_sum=0;
/// calac the checksum
pIpHeader->ip_sum=ip_checksum((unsigned char*)pIpHeader, 20 );
}
// send packet to MSTCP
api.SendPacketToMstcp(&Request);
}
}
}