The EthernetBridge example is a simple C++ program that implements an Ethernet bridge. An Ethernet bridge is a network device that connects two or more Ethernet networks together by forwarding frames between the networks based on their MAC addresses.
init() - This function initializes the bridge. It performs the following operations:
- Opens the network interfaces.
- Creates a list of MAC addresses for each network interface.
- Creates a table of MAC addresses to network interfaces.
run() - This function is the main loop of the bridge. It continuously receives frames from the network interfaces and forwards them to the appropriate network. It performs the following operations:
- Receives a frame from a network interface.
- Looks up the destination MAC address in the table of MAC addresses to network interfaces.
- If the destination MAC address is found, forwards the frame to the network interface associated with the destination MAC address.
- If the destination MAC address is not found, drops the frame.
- The code uses the NDISAPI to open and manage network interfaces.
- The code uses a table of MAC addresses to network interfaces to keep track of which network interface is associated with each MAC address.
- The code uses a loop to continuously receive frames from the network interfaces and forward them to the appropriate network.
- The code drops frames that do not have a destination MAC address.
Please read this blog post