|
21 | 21 | import android.net.LinkAddress; |
22 | 22 | import android.system.OsConstants; |
23 | 23 | import android.test.suitebuilder.annotation.SmallTest; |
24 | | -import junit.framework.TestCase; |
| 24 | +import com.android.internal.util.HexDump; |
25 | 25 |
|
26 | 26 | import java.net.Inet4Address; |
27 | 27 | import java.nio.ByteBuffer; |
28 | 28 | import java.util.ArrayList; |
29 | 29 |
|
| 30 | +import junit.framework.TestCase; |
30 | 31 | import libcore.util.HexEncoding; |
31 | 32 |
|
32 | 33 | import static android.net.dhcp.DhcpPacket.*; |
@@ -370,4 +371,69 @@ public void testPadAndOverloadedOptionsOffer() throws Exception { |
370 | 371 | assertDhcpResults("172.17.152.118/16", "172.17.1.1", "172.17.1.1", |
371 | 372 | null, "1.1.1.1", null, 43200, false, dhcpResults); |
372 | 373 | } |
| 374 | + |
| 375 | + @SmallTest |
| 376 | + public void testBug2111() throws Exception { |
| 377 | + final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode(( |
| 378 | + // IP header. |
| 379 | + "4500014c00000000ff119beac3eaf3880a3f5d04" + |
| 380 | + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation). |
| 381 | + "0043004401387464" + |
| 382 | + // BOOTP header. |
| 383 | + "0201060002554812000a0000000000000a3f5d040000000000000000" + |
| 384 | + // MAC address. |
| 385 | + "00904c00000000000000000000000000" + |
| 386 | + // Server name. |
| 387 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 388 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 389 | + // File. |
| 390 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 391 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 392 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 393 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 394 | + // Options. |
| 395 | + "638253633501023604c00002fe33040000bfc60104fffff00003040a3f50010608c0000201c0000202" + |
| 396 | + "0f0f646f6d61696e3132332e636f2e756b0000000000ff00000000" |
| 397 | + ).toCharArray(), false)); |
| 398 | + |
| 399 | + DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L3); |
| 400 | + assertTrue(offerPacket instanceof DhcpOfferPacket); |
| 401 | + DhcpResults dhcpResults = offerPacket.toDhcpResults(); |
| 402 | + assertDhcpResults("10.63.93.4/20", "10.63.80.1", "192.0.2.1,192.0.2.2", |
| 403 | + "domain123.co.uk", "192.0.2.254", null, 49094, false, dhcpResults); |
| 404 | + } |
| 405 | + |
| 406 | + @SmallTest |
| 407 | + public void testBug2136() throws Exception { |
| 408 | + final ByteBuffer packet = ByteBuffer.wrap(HexEncoding.decode(( |
| 409 | + // Ethernet header. |
| 410 | + "bcf5ac000000d0c7890000000800" + |
| 411 | + // IP header. |
| 412 | + "4500014c00000000ff119beac3eaf3880a3f5d04" + |
| 413 | + // UDP header. TODO: fix invalid checksum (due to MAC address obfuscation). |
| 414 | + "0043004401387574" + |
| 415 | + // BOOTP header. |
| 416 | + "0201060163339a3000050000000000000a209ecd0000000000000000" + |
| 417 | + // MAC address. |
| 418 | + "bcf5ac00000000000000000000000000" + |
| 419 | + // Server name. |
| 420 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 421 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 422 | + // File. |
| 423 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 424 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 425 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 426 | + "0000000000000000000000000000000000000000000000000000000000000000" + |
| 427 | + // Options. |
| 428 | + "6382536335010236040a20ff80330400001c200104fffff00003040a20900106089458413494584135" + |
| 429 | + "0f0b6c616e63732e61632e756b000000000000000000ff00000000" |
| 430 | + ).toCharArray(), false)); |
| 431 | + |
| 432 | + DhcpPacket offerPacket = DhcpPacket.decodeFullPacket(packet, ENCAP_L2); |
| 433 | + assertTrue(offerPacket instanceof DhcpOfferPacket); |
| 434 | + assertEquals("BCF5AC000000", HexDump.toHexString(offerPacket.getClientMac())); |
| 435 | + DhcpResults dhcpResults = offerPacket.toDhcpResults(); |
| 436 | + assertDhcpResults("10.32.158.205/20", "10.32.144.1", "148.88.65.52,148.88.65.53", |
| 437 | + "lancs.ac.uk", "10.32.255.128", null, 7200, false, dhcpResults); |
| 438 | + } |
373 | 439 | } |
0 commit comments