1

How can I make an Android network request lookup a local domain name registered with Bonjour?

I get this error when trying to fetch data using Volley.

java.net.UnknownHostException: Unable to resolve host "xxxxx.local": No address associated with hostname
Johan Nordberg
  • 3,621
  • 4
  • 33
  • 58
  • Basically "Unable to resolve host" means DNS lookup has failed. Can you access xxxxx.local in a browser (or ping in a shell)? – Toris Dec 15 '17 at 16:01
  • On iOS, macOS and windows I can. On Android I cannot. – Johan Nordberg Dec 15 '17 at 16:04
  • Maybe related: https://android.stackexchange.com/questions/49188/how-to-get-mdns-working-for-chrome-on-android https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/NetServices/Articles/faq.html and https://stackoverflow.com/questions/10588074/how-can-i-query-local-bonjour-dns-entries – Toris Dec 15 '17 at 16:10
  • Haven't tried yet but DNS-SD seems to be a key word to resolve it, as Bonjour uses mDNS. https://developer.android.com/training/connect-devices-wirelessly/nsd.html – Toris Dec 15 '17 at 16:16

2 Answers2

0

If you control the whole network stack, you can perform DNS service discovery (DNS-SD) through Android's NsdManager. I recommend this guide from the documentation:

https://developer.android.com/training/connect-devices-wirelessly/nsd

In short, it boils down to:

mNsdManager.discoverServices(
    SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);

You can cross-reference the service you wish to resolve to by inspecting the response from dns-sd on Mac:

$ dns-sd -Z . .
_http._tcp                                      PTR     myserver._http._tcp
myserver._http._tcp                             SRV     0 0 80 myserver.local. ; Replace with unicast FQDN of target host
myserver._http._tcp                             TXT     ""

In the NsdManager.DiscoveryListener callback, you can obtain the corresponding IP address from NsdServiceInfo.getHost().

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
-1

Have you tried with the IP of localhost ? 127.0.0.1 or 10.0.2.2:80 ?

sleakerz
  • 169
  • 19