Home › Forums › Discussions › Support › Trying to understand the Bridge example
- This topic has 5 replies, 2 voices, and was last updated 1 year, 9 months ago by AndyG.
-
AuthorPosts
-
January 29, 2023 at 4:32 pm #12790
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.
January 29, 2023 at 5:40 pm #12792There are two possible approaches to Ethernet bridge implementation:
- Turn on promiscuous mode on both bridged interfaces and relay packets between these.
- 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.
January 29, 2023 at 6:17 pm #12793Hi 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
January 29, 2023 at 6:31 pm #12794Sorry. 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)
January 30, 2023 at 10:03 pm #12795Does anyone have a C# example for this?
January 31, 2023 at 4:05 pm #12796I figured out my mistake. I wasn’t looping the ReadPackets Function and the internal buffer was filling up.
-
AuthorPosts
- You must be logged in to reply to this topic.