Skip to content

Commit

Permalink
test: Fix newServerSocketBindon for JavaAddressSpecifics
Browse files Browse the repository at this point in the history
Previously, these calls would erroneously not accept loopback addresses.
  • Loading branch information
kohlschuetter committed Feb 12, 2024
1 parent 416077c commit 4e5c3b2
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public CloseablePair<? extends DatagramChannel> 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());
Expand All @@ -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());
Expand Down

0 comments on commit 4e5c3b2

Please sign in to comment.