Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jmdns registers on IPv4 interface, but broadcasts IPv6

So I am trying to use jmdns on Android 3.2.1 (HTC Flyer) and I am using jmdns for service discovery. Everything works nicely except that one of my three devices (rest of them work fine) is broadcasting IPv6 address instead of IPv4. This is very weird as they are all connected to my home network over DHCP so they are all assigned IPv4 address.

So on my device I run

    android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) getSystemService(android.content.Context.WIFI_SERVICE);
    multicastLock = wifi.createMulticastLock("mylockthereturn");
    multicastLock.setReferenceCounted(true);
    multicastLock.acquire();
    try {
        jmdns = JmDNS.create();

        jmdns.registerServiceType(jmdnsType);
        String jmdnsName = /* Read from db */;
        serviceInfo = ServiceInfo.create(jmdnsType, huggler_id, server.getLocalPort(), " blah blah");

        jmdns.registerService(serviceInfo);
        Log.d(TAG, "JMDNS service registered on ip " + jmdns.getInterface());
    } catch (IOException e) {
        Log.e(TAG, "Error creating JMDNS service (" + e.getMessage() + ")");
        e.printStackTrace();
    }

And it prints out nice IPv4 IP which actually matches the one assigned by my network (success).

But when I run code which discovers services on other devices.

for(ServiceInfo si : jmdns.list(jmdnsType, 6000)) { // timeout: 6s
        if (si.getName().equals(jmdnsNAme))
            continue;
        try {
            Log.d(TAG, "Host has " + si.getInet4Addresses().length + "  v4 addresses. ");
            Log.d(TAG, "Host has " + si.getInet6Addresses().length + " v6 addresses. ");


}

And when it discovers Flyer it shows exactly one v6 address.

Can anybody suggest what might have happened?

I am using Jmdns 3.4.0 (3.4.1 does not work at all!) and I am kind of a zeroconf newbie.

UPDATE:

Some new information:

    D/Huggler ( 5691): Host has 0 v4 addresses. 
    D/Huggler ( 5691): Host has 1 v6 addresses. 
    D/Huggler ( 5691): Host IPv6 address is fe80::66a7:69ff:feeb:9083
    D/Huggler ( 5691): Host IPv6 hostname is fe80::66a7:69ff:feeb:9083
    D/Huggler ( 5691): Host is linklocal true

Can anybody help interpret those?

like image 719
siemanko Avatar asked Jan 08 '13 17:01

siemanko


1 Answers

Was seeing the same problem, but passing in the InetAddress in the call to jmDNS.create seemed to do the trick.

So try something like:

WifiManager wifi =   (WifiManager)getActivity().getSystemService(android.content.Context.WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wifi.getConnectionInfo().getIpAddress());
jmdns = JmDNS.create(InetAddress.getByName(ip));
like image 77
taf Avatar answered Sep 25 '22 19:09

taf