use of android.net.DhcpResults in project android_frameworks_base by ResurrectionRemix.
the class DhcpPacket method toDhcpResults.
/**
* Construct a DhcpResults object from a DHCP reply packet.
*/
public DhcpResults toDhcpResults() {
Inet4Address ipAddress = mYourIp;
if (ipAddress.equals(Inet4Address.ANY)) {
ipAddress = mClientIp;
if (ipAddress.equals(Inet4Address.ANY)) {
return null;
}
}
int prefixLength;
if (mSubnetMask != null) {
try {
prefixLength = NetworkUtils.netmaskToPrefixLength(mSubnetMask);
} catch (IllegalArgumentException e) {
// Non-contiguous netmask.
return null;
}
} else {
prefixLength = NetworkUtils.getImplicitNetmask(ipAddress);
}
DhcpResults results = new DhcpResults();
try {
results.ipAddress = new LinkAddress(ipAddress, prefixLength);
} catch (IllegalArgumentException e) {
return null;
}
if (mGateways.size() > 0) {
results.gateway = mGateways.get(0);
}
results.dnsServers.addAll(mDnsServers);
results.domains = mDomainName;
results.serverAddress = mServerIdentifier;
results.vendorInfo = mVendorInfo;
results.leaseDuration = (mLeaseTime != null) ? mLeaseTime : INFINITE_LEASE;
results.mtu = (mMtu != null && MIN_MTU <= mMtu && mMtu <= MAX_MTU) ? mMtu : 0;
return results;
}
use of android.net.DhcpResults in project android_frameworks_base by ResurrectionRemix.
the class DhcpPacketTest method testMultipleRouters.
@SmallTest
public void testMultipleRouters() throws Exception {
final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// Ethernet header.
"fc3d93000000" + "081735000000" + "0800" + // IP header.
"45000148c2370000ff117ac2c0a8bd02ffffffff" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
"0043004401343beb" + // BOOTP header.
"0201060027f518e20000800000000000c0a8bd310000000000000000" + // MAC address.
"fc3d9300000000000000000000000000" + // Server name.
"0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
"0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options.
"638253633501023604c0abbd023304000070803a04000038403b04000062700104ffffff00" + "0308c0a8bd01ffffff0006080808080808080404ff000000000000"));
DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2);
assertTrue(offerPacket instanceof DhcpOfferPacket);
assertEquals("FC3D93000000", HexDump.toHexString(offerPacket.getClientMac()));
DhcpResults dhcpResults = offerPacket.toDhcpResults();
assertDhcpResults("192.168.189.49/24", "192.168.189.1", "8.8.8.8,8.8.4.4", null, "192.171.189.2", null, 28800, false, 0, dhcpResults);
}
use of android.net.DhcpResults in project android_frameworks_base by crdroidandroid.
the class IpManager method handleIPv4Success.
private void handleIPv4Success(DhcpResults dhcpResults) {
mDhcpResults = new DhcpResults(dhcpResults);
final LinkProperties newLp = assembleLinkProperties();
final ProvisioningChange delta = setLinkProperties(newLp);
if (VDBG) {
Log.d(mTag, "onNewDhcpResults(" + Objects.toString(dhcpResults) + ")");
}
mCallback.onNewDhcpResults(dhcpResults);
dispatchCallback(delta, newLp);
}
use of android.net.DhcpResults in project android_frameworks_base by crdroidandroid.
the class DhcpPacket method toDhcpResults.
/**
* Construct a DhcpResults object from a DHCP reply packet.
*/
public DhcpResults toDhcpResults() {
Inet4Address ipAddress = mYourIp;
if (ipAddress.equals(Inet4Address.ANY)) {
ipAddress = mClientIp;
if (ipAddress.equals(Inet4Address.ANY)) {
return null;
}
}
int prefixLength;
if (mSubnetMask != null) {
try {
prefixLength = NetworkUtils.netmaskToPrefixLength(mSubnetMask);
} catch (IllegalArgumentException e) {
// Non-contiguous netmask.
return null;
}
} else {
prefixLength = NetworkUtils.getImplicitNetmask(ipAddress);
}
DhcpResults results = new DhcpResults();
try {
results.ipAddress = new LinkAddress(ipAddress, prefixLength);
} catch (IllegalArgumentException e) {
return null;
}
if (mGateways.size() > 0) {
results.gateway = mGateways.get(0);
}
results.dnsServers.addAll(mDnsServers);
results.domains = mDomainName;
results.serverAddress = mServerIdentifier;
results.vendorInfo = mVendorInfo;
results.leaseDuration = (mLeaseTime != null) ? mLeaseTime : INFINITE_LEASE;
results.mtu = (mMtu != null && MIN_MTU <= mMtu && mMtu <= MAX_MTU) ? mMtu : 0;
return results;
}
use of android.net.DhcpResults in project android_frameworks_base by crdroidandroid.
the class DhcpPacketTest method testOffer2.
@SmallTest
public void testOffer2() throws Exception {
final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// IP header.
"450001518d0600004011144dc0a82b01c0a82bf7" + // UDP header.
"00430044013d9ac7" + // BOOTP header.
"02010600dfc23d1f0002000000000000c0a82bf7c0a82b0100000000" + // MAC address.
"30766ff2a90c00000000000000000000" + // Server name.
"0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
"0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options
"638253633501023604c0a82b01330400000e103a04000007083b0400000c4e0104ffffff00" + "1c04c0a82bff0304c0a82b010604c0a82b012b0f414e44524f49445f4d455445524544ff"));
assertEquals(337, packet.limit());
DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
// Implicitly checks it's non-null.
assertTrue(offerPacket instanceof DhcpOfferPacket);
DhcpResults dhcpResults = offerPacket.toDhcpResults();
assertDhcpResults("192.168.43.247/24", "192.168.43.1", "192.168.43.1", null, "192.168.43.1", "ANDROID_METERED", 3600, true, 0, dhcpResults);
assertTrue(dhcpResults.hasMeteredHint());
}
Aggregations