|
22 | 22 | * |
23 | 23 | * <p>Uses JNA to call {@code DNSServiceRegister} / {@code DNSServiceRefDeallocate}. |
24 | 24 | * |
25 | | - * <p>Pass an {@link InetAddress} to scope registration to one LAN interface/host; the no-arg |
26 | | - * constructor registers on all interfaces ({@code interfaceIndex = 0}) with the system default |
27 | | - * hostname ({@code host = null}). |
| 25 | + * <p>Pass an {@link InetAddress} to scope registration to one LAN <em>interface</em>; SRV host |
| 26 | + * stays {@code null} so mDNSResponder advertises the system hostname (with A/AAAA). Passing a raw |
| 27 | + * IP as DNS-SD {@code host} breaks pairing — the daemon does not synthesize an A record for that |
| 28 | + * name. The no-arg constructor registers on all interfaces ({@code interfaceIndex = 0}). |
28 | 29 | * |
29 | 30 | * @author Karel Goderis |
30 | 31 | */ |
@@ -62,21 +63,25 @@ public DnssdHomekitAdvertiser() { |
62 | 63 | } |
63 | 64 |
|
64 | 65 | /** |
65 | | - * Scope registration to {@code localAddress}: SRV host is that address's host string, and the |
66 | | - * DNS-SD interface index is taken from the matching {@link NetworkInterface} when available. |
| 66 | + * Scope registration to the network interface that owns {@code localAddress}. SRV {@code host} is |
| 67 | + * left {@code null} (system default hostname + A/AAAA via mDNSResponder). |
| 68 | + * |
| 69 | + * <p>Do not pass {@code localAddress.getHostAddress()} as DNS-SD host: a literal IP becomes an |
| 70 | + * SRV target name with no A record, and Home pairing hangs after accepting the QR code. |
67 | 71 | * |
68 | 72 | * @param localAddress LAN address the HAP TCP listener uses |
69 | 73 | */ |
70 | 74 | public DnssdHomekitAdvertiser(InetAddress localAddress) { |
71 | | - this(resolveInterfaceIndex(localAddress), resolveHost(localAddress)); |
| 75 | + this(resolveInterfaceIndex(localAddress), null); |
72 | 76 | } |
73 | 77 |
|
74 | 78 | /** |
75 | 79 | * Full control over DNS-SD {@code interfaceIndex} and {@code host}. |
76 | 80 | * |
77 | 81 | * @param interfaceIndex {@link #INTERFACE_INDEX_ANY} (0) for all interfaces, or a platform |
78 | 82 | * interface index from {@link NetworkInterface#getIndex()} |
79 | | - * @param host SRV target host (IP or DNS name), or {@code null} for the system default hostname |
| 83 | + * @param host SRV target <strong>DNS hostname</strong>, or {@code null} for the system default. |
| 84 | + * Must not be a raw IP literal — DNS-SD will not register an A/AAAA for it. |
80 | 85 | */ |
81 | 86 | public DnssdHomekitAdvertiser(int interfaceIndex, String host) { |
82 | 87 | if (!SUPPORTED) { |
@@ -125,11 +130,6 @@ private static boolean detectSupport() { |
125 | 130 | } |
126 | 131 | } |
127 | 132 |
|
128 | | - private static String resolveHost(InetAddress localAddress) { |
129 | | - Objects.requireNonNull(localAddress, "localAddress"); |
130 | | - return localAddress.getHostAddress(); |
131 | | - } |
132 | | - |
133 | 133 | private static int resolveInterfaceIndex(InetAddress localAddress) { |
134 | 134 | Objects.requireNonNull(localAddress, "localAddress"); |
135 | 135 | try { |
|
0 commit comments