From 698ce0c52c0caa7dcbf2baa605f385c7864a8fc1 Mon Sep 17 00:00:00 2001 From: Greg Alexander Date: Sun, 18 Jan 2015 16:26:36 -0500 Subject: [PATCH] now it skips the fe80 bogus ipv6 addr --- NOTES | 14 ++++++++++++++ res/layout/main.xml | 1 + src/org/galexander/sshd/SimpleSSHD.java | 10 ++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/NOTES b/NOTES index b13c268..ee04362 100644 --- a/NOTES +++ b/NOTES @@ -157,6 +157,20 @@ So that is my remedy -- static executables for the moment. I tested them and it is only a little bit bigger -- 904kB of binaries instead of 668kB. +January 18, 2015. + +Markus Ethen suggested it display the current IP address so you know +where to ssh to, in case it isn't convenient to use static dhcp or to +remember the address. That seems to be easier said than done. You can +use WifiManager, but that won't give your IP address unless you're on +wifi. That is probably "good enough", but it is certainly not ideal. +There is also java.net.NetworkInterface, which seems to return a random +ipv6 address. + +Ah-hah! It is fe80::macaddr, which is a bogus "local-connection only" +ipv6 address, like 192.168, but automatically-generated without dhcp. +So if I skip that, it finds the proper ipv4 address! + XXX - display the phone's IP address XXX - if you remove it from the recent apps list, does it stop the service?? XXX - support password-based logins? diff --git a/res/layout/main.xml b/res/layout/main.xml index 0022207..535657b 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -10,6 +10,7 @@ android:typeface="monospace" android:singleLine="true" android:background="#ff112266" + android:scrollHorizontally="true" android:text="IP: XXX" /> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { - if (!addr.isLoopbackAddress()) { - return addr.getHostAddress(); + String ip = addr.getHostAddress(); + if (!addr.isLoopbackAddress() && + !ip.startsWith("fe80")) { + int i = ip.indexOf('%'); + if (i != -1) { + ip = ip.substring(0,i); + } + return ip; } } }