Send out modified ip packets, but no reponse ( NAT )

Home Forums Discussions Support Send out modified ip packets, but no reponse ( NAT )

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4876
    hoowaycn
    Participant

      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);
      }
      }

      }

      #5627
      Vadim Smirnov
      Keymaster

        In order to analyze your code I would also need to analyze the environment it runs in. However, check if you have enable IP routing (forwarding) since it is disabled by the default and TCP/IP will just drop the packets from the interface if they don’t match interface address information.

        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.

        No, this flag has informational purpose only (for you reference if packet was received from the network or from the stack).

        #5628
        hoowaycn
        Participant

          It’s XP. For the PPP, I use RasPPPoE.

          Enable IP routing? Do you mean set
          HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters
          IPEnableRouter to 1.

          Oh, I did it.

          And test again, still no response!!

          Do you need to see the whole code?

          #5629
          hoowaycn
          Participant

            I run a sniffer to monitor the packets
            and find that MSTCP doest not send out my nat packets.
            What’s reason cause it to drop the packets?

            Can someone send a NAT sample, so I can whether it computer
            configuration problem or my nat problem.

            #5630
            hoowaycn
            Participant

              Can anyone help me to solve this problem?If I solve this problem in my evaluation, I would purchase one.

            Viewing 5 posts - 1 through 5 (of 5 total)
            • You must be logged in to reply to this topic.