Re: Questions about NSNetService
Re: Questions about NSNetService
- Subject: Re: Questions about NSNetService
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Wed, 24 Sep 2014 12:33:41 +0100
On 24 Sep 2014, at 12:17, Rick Mann <email@hidden> wrote:
> Well, I didn't. I used this code:
>
> const char* ipCS = inet_ntoa(addr->sin_addr);
Oh boy, BSD's broken name translation APIs strike again. In my experience there are only two BSD name translation APIs that are fit for purpose, <x-man-page://3/getaddrinfo> and <x-man-page://3/getnameinfo>, and even those should only be used for IP numbers (via the AI_NUMERICHOST and NI_NUMERICHOST flags). Everything else is just fundamentally broken.
Oh, and just for the record, here's my Rules of DNS:
1. If you're connecting to a name, use a connect-by-name API. The post I reference below explains why that's important.
2. If you're connecting to a name at a layer that doesn't support a connect-by-name API (like BSD), you have two options:
o use a socket stream (NSStream or CFStream) to do the connect-by-name and then extract the connected socket from the stream
o use getaddrinfo and then write a lot of extra code to connect to each service in order until you find one that works (and you still won't be as good as the system's connect-by-name infrastructure)-:
3. If you're doing name-to-address (without connecting) or address-to-name translation, use CFHost.
4. If you're working with IPv{4,6} addresses, getaddrinfo and getnameinfo are fine, as long as you use them in numeric mode.
5. For anything else, use DNSServiceQueryRecord.
> The first address is correct, so its port must be correct, right?
I'm not really up for re-interpreting a sockaddr_in6 as a sockaddr_in today. I recommend you change your code to call getnameinfo. The SimplePing sample code shows how.
<https://developer.apple.com/library/mac/#samplecode/SimplePing/>
Once you've got accurate info please repost and we can take a look.
> And finally, when I call -getInputStream:outputStream:, what address is it using to connect?
That is a simple answer with a complex question. See the following.
<http://lists.apple.com/archives/ipv6-dev/2011/Jul/msg00009.html>
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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