diff --git a/Sources/AsyncDNSResolver/AsyncDNSResolver.swift b/Sources/AsyncDNSResolver/AsyncDNSResolver.swift index 1a9451f..fb340e4 100644 --- a/Sources/AsyncDNSResolver/AsyncDNSResolver.swift +++ b/Sources/AsyncDNSResolver/AsyncDNSResolver.swift @@ -185,21 +185,39 @@ enum QueryType { // MARK: - Query reply types public enum IPAddress: Sendable, Equatable, CustomStringConvertible { - case IPv4(String) - case IPv6(String) + case ipv4(IPv4) + case ipv6(IPv6) public var description: String { switch self { - case .IPv4(let address): - return address - case .IPv6(let address): - return address + case .ipv4(let address): + return String(describing: address) + case .ipv6(let address): + return String(describing: address) + } + } + + public struct IPv4: Sendable, Hashable, CustomStringConvertible { + public var address: String + public var description: String { self.address } + + public init(address: String) { + self.address = address + } + } + + public struct IPv6: Sendable, Hashable, CustomStringConvertible { + public var address: String + public var description: String { self.address } + + public init(address: String) { + self.address = address } } } public struct ARecord: Sendable, Equatable, CustomStringConvertible { - public let address: IPAddress + public let address: IPAddress.IPv4 public let ttl: Int32? public var description: String { @@ -208,7 +226,7 @@ public struct ARecord: Sendable, Equatable, CustomStringConvertible { } public struct AAAARecord: Sendable, Equatable, CustomStringConvertible { - public let address: IPAddress + public let address: IPAddress.IPv6 public let ttl: Int32? public var description: String { diff --git a/Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift b/Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift index 0d217ad..c2fc3a4 100644 --- a/Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift +++ b/Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift @@ -579,32 +579,34 @@ private func toStringArray(_ arrayPointer: UnsafeMutablePointer [ARecord] { @@ -253,7 +253,7 @@ extension DNSSD { var parsedAddressBytes = [CChar](repeating: 0, count: Int(INET6_ADDRSTRLEN)) inet_ntop(AF_INET6, ptr, &parsedAddressBytes, socklen_t(INET6_ADDRSTRLEN)) let parsedAddress = String(cString: parsedAddressBytes) - return AAAARecord(address: .IPv6(parsedAddress), ttl: nil) + return AAAARecord(address: .init(address: parsedAddress), ttl: nil) } func generateReply(records: [AAAARecord]) throws -> [AAAARecord] { diff --git a/Tests/AsyncDNSResolverTests/dnssd/DNSSDDNSResolverTests.swift b/Tests/AsyncDNSResolverTests/dnssd/DNSSDDNSResolverTests.swift index acddf17..10aeb28 100644 --- a/Tests/AsyncDNSResolverTests/dnssd/DNSSDDNSResolverTests.swift +++ b/Tests/AsyncDNSResolverTests/dnssd/DNSSDDNSResolverTests.swift @@ -108,7 +108,7 @@ final class DNSSDDNSResolverTests: XCTestCase { let addrBytes: [UInt8] = [38, 32, 1, 73] try addrBytes.withUnsafeBufferPointer { let record = try DNSSD.AQueryReplyHandler.instance.parseRecord(data: $0.baseAddress, length: UInt16($0.count)) - XCTAssertEqual(record, ARecord(address: .IPv4("38.32.1.73"), ttl: nil)) + XCTAssertEqual(record, ARecord(address: .init(address: "38.32.1.73"), ttl: nil)) } }