Search in sources :

Example 61 with DhcpPacket

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

Example 62 with DhcpPacket

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

the class DhcpPacketTest method testBadOfferWithoutACookie.

@SmallTest
public void testBadOfferWithoutACookie() throws Exception {
    final byte[] packet = HexDump.hexStringToByteArray(// IP header.
    "450001518d0600004011144dc0a82b01c0a82bf7" + // UDP header.
    "00430044013d9ac7" + // BOOTP header.
    "02010600dfc23d1f0002000000000000c0a82bf7c0a82b0100000000" + // MAC address.
    "30766ff2a90c00000000000000000000" + // Server name.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000");
    try {
        DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, packet.length, ENCAP_L3);
    } catch (DhcpPacket.ParseException expected) {
        assertDhcpErrorCodes(DhcpErrorEvent.PARSING_ERROR, expected.errorCode);
        return;
    }
    fail("Dhcp packet parsing should have failed");
}
Also used : DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 63 with DhcpPacket

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

the class DhcpPacketTest method testBadIpPacket.

@SmallTest
public void testBadIpPacket() throws Exception {
    final byte[] packet = HexDump.hexStringToByteArray(// IP header.
    "450001518d0600004011144dc0a82b01c0a82bf7");
    try {
        DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, packet.length, ENCAP_L3);
    } catch (DhcpPacket.ParseException expected) {
        assertDhcpErrorCodes(DhcpErrorEvent.L3_TOO_SHORT, expected.errorCode);
        return;
    }
    fail("Dhcp packet parsing should have failed");
}
Also used : DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 64 with DhcpPacket

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

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 65 with DhcpPacket

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

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