Posts

Post marked as solved
6 Replies
Hello @eskimo , Just to confirm again, is their support for "getaddrinfo" on all the iOS platforms as well ?
Post marked as solved
6 Replies
Thank you for the detailed feedback and guidance. I really appreciate you taking the time to provide such helpful information. The code you referenced in your previous email was very useful, and I've incorporated the suggestions you provided. Specifically, I've moved the top-level code into a function called performDNSLookup(), which is a more appropriate structure for Swift. I've also used DNSServiceSetDispatchQueue to schedule the DNSServiceRef on the main queue, and I'm using dispatchMain() to "park" the main thread and keep the callback active. Additionally, I've replaced the use of inet_ntop with getnameinfo and NI_NUMERIC{HOST,SERV}, as you recommended, to handle the sockaddr type more effectively in Swift. I've tested the updated code, and it's working as expected. Thank you again for your valuable guidance. Regards, Harshal
Post marked as solved
6 Replies
Thank you for the response. I was trying to write a poc and validate this with the following code: import Foundation import dnssd var vSDRef: DNSServiceRef? let callback: DNSServiceGetAddrInfoReply = { (sdef, flags, interface_idx, errorcode, hostname, resolvedAddresses, ttl, context) in NSLog("Callback called...") if errorcode == kDNSServiceErr_NoError { if let hostname = hostname, let address = resolvedAddresses { var add_string = [CChar](repeating: 0, count: Int(INET6_ADDRSTRLEN)) switch Int32(address.pointee.sa_family) { case AF_INET: var ipv4_addr = address.withMemoryRebound(to: sockaddr_in.self, capacity: 1) { $0.pointee } inet_ntop(AF_INET, &(ipv4_addr.sin_addr), &add_string, socklen_t(INET_ADDRSTRLEN)) case AF_INET6: var addr6 = address.withMemoryRebound(to: sockaddr_in6.self, capacity: 1) { $0.pointee } inet_ntop(AF_INET6, &(addr6.sin6_addr), &add_string, socklen_t(INET6_ADDRSTRLEN)) default: NSLog("Unknown address family") return } NSLog("Resolved \(String(cString: hostname)) to \(String(cString: add_string))") } else { NSLog("Error resolving DNS address: \(errorcode)") } } } let returned_error = DNSServiceGetAddrInfo(&vSDRef, DNSServiceFlags(kDNSServiceFlagsLongLivedQuery), 0, DNSServiceProtocol(kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6), "example.com", callback, nil) if returned_error == kDNSServiceErr_NoError { NSLog("DNS lookup started...") } else { NSLog("Error starting DNS resolution: \(returned_error)") } NSLog("Resolved if else") sleep (100)``` tcpdump showed that we are getting a response but the callback never gets triggered. Can you help me out here please. Thanks, Harshal.
Post not yet marked as solved
10 Replies
Hi everyone, I'm currently working on establishing connections using either IPv4 or IPv6 in my Swift application. However, I've hit a snag with NWProtocolIP.Options. It appears that I'm unable to create its instance to configure additional options. I would appreciate any tips or advice on how to achieve IPv4 or IPv6 connections exclusively. Here's a breakdown of what I'm aiming to accomplish in my app: Initialize the protocol options and offer choices for IP versions and various other transport layer options. Initialize the endpoint by passing the IP address struct and port number. Create the connection object using the endpoint and parameters. If IPv4 was selected as the option and the IP address struct contained an IPv6 address, I expect the NWConnection to fail, providing the corresponding error code. Any insights or guidance on resolving this issue would be highly appreciated. Thank you in advance for your help!