Skip to content
Merged
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fe043b9
Portmapping: add windowsAddress support
richfr Mar 30, 2026
04a4541
Portmapping: add windowsAddress support
richfr Mar 30, 2026
cf34fb8
Addressing PR feedback: update wslcsdk.cpp
richfr Apr 1, 2026
954d1a0
Addressing clang formatting error
richfr Apr 1, 2026
31e28b4
Providing default values for port bindings: wslcsdk.cpp
richfr Apr 1, 2026
7ca8e51
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 1, 2026
7f1eca4
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 1, 2026
eff50d2
Fixed merge conflicts. Set default BindingAddress to 127.0.0.1. Valid…
richfr Apr 7, 2026
41a39eb
Added new function InetNtopToHresult() to map inet result error value…
richfr Apr 7, 2026
895a604
return family name if socket address is invalid
richfr Apr 7, 2026
a788da8
Removed unnecessasry variable bindingAddressStrings. Also, commented …
richfr Apr 7, 2026
644ebab
Fixed clang formatting errors
richfr Apr 7, 2026
47c28f2
Added WSLC Sdk API tests for WslcContainerPortMapping.windowsAddress …
richfr Apr 7, 2026
9ed0f18
Add unique name to containerSettings var to make test debugging from …
richfr Apr 7, 2026
fb9c466
Adjust AF_UNIX portmapping test so that it fails if value accepted
richfr Apr 8, 2026
13ba738
Return more accurate strncpy_s error result
richfr Apr 8, 2026
e482e48
Improved error return value of IP address verification
richfr Apr 8, 2026
1e7656a
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 8, 2026
f4fd0ba
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 8, 2026
45b6841
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 8, 2026
75fa4ac
Provide better error reporting
richfr Apr 13, 2026
fdf802d
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 13, 2026
573786f
Respond to misc copilot feedback
richfr Apr 13, 2026
5a8a0ae
Merge branch 'richfr/portmapping' of https://github.com/microsoft/WSL…
richfr Apr 13, 2026
7f2e047
Resolving merge after syncing with origin
richfr Apr 13, 2026
6b5ffdd
Adjusted error messages
richfr Apr 13, 2026
dd50413
Removed 2 unnecessary lines of code
richfr Apr 13, 2026
86eb5b7
Mark internal function as static to avoid external linkage
richfr Apr 13, 2026
15c2e67
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 13, 2026
b9a3176
Merge branch 'feature/wsl-for-apps' into richfr/portmapping
1wizkid Apr 14, 2026
9618aad
Delete diagnostics/trace01.etl
1wizkid Apr 14, 2026
759f2f7
Delete diagnostics/trace02.etl
1wizkid Apr 14, 2026
3e6f691
Remove ETL files and Add Ignore rule to .gitignore
richfr Apr 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions src/windows/WslcSDK/wslcsdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,11 @@ try
}

std::unique_ptr<WSLCPortMapping[]> convertedPorts;
std::vector<std::string> bindingAddressStrings;
Comment thread
1wizkid marked this conversation as resolved.
Outdated
if (internalContainerSettings->ports && internalContainerSettings->portsCount)
{
convertedPorts = std::make_unique<WSLCPortMapping[]>(internalContainerSettings->portsCount);
bindingAddressStrings.resize(internalContainerSettings->portsCount);
Comment thread
1wizkid marked this conversation as resolved.
Outdated
for (uint32_t i = 0; i < internalContainerSettings->portsCount; ++i)
{
Comment thread
1wizkid marked this conversation as resolved.
const WslcContainerPortMapping& internalPort = internalContainerSettings->ports[i];
Expand All @@ -634,12 +636,48 @@ try
convertedPort.HostPort = internalPort.windowsPort;
convertedPort.ContainerPort = internalPort.containerPort;
Comment thread
1wizkid marked this conversation as resolved.

// TODO: Ipv6 & custom binding address support.
convertedPort.Family = AF_INET;

// TODO: Consider using standard protocol numbers instead of our own enum.
convertedPort.Protocol = internalPort.protocol == WSLC_PORT_PROTOCOL_TCP ? IPPROTO_TCP : IPPROTO_UDP;
Comment thread
1wizkid marked this conversation as resolved.
Outdated
convertedPort.BindingAddress = "127.0.0.1";

// Validate IP address if provided and if valid, copy to runtime structure.
if (internalPort.windowsAddress != nullptr)
{
char addrBuf[INET6_ADDRSTRLEN]{};
Comment thread
1wizkid marked this conversation as resolved.
Outdated
switch (internalPort.windowsAddress->ss_family)
{
case AF_INET:
{
const auto* addr4 = reinterpret_cast<const sockaddr_in*>(internalPort.windowsAddress);

THROW_HR_IF_NULL(E_UNEXPECTED, inet_ntop(AF_INET, &addr4->sin_addr, addrBuf, sizeof(addrBuf)));
Comment thread
1wizkid marked this conversation as resolved.
Outdated
Comment thread
1wizkid marked this conversation as resolved.
Outdated

convertedPort.Family = AF_INET;
break;
}

case AF_INET6:
{
const auto* addr6 = reinterpret_cast<const sockaddr_in6*>(internalPort.windowsAddress);

THROW_HR_IF_NULL(E_UNEXPECTED, inet_ntop(AF_INET6, &addr6->sin6_addr, addrBuf, sizeof(addrBuf)));
Comment thread
1wizkid marked this conversation as resolved.
Outdated

convertedPort.Family = AF_INET6;
break;
}

default:
// Reject unsupported or malformed address families
THROW_HR(E_INVALIDARG);
Comment thread
1wizkid marked this conversation as resolved.
Outdated
Comment thread
1wizkid marked this conversation as resolved.
Outdated
Comment thread
1wizkid marked this conversation as resolved.
Outdated
}
bindingAddressStrings[i] = addrBuf;
convertedPort.BindingAddress = bindingAddressStrings[i].c_str();
Comment thread
1wizkid marked this conversation as resolved.
Outdated
}
Comment thread
1wizkid marked this conversation as resolved.
else
{
// If no binding address is provided, default to wildcard.
convertedPort.Family = AF_UNSPEC;
Comment thread
1wizkid marked this conversation as resolved.
Outdated
convertedPort.BindingAddress = nullptr;
Comment thread
1wizkid marked this conversation as resolved.
Outdated
}
Comment thread
1wizkid marked this conversation as resolved.
}
containerOptions.Ports = convertedPorts.get();
containerOptions.PortsCount = static_cast<ULONG>(internalContainerSettings->portsCount);
Expand Down Expand Up @@ -772,7 +810,11 @@ try

for (uint32_t i = 0; i < portMappingCount; ++i)
{
RETURN_HR_IF(E_NOTIMPL, portMappings[i].windowsAddress != nullptr);
if (portMappings[i].windowsAddress != nullptr)
{
const auto family = portMappings[i].windowsAddress->ss_family;
RETURN_HR_IF(E_INVALIDARG, family != AF_INET && family != AF_INET6);
Comment thread
1wizkid marked this conversation as resolved.
Outdated
}
RETURN_HR_IF(E_NOTIMPL, portMappings[i].protocol != 0);
Comment thread
1wizkid marked this conversation as resolved.
}

Expand Down
Loading