private int validateIpConfigFields(LinkProperties linkProperties) {
    String ipAddr = mIpAddressView.getText().toString();
    InetAddress inetAddr = null;
    try {
      inetAddr = NetworkUtils.numericToInetAddress(ipAddr);
    } catch (IllegalArgumentException e) {
      return R.string.wifi_ip_settings_invalid_ip_address;
    }

    int networkPrefixLength = -1;
    try {
      networkPrefixLength = Integer.parseInt(mNetworkPrefixLengthView.getText().toString());
    } catch (NumberFormatException e) {
      // Use -1
    }
    if (networkPrefixLength < 0 || networkPrefixLength > 32) {
      return R.string.wifi_ip_settings_invalid_network_prefix_length;
    }
    linkProperties.addLinkAddress(new LinkAddress(inetAddr, networkPrefixLength));

    String gateway = mGatewayView.getText().toString();
    InetAddress gatewayAddr = null;
    try {
      gatewayAddr = NetworkUtils.numericToInetAddress(gateway);
    } catch (IllegalArgumentException e) {
      return R.string.wifi_ip_settings_invalid_gateway;
    }
    linkProperties.addRoute(new RouteInfo(gatewayAddr));

    String dns = mDns1View.getText().toString();
    InetAddress dnsAddr = null;
    try {
      dnsAddr = NetworkUtils.numericToInetAddress(dns);
    } catch (IllegalArgumentException e) {
      return R.string.wifi_ip_settings_invalid_dns;
    }
    linkProperties.addDns(dnsAddr);
    if (mDns2View.length() > 0) {
      dns = mDns2View.getText().toString();
      try {
        dnsAddr = NetworkUtils.numericToInetAddress(dns);
      } catch (IllegalArgumentException e) {
        return R.string.wifi_ip_settings_invalid_dns;
      }
      linkProperties.addDns(dnsAddr);
    }
    return 0;
  }
 private boolean readLinkProperty(String iface) {
   String DhcpPrefix = "dhcp." + iface + ".";
   String ip = SystemProperties.get(DhcpPrefix + "ipaddress");
   String dns1 = SystemProperties.get(DhcpPrefix + "dns1");
   String dns2 = SystemProperties.get(DhcpPrefix + "dns2");
   String gateway = SystemProperties.get(DhcpPrefix + "gateway");
   String mask = SystemProperties.get(DhcpPrefix + "mask");
   if (ip.isEmpty() || gateway.isEmpty()) {
     Log.e(TAG, "readLinkProperty, ip: " + ip + ", gateway: " + gateway + ", can not be empty");
     return false;
   }
   int PrefixLen = countPrefixLength(NetworkUtils.numericToInetAddress(mask).getAddress());
   mLinkProperties.addLinkAddress(
       new LinkAddress(NetworkUtils.numericToInetAddress(ip), PrefixLen));
   RouteInfo ri = new RouteInfo(NetworkUtils.numericToInetAddress(gateway));
   mLinkProperties.addRoute(ri);
   if (!dns1.isEmpty()) mLinkProperties.addDns(NetworkUtils.numericToInetAddress(dns1));
   if (!dns2.isEmpty()) mLinkProperties.addDns(NetworkUtils.numericToInetAddress(dns2));
   mLinkProperties.setInterfaceName(iface);
   return true;
 }
  private int validateIpConfigFields(LinkProperties linkProperties) {
    if (mIpAddressView == null) return 0;

    String ipAddr = mIpAddressView.getText().toString();
    if (TextUtils.isEmpty(ipAddr)) return R.string.wifi_ip_settings_invalid_ip_address;

    InetAddress inetAddr = null;
    try {
      inetAddr = NetworkUtils.numericToInetAddress(ipAddr);
    } catch (IllegalArgumentException e) {
      return R.string.wifi_ip_settings_invalid_ip_address;
    }

    int networkPrefixLength = -1;
    try {
      networkPrefixLength = Integer.parseInt(mNetworkPrefixLengthView.getText().toString());
      if (networkPrefixLength < 0 || networkPrefixLength > 32) {
        return R.string.wifi_ip_settings_invalid_network_prefix_length;
      }
      linkProperties.addLinkAddress(new LinkAddress(inetAddr, networkPrefixLength));
    } catch (NumberFormatException e) {
      // Set the hint as default after user types in ip address
      mNetworkPrefixLengthView.setText(
          mConfigUi.getContext().getString(R.string.wifi_network_prefix_length_hint));
    }

    String gateway = mGatewayView.getText().toString();
    if (TextUtils.isEmpty(gateway)) {
      try {
        // Extract a default gateway from IP address
        InetAddress netPart = NetworkUtils.getNetworkPart(inetAddr, networkPrefixLength);
        byte[] addr = netPart.getAddress();
        addr[addr.length - 1] = 1;
        mGatewayView.setText(InetAddress.getByAddress(addr).getHostAddress());
      } catch (RuntimeException ee) {
      } catch (java.net.UnknownHostException u) {
      }
    } else {
      InetAddress gatewayAddr = null;
      try {
        gatewayAddr = NetworkUtils.numericToInetAddress(gateway);
      } catch (IllegalArgumentException e) {
        return R.string.wifi_ip_settings_invalid_gateway;
      }
      linkProperties.addRoute(new RouteInfo(gatewayAddr));
    }

    String dns = mDns1View.getText().toString();
    InetAddress dnsAddr = null;

    if (TextUtils.isEmpty(dns)) {
      // If everything else is valid, provide hint as a default option
      mDns1View.setText(mConfigUi.getContext().getString(R.string.wifi_dns1_hint));
    } else {
      try {
        dnsAddr = NetworkUtils.numericToInetAddress(dns);
      } catch (IllegalArgumentException e) {
        return R.string.wifi_ip_settings_invalid_dns;
      }
      linkProperties.addDns(dnsAddr);
    }

    if (mDns2View.length() > 0) {
      dns = mDns2View.getText().toString();
      try {
        dnsAddr = NetworkUtils.numericToInetAddress(dns);
      } catch (IllegalArgumentException e) {
        return R.string.wifi_ip_settings_invalid_dns;
      }
      linkProperties.addDns(dnsAddr);
    }
    return 0;
  }