aboutsummaryrefslogtreecommitdiff
path: root/src/test.cpp
diff options
context:
space:
mode:
authorproller <proller@github.com>2013-06-23 11:31:22 +0400
committerproller <proller@github.com>2013-06-23 11:31:22 +0400
commitf960c3be313c761fe02f9167dc1fe3fca5dc4ada (patch)
tree54543a7e61e6ed273840d9bcba6bc9655add5243 /src/test.cpp
parent309c5f3641dccaf1260953f098ccd593396dee64 (diff)
downloadminetest-f960c3be313c761fe02f9167dc1fe3fca5dc4ada.tar.gz
minetest-f960c3be313c761fe02f9167dc1fe3fca5dc4ada.tar.bz2
minetest-f960c3be313c761fe02f9167dc1fe3fca5dc4ada.zip
Add support for IPv6
Two new configuration options are added: - "enable_ipv6" to enable/disable the overall use of IPv6 - "ipv6_server" to enable/disable the use of IPv6 sockets when running a server (when "enable_ipv6" is enabled)
Diffstat (limited to 'src/test.cpp')
-rw-r--r--src/test.cpp66
1 files changed, 48 insertions, 18 deletions
diff --git a/src/test.cpp b/src/test.cpp
index 5267b2768..b66f65daf 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -1293,26 +1293,56 @@ struct TestSocket: public TestBase
void Run()
{
const int port = 30003;
- UDPSocket socket;
- socket.Bind(port);
- const char sendbuffer[] = "hello world!";
- socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
+ // IPv6 socket test
+ {
+ UDPSocket socket6(true);
+ socket6.Bind(port);
- sleep_ms(50);
+ const char sendbuffer[] = "hello world!";
+ IPv6AddressBytes bytes;
+ bytes.bytes[15] = 1;
+ socket6.Send(Address(&bytes, port), sendbuffer, sizeof(sendbuffer));
+
+ sleep_ms(50);
+
+ char rcvbuffer[256];
+ memset(rcvbuffer, 0, sizeof(rcvbuffer));
+ Address sender;
+ for(;;)
+ {
+ int bytes_read = socket6.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
+ if(bytes_read < 0)
+ break;
+ }
+ //FIXME: This fails on some systems
+ UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
+ UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr, Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0);
+ }
- char rcvbuffer[256];
- memset(rcvbuffer, 0, sizeof(rcvbuffer));
- Address sender;
- for(;;)
+ // IPv4 socket test
{
- int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
- if(bytes_read < 0)
- break;
+ UDPSocket socket(false);
+ socket.Bind(port);
+
+ const char sendbuffer[] = "hello world!";
+ socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
+
+ sleep_ms(50);
+
+ char rcvbuffer[256];
+ memset(rcvbuffer, 0, sizeof(rcvbuffer));
+ Address sender;
+ for(;;)
+ {
+ int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
+ if(bytes_read < 0)
+ break;
+ }
+ //FIXME: This fails on some systems
+ UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
+ UASSERT(sender.getAddress().sin_addr.s_addr == Address(127,0,0,1, 0).getAddress().sin_addr.s_addr);
}
- //FIXME: This fails on some systems
- UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
- UASSERT(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
}
};
@@ -1412,12 +1442,12 @@ struct TestConnection: public TestBase
Handler hand_client("client");
infostream<<"** Creating server Connection"<<std::endl;
- con::Connection server(proto_id, 512, 5.0, &hand_server);
+ con::Connection server(proto_id, 512, 5.0, false, &hand_server);
server.Serve(30001);
infostream<<"** Creating client Connection"<<std::endl;
- con::Connection client(proto_id, 512, 5.0, &hand_client);
-
+ con::Connection client(proto_id, 512, 5.0, false, &hand_client);
+
UASSERT(hand_server.count == 0);
UASSERT(hand_client.count == 0);