import android.os.Parcel;
import android.os.Parcelable;
+import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.UnknownHostException;
*/
private final int prefixLength;
- public LinkAddress(InetAddress address, InetAddress mask) {
- this.address = address;
- this.prefixLength = computeprefixLength(mask);
- }
-
public LinkAddress(InetAddress address, int prefixLength) {
+ if (address == null || prefixLength < 0 ||
+ ((address instanceof Inet4Address) && prefixLength > 32) ||
+ (prefixLength > 128)) {
+ throw new IllegalArgumentException("Bad LinkAddress params " + address +
+ prefixLength);
+ }
this.address = address;
this.prefixLength = prefixLength;
}
this.prefixLength = interfaceAddress.getNetworkPrefixLength();
}
- private static int computeprefixLength(InetAddress mask) {
- int count = 0;
- for (byte b : mask.getAddress()) {
- for (int i = 0; i < 8; ++i) {
- if ((b & (1 << i)) != 0) {
- ++count;
- }
- }
- }
- return count;
- }
-
@Override
public String toString() {
return (address == null ? "" : (address.getHostAddress() + "/" + prefixLength));
private static final String BLUETOOTH_IFACE_ADDR_START= "192.168.44.1";
private static final int BLUETOOTH_MAX_PAN_CONNECTIONS = 5;
- private static final String BLUETOOTH_NETMASK = "255.255.255.0";
+ private static final int BLUETOOTH_PREFIX_LENGTH = 24;
// The timeout used to sent the UUIDs Intent
// This timeout should be greater than the page timeout
try {
ifcg = service.getInterfaceConfig(iface);
if (ifcg != null) {
- InetAddress mask = InetAddress.getByName(BLUETOOTH_NETMASK);
InetAddress addr = null;
if (ifcg.addr == null || (addr = ifcg.addr.getAddress()) == null ||
addr.equals(InetAddress.getByName("0.0.0.0")) ||
addr = InetAddress.getByName(address);
}
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
- ifcg.addr = new LinkAddress(addr, mask);
+ ifcg.addr = new LinkAddress(addr, BLUETOOTH_PREFIX_LENGTH);
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
service.setInterfaceConfig(iface, ifcg);
* <accesspoint></accesspoint>. The supported configuration includes: ssid,
* security, eap, phase2, identity, password, anonymousidentity, cacert, usercert,
* in which each is included in the corresponding tags. Static IP setting is also supported.
- * Tags that can be used include: ip, gateway, netmask, dns1, dns2. All access points have to be
- * enclosed in tags of <resources></resources>.
+ * Tags that can be used include: ip, gateway, networkprefixlength, dns1, dns2. All access points
+ * have to be enclosed in tags of <resources></resources>.
*
* The following is a sample configuration file for an access point using EAP-PEAP with MSCHAP2.
* <resources>
* </resources>
*
* Note:ssid and security have to be the first two tags
- * for static ip setting, tag "ip" should be listed before other fields: dns, gateway, netmask.
+ * for static ip setting, tag "ip" should be listed before other fields: dns, gateway,
+ * networkprefixlength.
*/
public class AccessPointParserHelper {
private static final String KEYSTORE_SPACE = "keystore://";
boolean ip = false;
boolean gateway = false;
boolean networkprefix = false;
- boolean netmask = false;
boolean dns1 = false;
boolean dns2 = false;
boolean eap = false;
if (tagName.equalsIgnoreCase("networkprefixlength")) {
networkprefix = true;
}
- if (tagName.equalsIgnoreCase("netmask")) {
- netmask = true;
- }
if (tagName.equalsIgnoreCase("dns1")) {
dns1 = true;
}
}
networkprefix = false;
}
- if (netmask) {
- try {
- String netMaskStr = new String(ch, start, length);
- if (!InetAddress.isNumeric(netMaskStr)) {
- throw new SAXException();
- }
- InetAddress netMaskAddr = InetAddress.getByName(netMaskStr);
- mLinkProperties.addLinkAddress(new LinkAddress(mInetAddr, netMaskAddr));
- } catch (UnknownHostException e) {
- throw new SAXException();
- }
- netmask = false;
- }
if (dns1) {
try {
String dnsAddr = new String(ch, start, length);
private BroadcastReceiver mStateReceiver;
private static final String USB_NEAR_IFACE_ADDR = "192.168.42.129";
- private static final String USB_NETMASK = "255.255.255.0";
+ private static final int USB_PREFIX_LENGTH = 24;
// USB is 192.168.42.1 and 255.255.255.0
// Wifi is 192.168.43.1 and 255.255.255.0
ifcg = service.getInterfaceConfig(iface);
if (ifcg != null) {
InetAddress addr = InetAddress.getByName(USB_NEAR_IFACE_ADDR);
- InetAddress mask = InetAddress.getByName(USB_NETMASK);
- ifcg.addr = new LinkAddress(addr, mask);
+ ifcg.addr = new LinkAddress(addr, USB_PREFIX_LENGTH);
if (enabled) {
ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
} else {