Skip to content

Commit b633eb9

Browse files
committed
Improve server port binding for remote
1 parent 11b4dd2 commit b633eb9

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Add `/remote` command to display connection URL, password and setup guide. Password is no longer shown in logs or welcome message.
6+
- Improve server port binding for remote.
67

78
## 0.116.4
89

src/eca/remote/server.clj

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,37 @@
2525
"Number of sequential ports to try before giving up."
2626
20)
2727

28+
(def ^:private virtual-interface-re
29+
"Matches network interface names that are typically virtual/software-defined.
30+
These are deprioritized when detecting the LAN IP."
31+
#"^(docker|br-|veth|vbox|virbr|tailscale|lo|tun|tap|wg|zt)")
32+
33+
(defn ^:private interface-priority
34+
"Returns a sort priority for a network interface (lower = preferred).
35+
Real hardware interfaces (wifi, ethernet) are preferred over virtual ones."
36+
^long [^NetworkInterface ni]
37+
(let [name (.getName ni)]
38+
(if (re-find virtual-interface-re name) 1 0)))
39+
2840
(defn ^:private detect-lan-ip
2941
"Enumerates network interfaces to find a site-local (private) IPv4 address.
42+
Prefers real hardware interfaces (wifi, ethernet) over virtual ones (docker, vbox).
3043
Returns the IP string or nil when none is found."
3144
[]
3245
(try
3346
(->> (enumeration-seq (NetworkInterface/getNetworkInterfaces))
3447
(filter (fn [^NetworkInterface ni]
3548
(and (.isUp ni)
36-
(not (.isLoopback ni)))))
49+
(not (.isLoopback ni))
50+
(not (.isVirtual ni)))))
51+
(sort-by interface-priority)
3752
(mapcat (fn [^NetworkInterface ni]
38-
(enumeration-seq (.getInetAddresses ni))))
39-
(filter (fn [^InetAddress addr]
40-
(and (instance? Inet4Address addr)
41-
(.isSiteLocalAddress addr))))
42-
(some (fn [^InetAddress addr] (.getHostAddress addr))))
53+
(->> (enumeration-seq (.getInetAddresses ni))
54+
(filter (fn [^InetAddress addr]
55+
(and (instance? Inet4Address addr)
56+
(.isSiteLocalAddress addr))))
57+
(map (fn [^InetAddress addr] (.getHostAddress addr))))))
58+
first)
4359
(catch Exception _ nil)))
4460

4561
(defn ^:private detect-host

0 commit comments

Comments
 (0)