Repository navigation
Description
摘要(中文)
结论. 在装有 WSL 的 Windows 机器上,「连接移动设备」对话框给出的配对链接(同一个地址也编码在二维码里)取的是 preferredLanAddress() 返回的第一个私有 IPv4,本例中是 vEthernet (WSL) 的 192.168.208.1,而不是真正承载默认路由的物理网卡地址。该地址只在主机内部(WSL 的 NAT 交换机)可达,手机无法连接,扫码配对直接失败。
复现.
- 在装有 WSL 的 Windows 上启动 DSH Desktop 0.10.0(harness 0.1.7-rc.2)。
- 打开「连接移动设备 / Connect a mobile device」,保持 WiFi Connection Mode。
- 对话框中的链接形如
http://192.168.208.1:43127/pair?token=…;此时Get-NetIPAddress显示192.168.208.1(vEthernet (WSL))排在真正的局域网地址(Ethernet,192.168.1.x)之前,而 Wi‑Fi 等其余网卡处于 APIPA(169.254.x)。 - 用同一局域网内的手机打开该链接或扫描二维码:无法连接(超时)。把主机名换成真实局域网地址后同一台手机可以配对。
原因(resources\app.asar,主进程).
- 端口:
port: developmentBuild ? 43128 : 43127(正式版 43127,开发版 43128;harness 端口是另一个,43129,代码里有注释说明二者独立),监听this.server?.listen(this.options.port ?? 0, "0.0.0.0", resolve2)。 - 链接:
snapshot()中http://${address}:${this.port}/pair?token=${this.pairingToken},其中address = preferredLanAddress();隧道模式下才改用${tunnelInstance.url}/pair?token=…。 preferredLanAddress()只取os.networkInterfaces()里第一个「非内部且私有」的 IPv4,既没有按默认路由/接口 metric 排序,也没有排除虚拟适配器。- 实测(本机):
require("os").networkInterfaces()的枚举顺序是vEthernet (WSL) 192.168.208.1→Ethernet 192.168.1.x→Loopback Pseudo-Interface 1 127.0.0.1(internal),所以preferredLanAddress()检查的第一个候选就是 WSL 地址:根因由代码与枚举顺序直接对上。
请求(厂商).
- 按默认路由(或路由 metric)选择接口,而不是
os.networkInterfaces()的第一个条目。 - 跳过虚拟/虚拟化/VPN 适配器(WSL
vEthernet、Hyper‑V、VMware、Wintun/OpenVPN、Tailscale 等);至少在存在真实可路由私有地址时不要使用它们。 - 在对话框中允许选择地址(列出全部候选 IPv4 与适配器名),或在所选地址不可达时自动回退到隧道模式。
- 可选:把接口名标注在链接旁边,用户一眼就能发现选错了网卡。
环境. DSH Desktop 0.10.0(harness 0.1.7-rc.2),Windows 10 Enterprise LTSC(build 19044),per-user 安装;resources\app.asar 6 550 424 B,sha256 2B67920B29C5BEC23CC23CC3F4B1F06875D5EF850A594173FD7B3E16AED50EEF。
EN report
1. Essence
On a Windows machine with WSL installed, the "Connect a mobile device" dialog hands out a pairing URL whose host is taken from preferredLanAddress() — the first private IPv4 returned by os.networkInterfaces(). On our machine that is the WSL virtual switch address (vEthernet (WSL), 192.168.208.1), not the physical adapter that actually carries the default route (Ethernet, 192.168.1.x). The WSL address is reachable only from the host itself, so a phone on the same LAN cannot open the page and pairing fails outright. The address is also what the QR code encodes.
2. How to reproduce
- On Windows with WSL present, start DSH Desktop 0.10.0 (harness 0.1.7-rc.2).
- Open Connect a mobile device and stay in WiFi Connection Mode.
- The link under the QR code reads
http://192.168.208.1:43127/pair?token=….Get-NetIPAddress -AddressFamily IPv4on the same machine shows192.168.208.1(vEthernet (WSL)) ordered before the real LAN address (Ethernet,192.168.1.x); the remaining adapters (Wi‑Fi and others) are APIPA169.254.x. - From a phone on the same LAN, open that link or scan the QR code: the request times out and pairing never starts. Substituting the real LAN address in the same URL pairs the phone immediately.
3. Root cause (shipped code)
Inside resources\app.asar (main process):
function preferredLanAddress() {
for (const entries of Object.values(networkInterfaces())) {
for (const entry of entries ?? []) {
if (entry.family === "IPv4" && !entry.internal && isPrivateAddress(entry.address)) return entry.address;
}
}
return void 0;
}- The first private, non-internal IPv4 wins; there is no ranking by default route or interface metric, and no exclusion of virtual/hypervisor/VPN adapters (
vEthernet (WSL), Hyper‑V, VMware, Wintun/OpenVPN, Tailscale …). - Measured on this machine, one command:
require("os").networkInterfaces()enumeratesvEthernet (WSL) 192.168.208.1first, thenEthernet 192.168.1.x, thenLoopback Pseudo-Interface 1 127.0.0.1(internal: true). The first candidatepreferredLanAddress()inspects is therefore the WSL address, which closes the loop between the code above and the observed pairing URL. - The pairing URL is built in
snapshot():
const address = preferredLanAddress();
const pairingUrl = !tokenValid ? void 0
: this.tunnelActive && this.tunnelInstance?.url
? `${this.tunnelInstance.url}/pair?token=${this.pairingToken}`
: address ? `http://${address}:${this.port}/pair?token=${this.pairingToken}` : void 0;- The bridge port is
port: developmentBuild ? 43128 : 43127(production 43127 / development 43128; the harness port is a separate constant, 43129 — the shipped code carries an explicit comment that the two ranges are independent; verbatim:// Keep the Harness origin stable across launches. These ports are separate/// from the production/development mobile bridge ports (43127/43128).). - The server listens on every interface:
this.server?.listen(this.options.port ?? 0, "0.0.0.0", resolve2), so only the displayed host is wrong — the listener itself is fine. - Tunnel mode is the only path that avoids the issue today:
${tunnelInstance.url}/pair?token=…, with Pinggy or a Cloudflare quick tunnel (forceCloudflareFailure: process.env.DSH_TUNNEL_FORCE_PINGGY === "1"). - Byte offsets inside
app.asarfor verification (the two snippets above are re-wrapped for readability; the shipped file has each on a single line):preferredLanAddressdefinition @5 662 831, pairing URL (pair?token=) @5 617 620,"0.0.0.0"inlisten(...)@5 612 003, port mapping line @6 450 072 (its43127literal @6 450 099), port comment @6 448 484.
4. Impact
On any developer machine that has WSL (or a similar virtual adapter) installed, the WiFi pairing flow is broken out of the box: the QR code and the printed link both point at an address that no other device can reach. The dialog gives no hint about which interface was chosen, and the only in-dialog escape is switching to tunnel mode (or the "try another link" fallback).
5. Workarounds for users (current build)
- Replace the host by hand, keeping the token from the same dialog:
http://<real-LAN-IP>:43127/pair?token=…(the listener already accepts it, since it binds0.0.0.0). - Switch to Internet Connection Mode, or press 「扫码打不开?换一条线路 / Can't open? Try another link」 — the URL then goes through a tunnel and the LAN address stops mattering.
- Temporarily disable the
vEthernet (WSL)adapter (or runwsl --shutdown) so a physical adapter is enumerated first. - Enable the durable pairing password (长效密码 / "Remember a durable pairing password") if the token rotation (
QR refreshes in N s) gets in the way.
6. Requests to the vendor
- Choose the interface that carries the default route (or the lowest-metric one) instead of the first entry of
os.networkInterfaces(). - Skip virtual, hypervisor and VPN adapters (
vEthernet (WSL), Hyper‑V, VMware, Wintun/OpenVPN, Tailscale …) whenever a physical adapter has a routable private IPv4. - Let the user pick the address in the dialog (list every candidate IPv4 with its adapter name), or fall back to tunnel mode automatically when the chosen address has no route to other devices.
- Optional: show the adapter name next to the URL so a wrong pick is visible at a glance.
7. Environment
| item | value |
|---|---|
| DSH Desktop | 0.10.0 (installed, per-user) |
| Harness | 0.1.7-rc.2 |
| OS | Windows 10 Enterprise LTSC, build 19044, x64 |
resources\app.asar |
6 550 424 B, sha256 2B67920B29C5BEC23CC23CC3F4B1F06875D5EF850A594173FD7B3E16AED50EEF |
| Observed | pairing URL http://192.168.208.1:43127/pair?token=…, QR countdown 244 s, mode WiFi Connection Mode |
Adapter order (Get-NetIPAddress) |
192.168.208.1 vEthernet (WSL) → 192.168.1.x Ethernet → 169.254.x (Wi‑Fi and three other adapters, APIPA) |
Notes: the pairing token is one-shot and rotates with the QR countdown, so it is not reproduced here. No personal paths, host names or user names are included in this report.
Activity
freetrip1 commentedon Oct 11, 2026
认领这个 issue,准备提 PR。
报告里有个关键细节:WSL 地址
192.168.208.1与真实网卡192.168.1.x同属 192.168 段,所以按网段排优先级修不了,只能按适配器名区分。方案:preferredLanAddress()先选非虚拟适配器的私网 IPv4;按名称降级 Hyper‑V 虚拟交换机(vEthernet (WSL)/vEthernet (Default Switch)等)、VMware、VirtualBox、Docker / Linux 网桥(docker0、br-*、virbr*)、VPN 隧道(utun*、tun*、WireGuard、Tailscale、ZeroTier 等);同级保持原枚举顺序;preferredLanAddress()在snapshot()里同步调用,读路由表要按平台起子进程,代价和改动面都偏大;对话框里列出全部候选地址(建议 3/4)可以作为后续单独的 UI 改动。会用报告里的真实枚举顺序(
vEthernet (WSL)→Ethernet→Loopback)写回归测试,另覆盖中文系统网卡名(以太网 / WLAN)、macOS / Linux 虚拟接口和回退路径。