Any proper way to get remote tcp port and ip address from a NEAppProxyTCPFlow

Hi there,

In order to get the remote tcp port from a NEAppProxyTCPFlow, what I did is:
Code Block
(NEAppProxyTCPFlow as! NWHostEndpoint).port

But I do not think that is a good way of achieving it.

Is there any proper way for it?

And I believe the ip address can be fetched by:
Code Block
NEAppProxyTCPFlow.remoteHostName

Is that right?

Thanks in advance for any suggestion.


One way to do this would be to create an extension for NWEndpoint and use the NEAppProxyTCPFlow's remoteEndpoint like so: flow.remoteEndpoint.nwEndpoint.

Code Block swift
extension NetworkExtension.NWEndpoint {
var nwEndpoint: Network.NWEndpoint {
if let endpoint = self as? NetworkExtension.NWHostEndpoint {
return Network.NWEndpoint.hostPort(host: NWEndpoint.Host(endpoint.hostname), port: NWEndpoint.Port(endpoint.port)!)
} else if let endpoint = self as? NetworkExtension.NWBonjourServiceEndpoint {
return Network.NWEndpoint.service(name: endpoint.name, type: endpoint.type, domain: endpoint.domain, interface: nil)
} else {
fatalError()
}
}
}



Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Any proper way to get remote tcp port and ip address from a NEAppProxyTCPFlow
 
 
Q