| 1 | # ContainerPortMapping |
| 2 | |
| 3 | Maps a Windows host port to a container port. |
| 4 | |
| 5 | **Constructors / properties** |
| 6 | |
| 7 | - `ContainerPortMapping(uint16_t windowsPort, uint16_t containerPort, PortProtocol protocol)` |
| 8 | - `WindowsPort()` / setter |
| 9 | - `ContainerPort()` / setter |
| 10 | - `Protocol()` / setter |
| 11 | - `WindowsAddress()` / setter |
| 12 | |
| 13 | **Important notes** |
| 14 | |
| 15 | - `WindowsAddress` is implemented. |
| 16 | - The setter accepts only `Windows::Networking::HostName` values whose type is `Ipv4` or `Ipv6`. |
| 17 | - `ToStruct()` uses `inet_pton` and stores a real `sockaddr_in` / `sockaddr_in6`. |
| 18 | |
| 19 | ```cpp |
| 20 | using namespace winrt::Windows::Networking; |
| 21 | |
| 22 | ContainerPortMapping mapping{ 8080, 80, PortProtocol::TCP }; |
| 23 | mapping.WindowsAddress(HostName{ L"127.0.0.1" }); |
| 24 | |
| 25 | auto hostPort = mapping.WindowsPort(); |
| 26 | auto guestPort = mapping.ContainerPort(); |
| 27 | auto protocol = mapping.Protocol(); |
| 28 | auto bindAddress = mapping.WindowsAddress(); |
| 29 | ``` |