DnsConfig: don't use signed bytes when printing.

intToInetString(0x0101a8c0) returns "-64.-88.1.1" because Java
integers are always signed. There is not a %u format specifier.

Though the quads of an IP address literally are bytes, they can
be left as an int to pass to String.format. This allows room for
sign bits, so intToInetString(0x0101a8c0) returns "192.168.1.1"

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
pull/51/head
Denton Gentry 2 years ago
parent db31496a24
commit 63dba694af

@ -231,10 +231,10 @@ public class DnsConfig {
String intToInetString(int hostAddress) {
return String.format(java.util.Locale.ROOT, "%d.%d.%d.%d",
(byte)(0xff & hostAddress),
(byte)(0xff & (hostAddress >> 8)),
(byte)(0xff & (hostAddress >> 16)),
(byte)(0xff & (hostAddress >> 24)));
(0xff & hostAddress),
(0xff & (hostAddress >> 8)),
(0xff & (hostAddress >> 16)),
(0xff & (hostAddress >> 24)));
}
// getDnsServersFromNetworkInfo retrieves DNS servers using ConnectivityManager

Loading…
Cancel
Save