Skip to content

Commit

Permalink
add some entropy to the message content and discard any message that …
Browse files Browse the repository at this point in the history
…we receive whose payload doesn't match what we expect
  • Loading branch information
sendaoYan committed Jun 26, 2024
1 parent 9879aab commit a7e552f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/jdk/java/nio/channels/DatagramChannel/Loopback.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)

// send datagram to multicast group
System.out.format("send %s -> %s%n", dc.getLocalAddress(), target);
ByteBuffer src = ByteBuffer.wrap("hello".getBytes("UTF-8"));
String str = "hello " + System.nanoTime();
ByteBuffer src = ByteBuffer.wrap(str.getBytes("UTF-8"));
dc.send(src, target);

// receive datagram sent to multicast group
Expand Down Expand Up @@ -158,6 +159,11 @@ static void test(ProtocolFamily family, InetAddress group, NetworkInterface ni)
} else {
sel.selectedKeys().clear();
SocketAddress sender = dc.receive(dst);
if (!src.toString().contentEquals(dst.toString())) {
System.out.println("src: " + src + "not equal to dst: " + dst);
dst.clear();
continue;
}
if (sender != null) {
System.out.format("received %s from %s%n", dst, sender);
senderPort = ((InetSocketAddress) sender).getPort();
Expand Down

0 comments on commit a7e552f

Please sign in to comment.