getnameinfo

Swift getnameinfo unreliable results for IPv6

ε祈祈猫儿з 提交于 2019-12-11 03:26:03
问题 I have the following extension on sockaddr : extension sockaddr { /// Indicates if this is an IPv4 address. var isIPv4: Bool { return sa_family == UInt8(AF_INET) } /// Indicates if this is an IPv6 address. var isIPv6: Bool { return sa_family == UInt8(AF_INET6) } /// Returns the address in string notation. var address: String? { var result: String = "" var me = self var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST)) if getnameinfo(&me, socklen_t(me.sa_len), &hostname, socklen_t