Re: Questions about NSNetService
Re: Questions about NSNetService
- Subject: Re: Questions about NSNetService
- From: Rick Mann <email@hidden>
- Date: Wed, 24 Sep 2014 04:17:10 -0700
On Sep 24, 2014, at 02:42 , Quinn The Eskimo! <email@hidden> wrote:
>
> On 24 Sep 2014, at 10:34, Rick Mann <email@hidden> wrote:
>
>> But the list of addresses provided in the NSNetService.addresses is confusing:
>
> Did you check the address family? The most common cause of confusion on this front is a device that returns IPv4 and IPv6 addresses. If you try to interpret IPv6 addresses as IPv4, you tend to get gibberish (-:
Well, I didn't. I used this code:
NSLogDebug(@" Hostname: %@", inService.hostName);
NSLogDebug(@" Port: %ld", (long) inService.port);
NSLogDebug(@" %lu addresses", (unsigned long) inService.addresses.count);
for (NSData* addrData in inService.addresses)
{
const struct sockaddr_in* addr = addrData.bytes;
const char* ipCS = inet_ntoa(addr->sin_addr);
NSLogDebug(@"Address: %s:%d", ipCS, addr->sin_port);
}
For the output:
2014-09-24 02:26:56.408 Balloon[1999:1574050] <AppDelegate.m: 141>: Hostname: balloon.local.
2014-09-24 02:26:56.410 Balloon[1999:1574050] <AppDelegate.m: 142>: Port: 2002
2014-09-24 02:26:56.412 Balloon[1999:1574050] <AppDelegate.m: 143>: 2 addresses
2014-09-24 02:26:56.413 Balloon[1999:1574050] <AppDelegate.m: 149>: Address: 192.168.15.59, port 53767
2014-09-24 02:26:56.417 Balloon[1999:1574050] <AppDelegate.m: 149>: Address: 0.0.0.0, port 53767
The first address is correct, so its port must be correct, right? Oh! The endianness is wrong. Flipping the bytes results in port 2002, which it should be. Okay.
The other address might be IPv6. Here's where it gets puzzling, though:
$ ping balloon.local
PING balloon.local (10.77.80.1): 56 data bytes
That 10. address is the one on the device's ad-hoc wifi network. My Mac is connected to that wifi network, and to the wired network 192. Why does the ping find the device on 10., but the addresses that come up in NSNetService are 192., and a corrupt IPv6 address, or a bad address?
And finally, when I call -getInputStream:outputStream:, what address is it using to connect?
--
Rick Mann
email@hidden
_______________________________________________
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