From 120b99579f43ac5b645e20c6f7802f567dd9be5e Mon Sep 17 00:00:00 2001 From: steffen Date: Sun, 18 Oct 2020 22:04:27 +0000 Subject: [PATCH] ipv6 and ipv4 can not work with one socket at the same time. --- Changelog | 2 ++ tcp.cc | 8 ++++++-- test-tcpserver.cc | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 524f3b3..0c69f7c 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,6 @@ 2020-10-18: +- needed to disable ipv6 on windows for the moment, as long as i can't + get both ipv4 and ipv6 to work at the same time. - fixed getpeername was not supported on accept connections - fixed windows support with TCP sockets. Needed to call closesocket on windows. - added support for windows. Everything should work but UNIX sockets. diff --git a/tcp.cc b/tcp.cc index c0893e1..2ab0bb9 100644 --- a/tcp.cc +++ b/tcp.cc @@ -44,10 +44,14 @@ int TCP::Listen(int port) { struct addrinfo hints, *res, *rp; if (sock > 0) Close(); - - bzero (&hints, sizeof (struct addrinfo)); +// FIXME: solution to get both (IPV4 and IPV6) to work at the same time? + bzero (&hints, sizeof (struct addrinfo)); hints.ai_flags = AI_PASSIVE; +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) + hints.ai_family = AF_INET; +#else hints.ai_family = AF_INET6; +#endif hints.ai_socktype = SOCK_STREAM; if ((err = getaddrinfo (NULL, itoa(buffer, port, 32), &hints, &res)) != 0) { return 0; diff --git a/test-tcpserver.cc b/test-tcpserver.cc index 01649c6..1eadb12 100644 --- a/test-tcpserver.cc +++ b/test-tcpserver.cc @@ -35,6 +35,7 @@ int main(int argc, char **argv) { while(1) { if (connection == NULL) { connection = tcpserver.Accept(); + printf ("accept connection? %p\n", connection); if (connection != NULL) printf (" server: got a new connection from:%s\n", connection->GetRemoteAddr().c_str()); }