Fix initialization of RouteInfo
IPv6 gateway is not correctly set in RouteInfo
Change-Id: I24b1ab71a64e3097c9ba641899240fc27847b86c
diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java
index 9c4e48b..39e708a 100644
--- a/core/java/android/net/RouteInfo.java
+++ b/core/java/android/net/RouteInfo.java
@@ -47,13 +47,25 @@
public RouteInfo(LinkAddress destination, InetAddress gateway) {
if (destination == null) {
try {
- if ((gateway != null) || (gateway instanceof Inet4Address)) {
- destination = new LinkAddress(Inet4Address.ANY, 0);
+ if (gateway != null) {
+ if (gateway instanceof Inet4Address) {
+ destination = new LinkAddress(Inet4Address.ANY, 0);
+ } else {
+ destination = new LinkAddress(Inet6Address.ANY, 0);
+ }
} else {
- destination = new LinkAddress(Inet6Address.ANY, 0);
+ // no destination, no gateway. invalid.
+ throw new RuntimeException("Invalid arguments passed in.");
}
} catch (Exception e) {}
}
+ if (gateway == null) {
+ if (destination.getAddress() instanceof Inet4Address) {
+ gateway = Inet4Address.ANY;
+ } else {
+ gateway = Inet6Address.ANY;
+ }
+ }
mDestination = new LinkAddress(NetworkUtils.getNetworkPart(destination.getAddress(),
destination.getNetworkPrefixLength()), destination.getNetworkPrefixLength());
mGateway = gateway;