@@ -168,7 +168,10 @@ public synchronized void stopServer() {
168
168
}
169
169
170
170
public CharSequence [] listOfIpAddresses () {
171
- ArrayList <String > arrayOfIps = new ArrayList <String >();
171
+ ArrayList <String > arrayOfIps = new ArrayList <String >(); // preferred IPs
172
+ ArrayList <String > arrayOfIps4 = new ArrayList <String >(); // IPv4 addresses
173
+ ArrayList <String > arrayOfIps6 = new ArrayList <String >(); // IPv6 addresses
174
+ ArrayList <String > arrayOfIpsL = new ArrayList <String >(); // loopback
172
175
173
176
174
177
try {
@@ -184,17 +187,27 @@ public CharSequence[] listOfIpAddresses() {
184
187
String theIpTemp = inetAddress .getHostAddress ();
185
188
String theIp = getServerUrl (theIpTemp );
186
189
187
- if (inetAddress instanceof Inet6Address
188
- || inetAddress .isLoopbackAddress ()) {
189
-
190
- arrayOfIps .add (theIp );
190
+ if (inetAddress instanceof Inet6Address ) {
191
+ arrayOfIps6 .add (theIp );
192
+ continue ;
193
+ } else if (inetAddress .isLoopbackAddress ()) {
194
+ arrayOfIpsL .add (theIp );
195
+ continue ;
196
+ } else if (intf .getDisplayName ().matches ("wlan.*" )) {
197
+ arrayOfIps .add (0 ,theIp ); // prefer IPv4 on wlan interface
198
+ continue ;
199
+ } else {
200
+ arrayOfIps4 .add (theIp );
191
201
continue ;
192
202
}
193
-
194
- arrayOfIps .add (0 , theIp ); // we prefer non local IPv4
195
203
}
196
204
}
197
205
206
+ // append IP lists in order of preference
207
+ arrayOfIps .addAll (arrayOfIps4 );
208
+ arrayOfIps .addAll (arrayOfIps6 );
209
+ arrayOfIps .addAll (arrayOfIpsL );
210
+
198
211
if (arrayOfIps .size () == 0 ) {
199
212
String firstIp = getServerUrl ("0.0.0.0" );
200
213
arrayOfIps .add (firstIp );
0 commit comments