Search in sources :

Example 56 with DhcpPacket

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

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

Example 57 with DhcpPacket

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

the class DhcpPacketTest method testBug2111.

@SmallTest
public void testBug2111() throws Exception {
    final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// IP header.
    "4500014c00000000ff119beac3eaf3880a3f5d04" + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation).
    "0043004401387464" + // BOOTP header.
    "0201060002554812000a0000000000000a3f5d040000000000000000" + // MAC address.
    "00904c00000000000000000000000000" + // Server name.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options.
    "638253633501023604c00002fe33040000bfc60104fffff00003040a3f50010608c0000201c0000202" + "0f0f646f6d61696e3132332e636f2e756b0000000000ff00000000"));
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    assertTrue(offerPacket instanceof DhcpOfferPacket);
    DhcpResults dhcpResults = offerPacket.toDhcpResults();
    assertDhcpResults("10.63.93.4/20", "10.63.80.1", "192.0.2.1,192.0.2.2", "domain123.co.uk", "192.0.2.254", null, 49094, 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 58 with DhcpPacket

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

the class DhcpPacketTest method testOfferWithBadCookie.

@SmallTest
public void testOfferWithBadCookie() 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" + // Bad cookie
    "DEADBEEF3501023604c0a82b01330400000e103a04000007083b0400000c4e0104ffffff00" + "1c04c0a82bff0304c0a82b010604c0a82b012b0f414e44524f49445f4d455445524544ff");
    try {
        DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, packet.length, ENCAP_L3);
    } catch (DhcpPacket.ParseException expected) {
        assertDhcpErrorCodes(DhcpErrorEvent.DHCP_BAD_MAGIC_COOKIE, expected.errorCode);
        return;
    }
    fail("Dhcp packet parsing should have failed");
}
Also used : DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 59 with DhcpPacket

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

the class DhcpPacketTest method testBadHwaddrLength.

@SmallTest
public void testBadHwaddrLength() 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"));
    String expectedClientMac = "30766FF2A90C";
    final int hwAddrLenOffset = 20 + 8 + 2;
    assertEquals(6, packet.get(hwAddrLenOffset));
    // Expect the expected.
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    assertNotNull(offerPacket);
    assertEquals(6, offerPacket.getClientMac().length);
    assertEquals(expectedClientMac, HexDump.toHexString(offerPacket.getClientMac()));
    // Reduce the hardware address length and verify that it shortens the client MAC.
    packet.flip();
    packet.put(hwAddrLenOffset, (byte) 5);
    offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    assertNotNull(offerPacket);
    assertEquals(5, offerPacket.getClientMac().length);
    assertEquals(expectedClientMac.substring(0, 10), HexDump.toHexString(offerPacket.getClientMac()));
    packet.flip();
    packet.put(hwAddrLenOffset, (byte) 3);
    offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    assertNotNull(offerPacket);
    assertEquals(3, offerPacket.getClientMac().length);
    assertEquals(expectedClientMac.substring(0, 6), HexDump.toHexString(offerPacket.getClientMac()));
    // Set the the hardware address length to 0xff and verify that we a) don't treat it as -1
    // and crash, and b) hardcode it to 6.
    packet.flip();
    packet.put(hwAddrLenOffset, (byte) -1);
    offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    assertNotNull(offerPacket);
    assertEquals(6, offerPacket.getClientMac().length);
    assertEquals(expectedClientMac, HexDump.toHexString(offerPacket.getClientMac()));
    // Set the the hardware address length to a positive invalid value (> 16) and verify that we
    // hardcode it to 6.
    packet.flip();
    packet.put(hwAddrLenOffset, (byte) 17);
    offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3);
    assertNotNull(offerPacket);
    assertEquals(6, offerPacket.getClientMac().length);
    assertEquals(expectedClientMac, HexDump.toHexString(offerPacket.getClientMac()));
}
Also used : ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 60 with DhcpPacket

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

the class DhcpPacketTest method testBadTruncatedOffer.

@SmallTest
public void testBadTruncatedOffer() throws Exception {
    final byte[] packet = HexDump.hexStringToByteArray(// IP header.
    "450001518d0600004011144dc0a82b01c0a82bf7" + // UDP header.
    "00430044013d9ac7" + // BOOTP header.
    "02010600dfc23d1f0002000000000000c0a82bf7c0a82b0100000000" + // MAC address.
    "30766ff2a90c00000000000000000000" + // Server name.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File, missing one byte
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000");
    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)

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