Search in sources :

Example 41 with DhcpPacket

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

the class DhcpPacketTest method testUdpServerAnySourcePort.

@SmallTest
public void testUdpServerAnySourcePort() throws Exception {
    final ByteBuffer packet = ByteBuffer.wrap(HexDump.hexStringToByteArray(// Ethernet header.
    "9cd917000000001c2e0000000800" + // IP header.
    "45a00148000040003d115087d18194fb0a0f7af2" + // NOTE: The server source port is not the canonical port 67.
    "C29F004401341268" + // BOOTP header.
    "02010600d628ba8200000000000000000a0f7af2000000000a0fc818" + // MAC address.
    "9cd91700000000000000000000000000" + // Server name.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // File.
    "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + // Options.
    "6382536335010236040a0169fc3304000151800104ffff000003040a0fc817060cd1818003d1819403" + "d18180060f0777766d2e6564751c040a0fffffff000000"));
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2);
    assertTrue(offerPacket instanceof DhcpOfferPacket);
    assertEquals("9CD917000000", HexDump.toHexString(offerPacket.getClientMac()));
    DhcpResults dhcpResults = offerPacket.toDhcpResults();
    assertDhcpResults("10.15.122.242/16", "10.15.200.23", "209.129.128.3,209.129.148.3,209.129.128.6", "wvm.edu", "10.1.105.252", null, 86400, 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 42 with DhcpPacket

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

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

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

the class DhcpPacketTest method assertDomainAndVendorInfoParses.

private void assertDomainAndVendorInfoParses(String expectedDomain, byte[] domainBytes, String expectedVendorInfo, byte[] vendorInfoBytes) throws Exception {
    ByteBuffer packet = new TestDhcpPacket(DHCP_MESSAGE_TYPE_OFFER).setDomainBytes(domainBytes).setVendorInfoBytes(vendorInfoBytes).build();
    DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_BOOTP);
    assertEquals(expectedDomain, offerPacket.mDomainName);
    assertEquals(expectedVendorInfo, offerPacket.mVendorInfo);
}
Also used : ByteBuffer(java.nio.ByteBuffer) DhcpPacket(android.net.dhcp.DhcpPacket)

Example 44 with DhcpPacket

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

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.DHCP_NO_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 45 with DhcpPacket

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

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)

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