Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

sipdroid is selecting wrong network interface #7

Open
jsalatas opened this issue Jun 29, 2014 · 0 comments
Open

sipdroid is selecting wrong network interface #7

jsalatas opened this issue Jun 29, 2014 · 0 comments

Comments

@jsalatas
Copy link

I am testing BBB-Android in an ASUS TF701T device and the sipdroid while trying to connect to the FreeSwitch server uses the wrong network interface.

The available interfaces are as follows:

# adb shell
shell@K00C:/ $ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN
    link/ether 82:30:bc:2a:2b:4e brd ff:ff:ff:ff:ff:ff
3: sit0: <NOARP> mtu 1480 qdisc noop state DOWN
    link/sit 0.0.0.0 brd 0.0.0.0
4: ip6tnl0: <NOARP> mtu 1452 qdisc noop state DOWN
    link/tunnel6 :: brd ::
5: rmnetctl: <NOARP> mtu 1500 qdisc noop state DOWN
    link/ipip 0.0.0.0 brd 0.0.0.0
6: p2p0: <NO-CARRIER,BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state DORMANT qlen 1000
    link/ether da:50:e6:1b:0f:e3 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::d850:e6ff:fe1b:fe3/64 scope link
       valid_lft forever preferred_lft forever
7: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether d8:50:e6:1b:0f:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.100/24 brd 192.168.0.255 scope global wlan0
    inet6 fe80::da50:e6ff:fe1b:fe3/64 scope link
       valid_lft forever preferred_lft forever
shell@K00C:/ $ #

In org.zoolu.net.IpAddress in method setLocalIpAddress it ends up using the p2p0 interface instead of wlan0 and eventually the application crashes as it cannot parse correctly the port due to the IPv6 that is used by the p2p0 interface.

Hacking with the code I ended up with the patch below which seems to fix the problem and everything is working ok now.

--- mconf-mobile/sipdroid/src/org/zoolu/net/IpAddress.java  2014-06-20 08:42:33.427511605 -0700
+++ workspace/sipdroid/src/org/zoolu/net/IpAddress.java 2014-06-22 08:13:33.320229897 -0700
@@ -140,34 +140,36 @@
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();

-               for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
-                   InetAddress inetAddress = enumIpAddr.nextElement();
-
-                   if (!inetAddress.isLoopbackAddress()) { 
-                       if (!PreferenceManager.getDefaultSharedPreferences(getUIContext()).getBoolean(Settings.PREF_STUN, Settings.DEFAULT_STUN)) {
-                           localIpAddress = inetAddress.getHostAddress().toString();
-                       } else {
-                           try {
-                               String StunServer = PreferenceManager.getDefaultSharedPreferences(getUIContext()).getString(Settings.PREF_STUN_SERVER, Settings.DEFAULT_STUN_SERVER);
-                               int StunServerPort = Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getUIContext()).getString(Settings.PREF_STUN_SERVER_PORT, Settings.DEFAULT_STUN_SERVER_PORT));
-
-                               DiscoveryTest StunDiscover = new DiscoveryTest(inetAddress, StunServer, StunServerPort);
-
-                               // call out to stun server 
-                               StunDiscover.test();
-                               //System.out.println("Public ip is:" + StunDiscover.di.getPublicIP().getHostAddress());
-                               localIpAddress = StunDiscover.di.getPublicIP().getHostAddress();
-                           } catch (BindException be) {
-                               if (!Sipdroid.release)
-                                   System.out.println(inetAddress.toString() + ": " + be.getMessage());
-                           } catch (Exception e) {
-                               if (!Sipdroid.release) {
-                                   System.out.println(e.getMessage());
-                                   e.printStackTrace();
-                               }
-                           } 
-                       }
-                   }                   
+               if(!intf.getName().contains("p2p")) {   
+                   for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
+                       InetAddress inetAddress = enumIpAddr.nextElement();
+   
+                       if (!inetAddress.isLoopbackAddress()) { 
+                           if (!PreferenceManager.getDefaultSharedPreferences(getUIContext()).getBoolean(Settings.PREF_STUN, Settings.DEFAULT_STUN)) {
+                               localIpAddress = inetAddress.getHostAddress().toString();
+                           } else {
+                               try {
+                                   String StunServer = PreferenceManager.getDefaultSharedPreferences(getUIContext()).getString(Settings.PREF_STUN_SERVER, Settings.DEFAULT_STUN_SERVER);
+                                   int StunServerPort = Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(getUIContext()).getString(Settings.PREF_STUN_SERVER_PORT, Settings.DEFAULT_STUN_SERVER_PORT));
+   
+                                   DiscoveryTest StunDiscover = new DiscoveryTest(inetAddress, StunServer, StunServerPort);
+   
+                                   // call out to stun server 
+                                   StunDiscover.test();
+                                   //System.out.println("Public ip is:" + StunDiscover.di.getPublicIP().getHostAddress());
+                                   localIpAddress = StunDiscover.di.getPublicIP().getHostAddress();
+                               } catch (BindException be) {
+                                   if (!Sipdroid.release)
+                                       System.out.println(inetAddress.toString() + ": " + be.getMessage());
+                               } catch (Exception e) {
+                                   if (!Sipdroid.release) {
+                                       System.out.println(e.getMessage());
+                                       e.printStackTrace();
+                                   }
+                               } 
+                           }
+                       }                   
+                   }
                }
            }
        } catch (SocketException ex) {
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant