Search in sources :

Example 46 with DhcpPacket

use of android.net.dhcp.DhcpPacket in project platform_frameworks_base by android.

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());
}
Also used : DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 47 with DhcpPacket

use of android.net.dhcp.DhcpPacket in project platform_frameworks_base by android.

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);
    }
}
Also used : DhcpPacket(android.net.dhcp.DhcpPacket)

Example 48 with DhcpPacket

use of android.net.dhcp.DhcpPacket in project android_frameworks_base by DirtyUnicorns.

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);
    }
}
Also used : DhcpPacket(android.net.dhcp.DhcpPacket)

Example 49 with DhcpPacket

use of android.net.dhcp.DhcpPacket in project android_frameworks_base by DirtyUnicorns.

the class DhcpPacketTest method checkIpAddress.

private void checkIpAddress(String expected, byte type, Inet4Address clientIp, Inet4Address yourIp, byte[] netmaskBytes) throws Exception {
    ByteBuffer packet = new TestDhcpPacket(type, clientIp, yourIp).setNetmaskBytes(netmaskBytes).build();
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
    DhcpResults results = offerPacket.toDhcpResults();
    if (expected != null) {
        LinkAddress expectedAddress = new LinkAddress(expected);
        assertEquals(expectedAddress, results.ipAddress);
    } else {
        assertNull(results);
    }
}
Also used : LinkAddress(android.net.LinkAddress) DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket)

Example 50 with DhcpPacket

use of android.net.dhcp.DhcpPacket in project android_frameworks_base by DirtyUnicorns.

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());
}
Also used : DhcpResults(android.net.DhcpResults) ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket)

Aggregations

DhcpPacket (android.net.dhcp.DhcpPacket)72 SmallTest (android.test.suitebuilder.annotation.SmallTest)52 ByteBuffer (java.nio.ByteBuffer)44 DhcpResults (android.net.DhcpResults)40 LinkAddress (android.net.LinkAddress)4