From 4e5c3b2870e84869cdfcca861499649a7a19b0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Mon, 12 Feb 2024 20:26:40 +0100 Subject: [PATCH] test: Fix newServerSocketBindon for JavaAddressSpecifics Previously, these calls would erroneously not accept loopback addresses. --- .../org/newsclub/net/unix/java/JavaAddressSpecifics.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/junixsocket-common/src/test/java/org/newsclub/net/unix/java/JavaAddressSpecifics.java b/junixsocket-common/src/test/java/org/newsclub/net/unix/java/JavaAddressSpecifics.java index c3c0efa9d..2e9dd92c9 100644 --- a/junixsocket-common/src/test/java/org/newsclub/net/unix/java/JavaAddressSpecifics.java +++ b/junixsocket-common/src/test/java/org/newsclub/net/unix/java/JavaAddressSpecifics.java @@ -116,7 +116,8 @@ public CloseablePair newDatagramSocketPair() throws I @Override public ServerSocket newServerSocketBindOn(SocketAddress addr) throws IOException { InetSocketAddress inetAddr = (InetSocketAddress) addr; - if (!inetAddr.getAddress().isAnyLocalAddress()) { + InetAddress address = inetAddr.getAddress(); + if (!address.isAnyLocalAddress() && !address.isLoopbackAddress()) { throw new IllegalArgumentException("Not a local address: " + inetAddr); } return new ServerSocket(inetAddr.getPort()); @@ -132,7 +133,8 @@ public Socket connectTo(SocketAddress addr) throws IOException { public ServerSocket newServerSocketBindOn(SocketAddress addr, boolean deleteOnClose) throws IOException { InetSocketAddress inetAddr = (InetSocketAddress) addr; - if (!inetAddr.getAddress().isAnyLocalAddress()) { + InetAddress address = inetAddr.getAddress(); + if (!address.isAnyLocalAddress() && !address.isLoopbackAddress()) { throw new IllegalArgumentException("Not a local address: " + inetAddr); } return new ServerSocket(inetAddr.getPort());