@@ -79,13 +79,13 @@ private func getaddrinfo_numeric(_ string: String, family: Int32 = 0) -> NWEndpo
79
79
var result : NWEndpoint . Host ? = nil
80
80
81
81
if let sa = addrinfo. pointee. ai_addr {
82
- if ( sa. pointee. sa_family == AF_INET) {
82
+ if sa. pointee. sa_family == AF_INET {
83
83
sa. withMemoryRebound ( to: sockaddr_in. self, capacity: 1 , { ( sin) -> Void in
84
84
result = NWEndpoint . Host. ipv4 ( IPv4Address ( sin. pointee. sin_addr, interface) )
85
85
} )
86
- } else if ( sa. pointee. sa_family == AF_INET6) {
86
+ } else if sa. pointee. sa_family == AF_INET6 {
87
87
sa. withMemoryRebound ( to: sockaddr_in6. self, capacity: 1 , { ( sin6) -> Void in
88
- if ( sin6. pointee. sin6_scope_id != 0 ) {
88
+ if sin6. pointee. sin6_scope_id != 0 {
89
89
interface = NWInterface ( Int ( sin6. pointee. sin6_scope_id) )
90
90
}
91
91
let ipv6 = IPv6Address ( sin6. pointee. sin6_addr, interface) ;
@@ -107,7 +107,7 @@ private func getnameinfo_numeric(address: UnsafeRawPointer) -> String {
107
107
var result : String ? = nil
108
108
let maxLen = socklen_t ( 100 )
109
109
let storage = UnsafeMutablePointer< Int8> . allocate( capacity: Int ( maxLen) )
110
- if ( getnameinfo ( sa, socklen_t ( sa. pointee. sa_len) , storage, maxLen, nil , 0 , NI_NUMERICHOST) == 0 ) {
110
+ if getnameinfo ( sa, socklen_t ( sa. pointee. sa_len) , storage, maxLen, nil , 0 , NI_NUMERICHOST) == 0 {
111
111
result = String ( cString: storage)
112
112
}
113
113
storage. deallocate ( )
@@ -212,7 +212,7 @@ public struct IPv4Address: IPAddress, Hashable, CustomDebugStringConvertible {
212
212
/// - Parameter interface: An optional network interface to scope the address to. Defaults to nil.
213
213
/// - Returns: An IPv4Address or nil if the Data parameter did not contain an IPv4 address.
214
214
public init ? ( _ rawValue: Data , _ interface: NWInterface ? = nil ) {
215
- if ( rawValue. count != MemoryLayout< in_addr> . size) {
215
+ if rawValue. count != MemoryLayout< in_addr> . size {
216
216
return nil
217
217
}
218
218
let v4 = rawValue. withUnsafeBytes { ( ptr: UnsafePointer < in_addr > ) -> in_addr in
@@ -378,7 +378,7 @@ public struct IPv6Address: IPAddress, Hashable, CustomDebugStringConvertible {
378
378
/// - Parameter interface: An optional interface the address is scoped to. Defaults to nil.
379
379
/// - Returns: nil unless the raw data contained an IPv6 address
380
380
public init ? ( _ rawValue: Data , _ interface: NWInterface ? = nil ) {
381
- if ( rawValue. count != MemoryLayout< in6_addr> . size) {
381
+ if rawValue. count != MemoryLayout< in6_addr> . size {
382
382
return nil
383
383
}
384
384
let v6 = rawValue. withUnsafeBytes { ( ptr: UnsafePointer < in6_addr > ) -> in6_addr in
@@ -571,7 +571,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
571
571
var hints = addrinfo ( ai_flags: AI_DEFAULT, ai_family: AF_INET6, ai_socktype: SOCK_STREAM, ai_protocol: 0 ,
572
572
ai_addrlen: 0 , ai_canonname: nil , ai_addr: nil , ai_next: nil )
573
573
var resolved : UnsafeMutablePointer < addrinfo > ? = nil
574
- if ( getaddrinfo ( nil , service, & hints, & resolved) != 0 ) {
574
+ if getaddrinfo ( nil , service, & hints, & resolved) != 0 {
575
575
return nil
576
576
}
577
577
@@ -630,31 +630,30 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
630
630
if let nwinterface = nw_endpoint_copy_interface ( nw) {
631
631
interface = NWInterface ( nwinterface)
632
632
}
633
- if ( nw_endpoint_get_type ( nw) == Network . nw_endpoint_type_host)
634
- {
633
+ if nw_endpoint_get_type ( nw) == Network . nw_endpoint_type_host {
635
634
let host = NWEndpoint . Host. name ( String ( cString: nw_endpoint_get_hostname ( nw) ) , interface)
636
635
self = . hostPort( host: host, port: NWEndpoint . Port ( nw_endpoint_get_port ( nw) ) )
637
- } else if ( nw_endpoint_get_type ( nw) == Network . nw_endpoint_type_address) {
636
+ } else if nw_endpoint_get_type ( nw) == Network . nw_endpoint_type_address {
638
637
let port = NWEndpoint . Port ( nw_endpoint_get_port ( nw) )
639
638
let address = nw_endpoint_get_address ( nw)
640
- if ( address. pointee. sa_family == AF_INET && address. pointee. sa_len == MemoryLayout< sockaddr_in> . size) {
639
+ if address. pointee. sa_family == AF_INET && address. pointee. sa_len == MemoryLayout< sockaddr_in> . size {
641
640
let host = address. withMemoryRebound ( to: sockaddr_in. self, capacity: 1 ) {
642
641
( sin: UnsafePointer < sockaddr_in > ) -> NWEndpoint . Host in
643
642
return NWEndpoint . Host. ipv4 ( IPv4Address ( sin. pointee. sin_addr, interface) )
644
643
}
645
644
self = . hostPort( host: host, port: port)
646
- } else if ( address. pointee. sa_family == AF_INET6 &&
647
- address. pointee. sa_len == MemoryLayout< sockaddr_in6> . size) {
645
+ } else if address. pointee. sa_family == AF_INET6 &&
646
+ address. pointee. sa_len == MemoryLayout< sockaddr_in6> . size {
648
647
let host = address. withMemoryRebound ( to: sockaddr_in6. self, capacity: 1 ) {
649
648
( sin6) -> NWEndpoint . Host in
650
- if ( interface == nil && sin6. pointee. sin6_scope_id != 0 ) {
649
+ if interface == nil && sin6. pointee. sin6_scope_id != 0 {
651
650
interface = NWInterface ( Int ( sin6. pointee. sin6_scope_id) )
652
651
}
653
652
return NWEndpoint . Host. ipv6 ( IPv6Address ( sin6. pointee. sin6_addr,
654
653
interface) )
655
654
}
656
655
self = . hostPort( host: host, port: port)
657
- } else if ( address. pointee. sa_family == AF_UNIX) {
656
+ } else if address. pointee. sa_family == AF_UNIX {
658
657
// sockaddr_un is very difficult to deal with in swift. Fortunately, nw_endpoint_copy_address_string
659
658
// already does exactly what we need.
660
659
let path = nw_endpoint_copy_address_string ( nw)
@@ -663,7 +662,7 @@ public enum NWEndpoint: Hashable, CustomDebugStringConvertible {
663
662
} else {
664
663
return nil
665
664
}
666
- } else if ( nw_endpoint_get_type ( nw) == Network . nw_endpoint_type_bonjour_service) {
665
+ } else if nw_endpoint_get_type ( nw) == Network . nw_endpoint_type_bonjour_service {
667
666
self = . service( name: String ( cString: nw_endpoint_get_bonjour_service_name ( nw) ) ,
668
667
type: String ( cString: nw_endpoint_get_bonjour_service_type ( nw) ) ,
669
668
domain: String ( cString: nw_endpoint_get_bonjour_service_domain ( nw) ) ,
0 commit comments