diff --git a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java index e9bfb43b5e..eddb416972 100644 --- a/tests/cts/net/src/android/net/ipv6/cts/PingTest.java +++ b/tests/cts/net/src/android/net/ipv6/cts/PingTest.java @@ -53,6 +53,9 @@ public class PingTest extends AndroidTestCase { /** Maximum size of the packets we're using to test. */ private static final int MAX_SIZE = 4096; + /** Size of the ICMPv6 header. */ + private static final int ICMP_HEADER_SIZE = 8; + /** Number of packets to test. */ private static final int NUM_PACKETS = 10; @@ -65,7 +68,7 @@ public class PingTest extends AndroidTestCase { * Returns a byte array containing an ICMPv6 echo request with the specified payload length. */ private byte[] pingPacket(int payloadLength) { - byte[] packet = new byte[payloadLength + 8]; + byte[] packet = new byte[payloadLength + ICMP_HEADER_SIZE]; new Random().nextBytes(packet); System.arraycopy(PING_HEADER, 0, packet, 0, PING_HEADER.length); return packet; @@ -155,7 +158,7 @@ public class PingTest extends AndroidTestCase { assertEquals("localhost/::1", ipv6Loopback.toString()); for (int i = 0; i < NUM_PACKETS; i++) { - byte[] packet = pingPacket((int) (Math.random() * MAX_SIZE)); + byte[] packet = pingPacket((int) (Math.random() * (MAX_SIZE - ICMP_HEADER_SIZE))); FileDescriptor s = createPingSocket(); // Use both recvfrom and read(). sendPing(s, ipv6Loopback, packet);