Re: Can't get remote host and port after CFStreamCreatePairWithSocketToNetService
Re: Can't get remote host and port after CFStreamCreatePairWithSocketToNetService
- Subject: Re: Can't get remote host and port after CFStreamCreatePairWithSocketToNetService
- From: Jeff Johnson <email@hidden>
- Date: Mon, 13 Apr 2015 12:12:36 -0500
On Apr 13, 2015, at 11:29 AM, Jens Alfke <email@hidden> wrote:
>> On Apr 13, 2015, at 8:31 AM, Jeff Johnson <email@hidden> wrote:
>>
>> I try to get kCFStreamPropertySocketRemoteHostName and kCFStreamPropertySocketRemotePortNumber from both the read stream and the write stream, but again I always get NULL.
>
> Have you tried kCFStreamPropertySocketRemoteHost? (Although I haven’t found this property to work either in the related case of a stream opened from an _incoming_ TCP connection.)
Trying now, but I'm getting NULL for that property.
>> Isn't this supposed to work? Isn't the net service supposed to resolve when you open the streams?
>
> My guess is that the address is resolved but at a lower level in the stack, and the resolved address doesn’t get stored into the NetService object itself. Which would be a bug.
>
> Workarounds I can think of:
> (a) Use a lower-level (Unix) API to get the remote address from the underlying socket file descriptor. I don’t know these APIs well enough to tell you how to do it, other than to guess that getsockopt might be involved.
> (b) Instead of calling the convenience routine CFStreamCreatePairWithSocketToNetService, DIY by first resolving the NetService, getting the address, and then opening streams to it.
Unfortunately, the reason I'm using CFStreamCreatePairWithSocketToNetService in the first place is to avoid resolving the net service manually.
> (c) Do without the address. There shouldn’t be much need for it, except for debugging purposes.
I want the host and port is to send a "Host" header. I might be able to get away without it, but I'd prefer to adhere to standards.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden