use of android.net.dhcp.DhcpPacket in project android_frameworks_base by ResurrectionRemix.
the class DhcpPacketTest method checkMtu.
private void checkMtu(ByteBuffer packet, int expectedMtu, byte[] mtuBytes) throws Exception {
if (mtuBytes != null) {
packet.position(packet.capacity() - mtuBytes.length);
packet.put(mtuBytes);
packet.clear();
}
DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
// Implicitly checks it's non-null.
assertTrue(offerPacket instanceof DhcpOfferPacket);
DhcpResults dhcpResults = offerPacket.toDhcpResults();
assertDhcpResults("192.168.159.247/20", "192.168.159.254", "8.8.8.8,8.8.4.4", null, "192.168.144.3", null, 7200, false, expectedMtu, dhcpResults);
}
use of android.net.dhcp.DhcpPacket in project android_frameworks_base by ResurrectionRemix.
the class DhcpPacketTest method assertLeaseTimeParses.
private void assertLeaseTimeParses(boolean expectValid, Integer rawLeaseTime, long leaseTimeMillis, byte[] leaseTimeBytes) throws Exception {
TestDhcpPacket testPacket = new TestDhcpPacket(DHCP_MESSAGE_TYPE_OFFER);
if (leaseTimeBytes != null) {
testPacket.setLeaseTimeBytes(leaseTimeBytes);
}
ByteBuffer packet = testPacket.build();
DhcpPacket offerPacket = null;
if (!expectValid) {
try {
offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
fail("Invalid packet parsed successfully: " + offerPacket);
} catch (ParseException expected) {
}
return;
}
offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
assertNotNull(offerPacket);
assertEquals(rawLeaseTime, offerPacket.mLeaseTime);
// Just check this doesn't crash.
DhcpResults dhcpResults = offerPacket.toDhcpResults();
assertEquals(leaseTimeMillis, offerPacket.getLeaseTimeMillis());
}
use of android.net.dhcp.DhcpPacket in project android_frameworks_base by crdroidandroid.
the class ConnectivityPacketSummary method parseDHCPv4.
private void parseDHCPv4(StringJoiner sj) {
final DhcpPacket dhcpPacket;
try {
dhcpPacket = DhcpPacket.decodeFullPacket(mBytes, mLength, DhcpPacket.ENCAP_L2);
sj.add(dhcpPacket.toString());
} catch (DhcpPacket.ParseException e) {
sj.add("parse error: " + e);
}
}
use of android.net.dhcp.DhcpPacket in project android_frameworks_base by crdroidandroid.
the class DhcpPacketTest method assertLeaseTimeParses.
private void assertLeaseTimeParses(boolean expectValid, Integer rawLeaseTime, long leaseTimeMillis, byte[] leaseTimeBytes) throws Exception {
TestDhcpPacket testPacket = new TestDhcpPacket(DHCP_MESSAGE_TYPE_OFFER);
if (leaseTimeBytes != null) {
testPacket.setLeaseTimeBytes(leaseTimeBytes);
}
ByteBuffer packet = testPacket.build();
DhcpPacket offerPacket = null;
if (!expectValid) {
try {
offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
fail("Invalid packet parsed successfully: " + offerPacket);
} catch (ParseException expected) {
}
return;
}
offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
assertNotNull(offerPacket);
assertEquals(rawLeaseTime, offerPacket.mLeaseTime);
// Just check this doesn't crash.
DhcpResults dhcpResults = offerPacket.toDhcpResults();
assertEquals(leaseTimeMillis, offerPacket.getLeaseTimeMillis());
}
use of android.net.dhcp.DhcpPacket in project android_frameworks_base by crdroidandroid.
the class DhcpPacketTest method testBug2136.
@SmallTest
public void testBug2136() throws Exception {
final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// Ethernet header.
"bcf5ac000000d0c7890000000800" + // IP header.
"4500014c00000000ff119beac3eaf3880a3f5d04" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
"0043004401387574" + // BOOTP header.
"0201060163339a3000050000000000000a209ecd0000000000000000" + // MAC address.
"bcf5ac00000000000000000000000000" + // Server name.
"0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
"0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options.
"6382536335010236040a20ff80330400001c200104fffff00003040a20900106089458413494584135" + "0f0b6c616e63732e61632e756b000000000000000000ff00000000"));
DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2);
assertTrue(offerPacket instanceof DhcpOfferPacket);
assertEquals("BCF5AC000000", HexDump.toHexString(offerPacket.getClientMac()));
DhcpResults dhcpResults = offerPacket.toDhcpResults();
assertDhcpResults("10.32.158.205/20", "10.32.144.1", "148.88.65.52,148.88.65.53", "lancs.ac.uk", "10.32.255.128", null, 7200, false, 0, dhcpResults);
}
Aggregations