Trying to understand the Bridge example

Home Forums Discussions Support Trying to understand the Bridge example

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12790
    AndyG
    Participant

      Hi, thanks for providing this great networking lib.

      I am trying to convert the Bridge example to a language called ‘Purebasic’. It’s a procedural language and produces very fast code. I am using the dll C style.

      I have a dual 10G intel pcie adapter adapter installed and 2 Mikrotik routers,  1 connected to each port. One router is a DHCP server, the other a DHCP Client. My application has 2 threads, 1 for each network interface port.

      My problem is, i dont understand anything from the C++ example, i should have learnt C++ years ago. The DHCP Client does get an ip address sometimes but it takes a long time when it does get one. Pings timeout.

      At the moment, i am reading a packet and when PACKET_FLAG_ON_RECEIVE is triggered, i copy the packet and send it to the other adapter. The second thread does the same this for the other nic port. The packets are not destined for the PC the app is running on. Can you give me any clues to where i am going wrong? Or can you give me a basic flow of what i should be doing? Do i need to change change the mac address of the packets?

      Sorry for the amount of questions.

      #12792
      Vadim Smirnov
      Keymaster

        There are two possible approaches to Ethernet bridge implementation:

        1. Turn on promiscuous mode on both bridged interfaces and relay packets between these.
        2. Do MAC address translation. This approach is similar to how IP address NAT implemented.

        EBRIDGE sample implements the first, it is a bit slower (due to using promiscuous mode) but easier to understand. The only complex part is bridging Wi-Fi to wired LAN, where you still need the MAC address translation.

        I would also recommend unchecking the IPv4/IPv6 protocols on the NIC’s you are bridging, especially if you are using MAC address translation because it tends to confuse some routers (two IPs on the same MAC).

        Since both your network adapters are wired, the simple approach should work. Just forward packets received from one to another and vice versa without changing them.

        #12793
        AndyG
        Participant

          Hi thanks for the quick reply. I have found where the problem is but I am not sure what to do. When I copy the received packet ready for sending to the adapter, I am doing something wrong with the size. I tried fixing the the amount I copy to 1540 bytes just to see if something changed and it did. I can ping and get an ip everytime but bandwidth is low. I am sure now that i am not calculation the length for the packet send

          #12794
          AndyG
          Participant

            Sorry. How should I populate the _INTERMEDIATE_BUFFER for sending the packet to the adapter?

            This is what I tried originally,

            CopyMemory(recv_buf\m_IBuffer, send_buf\m_IBuffer, recv_buf\m_Length)

            send_buf\m_Length = recv_buf\m_Length

            send_buf\m_Flags = #NDIS_PACKET_TYPE_PROMISCUOUS

            SendPacketToAdapter(val\filter, val\send_pkt)

            #12795
            AndyG
            Participant

              Does anyone have a C# example for this?

              #12796
              AndyG
              Participant

                I figured out my mistake. I wasn’t looping the ReadPackets Function and the internal buffer was filling up.

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