Skip to content

Crashing with IPv6 connections #20

@dkulp

Description

@dkulp

I'm working on supporting some of the wled API on a more "full featured" device. One part of that is that the device supports IPv6. When WLED-native detects this service, there are a few issues:

  1. The IPv6 address is too long to display in the list of devices. The list cannot be made wide enough to display it.

  2. When clicking on the device, wled-native crashes

I actually think the best fix would be to limit the connection to ipv4. This allows

diff --git a/wled-native/Service/DiscoveryService.swift b/wled-native/Service/DiscoveryService.swift
index 904d783..dc2cf36 100644
--- a/wled-native/Service/DiscoveryService.swift
+++ b/wled-native/Service/DiscoveryService.swift
@@ -41,7 +41,10 @@ class DiscoveryService: NSObject, Identifiable {
                     print("NW Browser: Added")
                     if case .service(let name, _, _, _) = added.endpoint {
                         print("Connecting to \(name)")
-                        let connection = NWConnection(to: added.endpoint, using: .tcp)
+                        let params = NWParameters.tcp
+                        let ip = params.defaultProtocolStack.internetProtocol! as! NWProtocolIP.Options
+                        ip.version = .v4
+                        let connection = NWConnection(to: added.endpoint, using: params)
                         connection.stateUpdateHandler = { state in

Note: the _wled._tcp service is only registered with mdns on ipv4 and a " avahi-browse -a | grep wled" from a linux box confirms that. Ideally, wled-native would check the registration and force ipv4 appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions