use of android.net.RouteInfo in project XobotOS by xamarin.
the class DataCallState method setLinkProperties.
public SetupResult setLinkProperties(LinkProperties linkProperties, boolean okToUseSystemPropertyDns) {
SetupResult result;
// a failure we'll clear again at the bottom of this code.
if (linkProperties == null)
linkProperties = new LinkProperties();
else
linkProperties.clear();
if (status == FailCause.NONE.getErrorCode()) {
String propertyPrefix = "net." + ifname + ".";
try {
// set interface name
linkProperties.setInterfaceName(ifname);
// set link addresses
if (addresses != null && addresses.length > 0) {
for (String addr : addresses) {
LinkAddress la;
int addrPrefixLen;
String[] ap = addr.split("/");
if (ap.length == 2) {
addr = ap[0];
addrPrefixLen = Integer.parseInt(ap[1]);
} else {
addrPrefixLen = 0;
}
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(addr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric ip addr=" + addr);
}
if (!ia.isAnyLocalAddress()) {
if (addrPrefixLen == 0) {
// Assume point to point
addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128;
}
if (DBG)
Log.d(LOG_TAG, "addr/pl=" + addr + "/" + addrPrefixLen);
la = new LinkAddress(ia, addrPrefixLen);
linkProperties.addLinkAddress(la);
}
}
} else {
throw new UnknownHostException("no address for ifname=" + ifname);
}
// set dns servers
if (dnses != null && dnses.length > 0) {
for (String addr : dnses) {
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(addr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric dns addr=" + addr);
}
if (!ia.isAnyLocalAddress()) {
linkProperties.addDns(ia);
}
}
} else if (okToUseSystemPropertyDns) {
String[] dnsServers = new String[2];
dnsServers[0] = SystemProperties.get(propertyPrefix + "dns1");
dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2");
for (String dnsAddr : dnsServers) {
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(dnsAddr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric dns addr=" + dnsAddr);
}
if (!ia.isAnyLocalAddress()) {
linkProperties.addDns(ia);
}
}
} else {
throw new UnknownHostException("Empty dns response and no system default dns");
}
// set gateways
if ((gateways == null) || (gateways.length == 0)) {
String sysGateways = SystemProperties.get(propertyPrefix + "gw");
if (sysGateways != null) {
gateways = sysGateways.split(" ");
} else {
gateways = new String[0];
}
}
for (String addr : gateways) {
InetAddress ia;
try {
ia = NetworkUtils.numericToInetAddress(addr);
} catch (IllegalArgumentException e) {
throw new UnknownHostException("Non-numeric gateway addr=" + addr);
}
if (!ia.isAnyLocalAddress()) {
linkProperties.addRoute(new RouteInfo(ia));
}
}
result = SetupResult.SUCCESS;
} catch (UnknownHostException e) {
Log.d(LOG_TAG, "setLinkProperties: UnknownHostException " + e);
e.printStackTrace();
result = SetupResult.ERR_UnacceptableParameter;
}
} else {
if (version < 4) {
result = SetupResult.ERR_GetLastErrorFromRil;
} else {
result = SetupResult.ERR_RilError;
}
}
// An error occurred so clear properties
if (result != SetupResult.SUCCESS) {
if (DBG) {
Log.d(LOG_TAG, "setLinkProperties: error clearing LinkProperties " + "status=" + status + " result=" + result);
}
linkProperties.clear();
}
return result;
}
use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.
the class RouteInfoTest method testMatches.
public void testMatches() {
class PatchedRouteInfo {
private final RouteInfo mRouteInfo;
public PatchedRouteInfo(IpPrefix destination, InetAddress gateway, String iface) {
mRouteInfo = new RouteInfo(destination, gateway, iface);
}
public boolean matches(InetAddress destination) {
return mRouteInfo.matches(destination);
}
}
PatchedRouteInfo r;
r = new PatchedRouteInfo(Prefix("2001:db8:f00::ace:d00d/127"), null, "rmnet0");
assertTrue(r.matches(Address("2001:db8:f00::ace:d00c")));
assertTrue(r.matches(Address("2001:db8:f00::ace:d00d")));
assertFalse(r.matches(Address("2001:db8:f00::ace:d00e")));
assertFalse(r.matches(Address("2001:db8:f00::bad:d00d")));
assertFalse(r.matches(Address("2001:4868:4860::8888")));
assertFalse(r.matches(Address("8.8.8.8")));
r = new PatchedRouteInfo(Prefix("192.0.2.0/23"), null, "wlan0");
assertTrue(r.matches(Address("192.0.2.43")));
assertTrue(r.matches(Address("192.0.3.21")));
assertFalse(r.matches(Address("192.0.0.21")));
assertFalse(r.matches(Address("8.8.8.8")));
PatchedRouteInfo ipv6Default = new PatchedRouteInfo(Prefix("::/0"), null, "rmnet0");
assertTrue(ipv6Default.matches(Address("2001:db8::f00")));
assertFalse(ipv6Default.matches(Address("192.0.2.1")));
PatchedRouteInfo ipv4Default = new PatchedRouteInfo(Prefix("0.0.0.0/0"), null, "rmnet0");
assertTrue(ipv4Default.matches(Address("255.255.255.255")));
assertTrue(ipv4Default.matches(Address("192.0.2.1")));
assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.
the class RouteInfoTest method testMulticastRoute.
// Make sure that creating routes to multicast addresses doesn't throw an exception. Even though
// there's nothing we can do with them, we don't want to crash if, e.g., someone calls
// requestRouteToHostAddress("230.0.0.0", MOBILE_HIPRI);
public void testMulticastRoute() {
RouteInfo r;
r = new RouteInfo(Prefix("230.0.0.0/32"), Address("192.0.2.1"), "wlan0");
r = new RouteInfo(Prefix("ff02::1/128"), Address("2001:db8::1"), "wlan0");
// No exceptions? Good.
}
use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.
the class RouteInfoTest method testTruncation.
public void testTruncation() {
LinkAddress l;
RouteInfo r;
l = new LinkAddress("192.0.2.5/30");
r = new RouteInfo(l, Address("192.0.2.1"), "wlan0");
assertEquals("192.0.2.4", r.getDestination().getAddress().getHostAddress());
l = new LinkAddress("2001:db8:1:f::5/63");
r = new RouteInfo(l, Address("2001:db8:5::1"), "wlan0");
assertEquals("2001:db8:1:e::", r.getDestination().getAddress().getHostAddress());
}
use of android.net.RouteInfo in project android_frameworks_base by ResurrectionRemix.
the class IPv6TetheringCoordinator method getIPv6OnlyLinkProperties.
private static LinkProperties getIPv6OnlyLinkProperties(LinkProperties lp) {
final LinkProperties v6only = new LinkProperties();
if (lp == null) {
return v6only;
}
// NOTE: At this time we don't copy over any information about any
// stacked links. No current stacked link configuration has IPv6.
v6only.setInterfaceName(lp.getInterfaceName());
v6only.setMtu(lp.getMtu());
for (LinkAddress linkAddr : lp.getLinkAddresses()) {
if (linkAddr.isGlobalPreferred() && linkAddr.getPrefixLength() == 64) {
v6only.addLinkAddress(linkAddr);
}
}
for (RouteInfo routeInfo : lp.getRoutes()) {
final IpPrefix destination = routeInfo.getDestination();
if ((destination.getAddress() instanceof Inet6Address) && (destination.getPrefixLength() <= 64)) {
v6only.addRoute(routeInfo);
}
}
for (InetAddress dnsServer : lp.getDnsServers()) {
if (isIPv6GlobalAddress(dnsServer)) {
// For now we include ULAs.
v6only.addDnsServer(dnsServer);
}
}
v6only.setDomains(lp.getDomains());
return v6only;
}
Aggregations