Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e48e76c authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "Start using NetworkUtils.numericToInetAddress."

parents 76bb1200 e590373e
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -233,17 +233,11 @@ public final class Proxy {
                if (host.equalsIgnoreCase("localhost")) {
                    return true;
                }
                // Check we have a numeric address so we don't cause a DNS lookup in getByName.
                if (InetAddress.isNumeric(host)) {
                    if (InetAddress.getByName(host).isLoopbackAddress()) {
                if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
                    return true;
                }
            }
            }
        } catch (UnknownHostException ignored) {
            // Can't happen for a numeric address (InetAddress.getByName).
        } catch (IllegalArgumentException iex) {
            // Ignore (URI.create)
        }
        return false;
    }
+4 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.res.Resources.NotFoundException;
import android.net.ConnectivityManager;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.ServiceManager;
@@ -379,9 +380,9 @@ final class BluetoothPanProfileHandler {
            if (ifcg != null) {
                InetAddress addr = null;
                if (ifcg.addr == null || (addr = ifcg.addr.getAddress()) == null ||
                        addr.equals(InetAddress.getByName("0.0.0.0")) ||
                        addr.equals(InetAddress.getByName("::0"))) {
                    addr = InetAddress.getByName(address);
                        addr.equals(NetworkUtils.numericToInetAddress("0.0.0.0")) ||
                        addr.equals(NetworkUtils.numericToInetAddress("::0"))) {
                    addr = NetworkUtils.numericToInetAddress(address);
                }
                ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
                ifcg.addr = new LinkAddress(addr, BLUETOOTH_PREFIX_LENGTH);
+5 −21
Original line number Diff line number Diff line
@@ -15,12 +15,11 @@
 */
package com.android.internal.net;


import android.net.NetworkUtils;
import android.util.Config;
import android.util.Log;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.Collection;
@@ -38,13 +37,6 @@ public class DomainNameValidator {
    private static final boolean DEBUG = false;
    private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;

    private static Pattern QUICK_IP_PATTERN;
    static {
        try {
            QUICK_IP_PATTERN = Pattern.compile("^[a-f0-9\\.:]+$");
        } catch (PatternSyntaxException e) {}
    }

    private static final int ALT_DNS_NAME = 2;
    private static final int ALT_IPA_NAME = 7;

@@ -75,19 +67,11 @@ public class DomainNameValidator {
        if (rval) {
            try {
                // do a quick-dirty IP match first to avoid DNS lookup
                rval = QUICK_IP_PATTERN.matcher(domain).matches();
                if (rval) {
                rval = domain.equals(
                        InetAddress.getByName(domain).getHostAddress());
                }
            } catch (UnknownHostException e) {
                String errorMessage = e.getMessage();
                if (errorMessage == null) {
                  errorMessage = "unknown host exception";
                }

                        NetworkUtils.numericToInetAddress(domain).getHostAddress());
            } catch (IllegalArgumentException e) {
                if (LOG_ENABLED) {
                    Log.v(TAG, "DomainNameValidator.isIpAddress(): " + errorMessage);
                    Log.v(TAG, "DomainNameValidator.isIpAddress(): " + e);
                }

                rval = false;
+2 −2
Original line number Diff line number Diff line
@@ -286,8 +286,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                    com.android.internal.R.string.config_default_dns_server);
        }
        try {
            mDefaultDns = InetAddress.getByName(dns);
        } catch (UnknownHostException e) {
            mDefaultDns = NetworkUtils.numericToInetAddress(dns);
        } catch (IllegalArgumentException e) {
            loge("Error setting defaultDns using " + dns);
        }

+10 −10
Original line number Diff line number Diff line
@@ -270,9 +270,9 @@ class NetworkManagementService extends INetworkManagementService.Stub {
            InetAddress addr = null;
            int prefixLength = 0;
            try {
                addr = InetAddress.getByName(st.nextToken(" "));
            } catch (UnknownHostException uhe) {
                Slog.e(TAG, "Failed to parse ipaddr", uhe);
                addr = NetworkUtils.numericToInetAddress(st.nextToken(" "));
            } catch (IllegalArgumentException iae) {
                Slog.e(TAG, "Failed to parse ipaddr", iae);
            }

            try {
@@ -451,7 +451,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
        try {
            String cmd = "tether dns set";
            for (String s : dns) {
                cmd += " " + InetAddress.getByName(s).getHostAddress();
                cmd += " " + NetworkUtils.numericToInetAddress(s).getHostAddress();
            }
            try {
                mConnector.doCommand(cmd);
@@ -459,7 +459,7 @@ class NetworkManagementService extends INetworkManagementService.Stub {
                throw new IllegalStateException(
                        "Unable to communicate to native daemon for setting tether dns");
            }
        } catch (UnknownHostException e) {
        } catch (IllegalArgumentException e) {
            throw new IllegalStateException("Error resolving dns name", e);
        }
    }
@@ -519,11 +519,11 @@ class NetworkManagementService extends INetworkManagementService.Stub {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
            mConnector.doCommand(String.format("pppd attach %s %s %s %s %s", tty,
                    InetAddress.getByName(localAddr).getHostAddress(),
                    InetAddress.getByName(remoteAddr).getHostAddress(),
                    InetAddress.getByName(dns1Addr).getHostAddress(),
                    InetAddress.getByName(dns2Addr).getHostAddress()));
        } catch (UnknownHostException e) {
                    NetworkUtils.numericToInetAddress(localAddr).getHostAddress(),
                    NetworkUtils.numericToInetAddress(remoteAddr).getHostAddress(),
                    NetworkUtils.numericToInetAddress(dns1Addr).getHostAddress(),
                    NetworkUtils.numericToInetAddress(dns2Addr).getHostAddress()));
        } catch (IllegalArgumentException e) {
            throw new IllegalStateException("Error resolving addr", e);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException("Error communicating to native daemon to attach pppd", e);
Loading