Re: PeerToPeer Replications using bonjour not working with IPV6 addresses
Re: PeerToPeer Replications using bonjour not working with IPV6 addresses
- Subject: Re: PeerToPeer Replications using bonjour not working with IPV6 addresses
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Fri, 17 Oct 2014 16:36:23 +0100
On 17 Oct 2014, at 16:28, Jens Alfke <email@hidden> wrote:
> (What is the valid syntax for using a raw IPv6 address as the hostname in a URL?)
The IPv6 address goes in square brackets.
<http://www.ietf.org/rfc/rfc 2732.txt>
> Is that always going to work?
/Always/ is a strong term, but it'll work in most cases and generally work better than trying to deal with addresses.
> I haven't used the NSNetService.hostName property before — does every device running mDNS have a host name?
Yes.
Consider the two steps of a Bonjour client. First, a browse operation returns all the PTR records that represents services of the specified type. Remember that a PTR record points to another record, in this case to the SRV records for the service.
Here's an example of this, first with dns-sd's high-level syntax and then using its raw query syntax:
$ dns-sd -B _ssh._tcp
Browsing for _ssh._tcp
Timestamp A/R Flags if Domain Service Type Instance Name
11:42:40.431 Add 2 5 local. _ssh._tcp. Fluffy
^C
$ dns-sd -Q _ssh._tcp.local. PTR
Timestamp A/R Flags if Name T C Rdata
11:45:12.645 Add 2 5 _ssh._tcp.local. 12 1 Fluffy._ssh._tcp.local.
^C
Next, a resolve operation looks up one of the SRV records, which contains the name of the A record. Here's another example, again uses both dns-sd syntaxes:
$ dns-sd -L Fluffy _ssh._tcp local
Lookup Fluffy._ssh._tcp.local
11:43:15.832 Fluffy._ssh._tcp.local. can be reached at Fluffy.local.:22 (interface 5)
^C
$ dns-sd -Q Fluffy._ssh._tcp.local. SRV
Timestamp A/R Flags if Name T C Rdata
11:46:49.984 Add 2 5 Fluffy._ssh._tcp.local. 33 1 0 0 22 Fluffy.local.
^C
Finally, the second part of the resolve operation is to convert the A record to an IP address. This can only be done as a raw query.
$ dns-sd -Q fluffy.local. A
Timestamp A/R Flags if Name T C Rdata
11:43:31.464 Add 2 5 Fluffy.local. 1 1 217.41.101.22
^C
Note: This example only describes A records but the same process works for AAAA record.s
So, all resolves necessarily go through an A / AAAA record, and thus you are guaranteed a valid host name.
> Also, the docs say that the hostName property isn't populated until the service is resolved. At which time the actual IP addresses are also available, so why not just use those?
Because looking at the addresses array gets you involved in the process of choosing which is the correct address to connect to. That's hard, and can only be done properly at the time of the actual connection. For a glimpse of what's involved, check out the post referenced below.
<http://lists.apple.com/archives/ipv6-dev/2011/Jul/msg00009.html>
> The connect-time code here is the Couchbase Lite library, which the developer doesn't control. I do control it :) but my code just passes the URL to NSURLConnection and/or CFReadStreamCreateForHTTPRequest. Are those going to resolve this hostname properly?
Yes. And both these use the system's connect-by-name infrastructure, and thus will do a better job of address selection than you can do.
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