c2w-net: add dynamic port forwarding for WebSocket mode
Summary
Enables port forwarding (-p flag) in --listen-ws mode by dynamically querying DHCP leases to discover the actual container IP address, removing the need for hardcoded values or static MAC-to-IP mappings.
Changes
- Query gvisor-tap-vsock's internal
/services/dhcp/leasesendpoint to discover container IP - Poll every 200ms for up to 10 seconds to detect when container receives DHCP lease
- Automatically start port forwarders once container IP is discovered
- Remove all IP address guessing and hardcoded attempts
Motivation
This change enables browser-hosted Wasm containers to accept incoming connections on forwarded ports. Use cases include:
- Running web servers inside containers accessible from the host
- Port-based service discovery and access
- Multi-container networking scenarios
Technical Details
The implementation:
- Container connects via WebSocket
- c2w-net polls DHCP lease table to capture assigned IP
- Port forwarders start with discovered IP as target
- Falls back to default IP (192.168.127.3) after 10-second timeout
Testing
Existing integration tests continue to pass as changes only affect --listen-ws mode code path. The -p flag now works correctly with WebSocket mode.
tested on macos, android, ios.\
macos: works
android: looks like it works using screen logs, but dont have time rn to do a delegate
windows: no machine to test
ios: browser crashed
Please add the signed-off-by line with your name: https://github.com/container2wasm/container2wasm/blob/255b65008ab07b7981c5462046c30d7b891f1adc/CONTRIBUTING.md#sign-your-patch