From 4530de7a3c1f9897dc875d43a77fd192e7d58de5 Mon Sep 17 00:00:00 2001 From: David Smith Date: Fri, 31 Jan 2025 15:55:53 +0100 Subject: [PATCH] TESTS: Avoid requiring ipv6 in some of the standard tests --- tests/XrdCl/XrdClSocket.cc | 2 +- tests/common/Server.cc | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/XrdCl/XrdClSocket.cc b/tests/XrdCl/XrdClSocket.cc index b1009c8f6f3..9f077d38fc2 100644 --- a/tests/XrdCl/XrdClSocket.cc +++ b/tests/XrdCl/XrdClSocket.cc @@ -230,7 +230,7 @@ TEST(SocketTest, TransferTest) EXPECT_TRUE( serv.Start() ); EXPECT_EQ( sock.GetStatus(), Socket::Disconnected ); - EXPECT_XRDST_OK( sock.Initialize( AF_INET6 ) ); + EXPECT_XRDST_OK( sock.Initialize( AF_INET ) ); EXPECT_XRDST_OK( sock.Connect( "localhost", port ) ); EXPECT_EQ( sock.GetStatus(), Socket::Connected ); diff --git a/tests/common/Server.cc b/tests/common/Server.cc index 6f9e7cd7304..280619af4a3 100644 --- a/tests/common/Server.cc +++ b/tests/common/Server.cc @@ -147,8 +147,17 @@ bool Server::Setup( int port, int accept, ClientHandlerFactory *factory ) pListenSocket = socket( protocolFamily, SOCK_STREAM, 0 ); if( pListenSocket < 0 ) { - log->Error( 1, "Unable to create listening socket: %s", strerror( errno ) ); - return false; + if ( errno == EAFNOSUPPORT && pProtocolFamily == Both ) + { + protocolFamily = AF_INET; + pProtocolFamily = Inet4; + pListenSocket = socket( protocolFamily, SOCK_STREAM, 0 ); + } + if ( pListenSocket < 0 ) + { + log->Error( 1, "Unable to create listening socket: %s", strerror( errno ) ); + return false; + } } int optVal = 1; @@ -159,9 +168,9 @@ bool Server::Setup( int port, int accept, ClientHandlerFactory *factory ) return false; } - if( pProtocolFamily == Both ) + if( protocolFamily == AF_INET6 ) { - optVal = 0; + optVal = (pProtocolFamily == Both) ? 0 : 1; if( setsockopt( pListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, &optVal, sizeof(optVal) ) == -1 ) {