Search in sources :

Example 36 with DhcpPacket

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

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

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

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

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

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

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

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

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

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)

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