aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Library/NetSocket/NetSocket.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-11-08 12:33:00 -0800
committerDustin Mierau <dustin@mierau.me>2025-11-08 12:33:00 -0800
commit286c408370681b022deaabd254d499aefec28add (patch)
tree8dd76ca8e362513c34a444f921debcc28eab6a76 /Hotline/Library/NetSocket/NetSocket.swift
parent2f332ee497af925db1a2583135e9dfcdaff84794 (diff)
Some work on making it possible to connect to servers with an IPv6 address. Improve connect form a bit. Add Copy Link to context menu for servers and trackers.
Diffstat (limited to 'Hotline/Library/NetSocket/NetSocket.swift')
-rw-r--r--Hotline/Library/NetSocket/NetSocket.swift19
1 files changed, 18 insertions, 1 deletions
diff --git a/Hotline/Library/NetSocket/NetSocket.swift b/Hotline/Library/NetSocket/NetSocket.swift
index 5c7d185..e66ef3f 100644
--- a/Hotline/Library/NetSocket/NetSocket.swift
+++ b/Hotline/Library/NetSocket/NetSocket.swift
@@ -173,7 +173,24 @@ public actor NetSocket {
guard let nwPort = NWEndpoint.Port(rawValue: port) else {
throw NetSocketError.invalidPort
}
- return try await self.connect(host: .name(host, nil), port: nwPort, tls: tls, config: config)
+
+ // Parse the host string to create the appropriate NWEndpoint.Host
+ let nwHost: NWEndpoint.Host
+
+ // Try parsing as IPv6 without zone
+ if let ipv6Addr = IPv6Address(host) {
+ nwHost = .ipv6(ipv6Addr)
+ }
+ // Try parsing as IPv4
+ else if let ipv4Addr = IPv4Address(host) {
+ nwHost = .ipv4(ipv4Addr)
+ }
+ // Fall back to treating as hostname
+ else {
+ nwHost = .name(host, nil)
+ }
+
+ return try await self.connect(host: nwHost, port: nwPort, tls: tls, config: config)
}
// MARK: Close