diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2011-02-22 16:00:42 -0800 |
---|---|---|
committer | Robert Greenwalt <rgreenwalt@google.com> | 2011-03-02 11:37:32 -0800 |
commit | e590373ea71251cfffc8f22f011e2e6335dce716 (patch) | |
tree | 4fb1c57267a51143b6a0ebaf10174ae89280b6c2 /telephony | |
parent | 0390191392e62314d9dfeba655f737a0e2594950 (diff) | |
download | frameworks_base-e590373ea71251cfffc8f22f011e2e6335dce716.zip frameworks_base-e590373ea71251cfffc8f22f011e2e6335dce716.tar.gz frameworks_base-e590373ea71251cfffc8f22f011e2e6335dce716.tar.bz2 |
Start using NetworkUtils.numericToInetAddress.
Generates InetAddresses without risking an accidental dns lookup. For use with supposedly
numeric-only ip address strings.
Change-Id: I694f3976ce1c6382854706f6557ea88a289add3a
Diffstat (limited to 'telephony')
-rw-r--r-- | telephony/java/com/android/internal/telephony/DataConnection.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java index e0b9603..89513fd 100644 --- a/telephony/java/com/android/internal/telephony/DataConnection.java +++ b/telephony/java/com/android/internal/telephony/DataConnection.java @@ -23,6 +23,7 @@ import com.android.internal.util.HierarchicalStateMachine; import android.net.LinkAddress; import android.net.LinkCapabilities; import android.net.LinkProperties; +import android.net.NetworkUtils; import android.os.AsyncResult; import android.os.Message; import android.os.SystemProperties; @@ -415,11 +416,13 @@ public abstract class DataConnection extends HierarchicalStateMachine { } else { addrPrefixLen = 0; } - if (!InetAddress.isNumeric(addr)) { + InetAddress ia; + try { + ia = NetworkUtils.numericToInetAddress(addr); + } catch (IllegalArgumentException e) { EventLogTags.writeBadIpAddress(addr); throw new UnknownHostException("Non-numeric ip addr=" + addr); } - InetAddress ia = InetAddress.getByName(addr); if (addrPrefixLen == 0) { // Assume point to point addrPrefixLen = (ia instanceof Inet4Address) ? 32 : 128; @@ -434,11 +437,13 @@ public abstract class DataConnection extends HierarchicalStateMachine { } if (response.dnses != null && response.dnses.length > 0) { for (String addr : response.dnses) { - if (!InetAddress.isNumeric(addr)) { + InetAddress ia; + try { + ia = NetworkUtils.numericToInetAddress(addr); + } catch (IllegalArgumentException e) { EventLogTags.writePdpBadDnsAddress("dns=" + addr); throw new UnknownHostException("Non-numeric dns addr=" + addr); } - InetAddress ia = InetAddress.getByName(addr); linkProperties.addDns(ia); } result = SetupResult.SUCCESS; @@ -448,12 +453,14 @@ public abstract class DataConnection extends HierarchicalStateMachine { dnsServers[1] = SystemProperties.get(propertyPrefix + "dns2"); if (isDnsOk(dnsServers)) { for (String dnsAddr : dnsServers) { - if (!InetAddress.isNumeric(dnsAddr)) { + InetAddress ia; + try { + ia = NetworkUtils.numericToInetAddress(dnsAddr); + } catch (IllegalArgumentException e) { EventLogTags.writePdpBadDnsAddress("dnsAddr=" + dnsAddr); throw new UnknownHostException("Non-numeric dns addr=" + dnsAddr); } - InetAddress ia = InetAddress.getByName(dnsAddr); linkProperties.addDns(ia); } result = SetupResult.SUCCESS; @@ -476,11 +483,13 @@ public abstract class DataConnection extends HierarchicalStateMachine { } } for (String addr : response.gateways) { - if (!InetAddress.isNumeric(addr)) { + InetAddress ia; + try { + ia = NetworkUtils.numericToInetAddress(addr); + } catch (IllegalArgumentException e) { EventLogTags.writePdpBadDnsAddress("gateway=" + addr); throw new UnknownHostException("Non-numeric gateway addr=" + addr); } - InetAddress ia = InetAddress.getByName(addr); linkProperties.addGateway(ia); } result = SetupResult.SUCCESS; |