|
NetBurner 3.5.8
PDF Version |
Example Path: examples/MultiHome
A NetBurner TCP/IP Stack example demonstrating IPv4 multihoming capabilities.
This application demonstrates how to put multiple IP addresses on a single NetBurner device using the Multihome functionality. The device runs one HTTP server that responds on every configured address at once:
Browse to any of the device's addresses and you reach the same web server; the served page reports which address the request actually arrived on.
Before building and running this application, you must enable multihome support:
The application example includes a predef-overload.h file that automatically enables:
MULTIHOME functionalityNUM_MULTI_INTERFACES)The file utilizes the NetBurner overload feature by locating the file at: \MultiHome\overload\nbrtos\include\predef-overload.h
This way NetBurner system file predef.h does not need to be mofified. See the OverloadDirectory example or the Overload section of this manual for more information.
Alternatively, you can modify the NetBurner predef.h system file as described below:
\nburn\nbrtos\include\predef.hMULTIHOME definitioninit() and addressed via DHCP (falling back to AutoIP if no DHCP server responds)AddInterface()AddSameSubnetMultihome() reads the physical interface's address/mask/gateway, scans its subnet for a free address, and adds the first one that passes a conflict checkAdding a second address on the same subnet risks colliding with another device, so the example checks before it claims one. ICMP echo (ping) alone is unreliable — many hosts drop ping but still answer ARP — so the check is ARP-based (the mechanism behind RFC 5227 Address Conflict Detection):
AddressInUse() pings a candidate to trigger ARP resolution, then reads the ARP cache with GetArpMacFromIp(). A cache hit means a host answered ARP, so the address is taken.AddInterface(addr, mask, gateway, physicalIfNum).IsMyAddressUsedArpDetect() runs a final RFC-5227 conflict check on the now-assigned address; on conflict the example calls Removeinterface() and tries the next candidate.sendGratuitousArp() announces the claimed address to update neighbor caches.Note that probing only detects addresses that are currently online; choosing from outside any DHCP pool is still advisable.
The application starts an HTTP server that answers on every configured address. Access the web page using any of the device's IP addresses to see:
The page is built from a static HTML shell; the device fills in the live values through CPPCALL handlers (ShowRequestPath and ShowInterfaceTable). Reloading through a different device address changes the highlighted row – a concrete demonstration of multihoming.
At boot the application prints every interface and its IP address to the debug serial port.
main.cpp: Application logic and the web page's CPPCALL handlershtml/index.html: Static page shell with CPPCALL placeholders for the live datahtml/style.css, html/logo.png: Self-contained styling for the page (no framework or CDN)predef-overload.h: Compiler definitions for multihome supportUserMain(): Main application entry point; starts HTTP and adds the multihome addressesAddInterface(): Adds a multihome IP address at runtimeAddSameSubnetMultihome(): Finds and adds a free address on the physical interface's subnetAddressInUse(): ARP-based conflict probe for a candidate addressShowRequestPath(): CPPCALL handler – reports the local (served) and client IP for the requestShowInterfaceTable(): CPPCALL handler – enumerates all interfaces and emits the address tableThe fixed multihome interface is configured with:
IPADDR4::NullIP())The null gateway is intentional and illustrative: a multihome address only needs to answer requests that arrive on it (a purely local exchange), so no gateway is required. You would supply one only if the device had to originate traffic off that subnet through this interface. By contrast, the auto-picked multihome address copies the primary interface's mask and gateway, so on the same subnet it shares the primary's gateway.
Ensure your network topology can accommodate this address range if you plan to access the multihome address.
examples/VLan): the VLAN counterpart of this example — uses the same MULTIHOME support to add tagged VLAN interfaces (VLAN IDs) on one Ethernet port.examples/ShowInterfaces): displays interface details in a web page; a good companion to the address table here.overload/ mechanism used here enables MULTIHOME without editing system headers.The application includes a compile-time check to ensure multihome support is enabled. If MULTIHOME is not defined, compilation will fail with an informative error message directing you to enable the feature in the system configuration.