make quasselcore listen on IPv6 if available
authorDaniel Albers <daniel@lbers.com>
Tue, 17 Aug 2010 20:03:30 +0000 (22:03 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 25 Aug 2010 08:30:00 +0000 (10:30 +0200)
On most TCP/IP stacks creating a IPv6 listen socket will also allow IPv4
connectivity via IPv4-Mapped IPv6 Addresses. Notable exceptions are
NetBSD and OpenBSD.
Due to these exceptions a successful IPv6 bind() doesn't guarantee IPv4
connectivity, so we still have to try both.
The former implementation did this too, just in the wrong order.

src/common/main.cpp
src/core/core.cpp

index d0e0840..9823f85 100644 (file)
@@ -101,7 +101,7 @@ int main(int argc, char **argv) {
 #endif
 #ifndef BUILD_QTUI
   // put core-only arguments here
 #endif
 #ifndef BUILD_QTUI
   // put core-only arguments here
-  cliParser->addOption("listen <address>[,<address[,...]]>", 0, "The address(es) quasselcore will listen on", "0.0.0.0,::");
+  cliParser->addOption("listen <address>[,<address[,...]]>", 0, "The address(es) quasselcore will listen on", "::,0.0.0.0");
   cliParser->addOption("port <port>",'p', "The port quasselcore will listen at", QString("4242"));
   cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
   cliParser->addOption("logfile <path>", 'l', "Path to logfile");
   cliParser->addOption("port <port>",'p', "The port quasselcore will listen at", QString("4242"));
   cliParser->addSwitch("norestore", 'n', "Don't restore last core's state");
   cliParser->addOption("logfile <path>", 'l', "Path to logfile");
index 378e3a4..03a7f81 100644 (file)
@@ -396,40 +396,39 @@ bool Core::startListening() {
         );
       } else {
         switch(addr.protocol()) {
         );
       } else {
         switch(addr.protocol()) {
-          case QAbstractSocket::IPv4Protocol:
-            if(_server.listen(addr, port)) {
+          case QAbstractSocket::IPv6Protocol:
+            if(_v6server.listen(addr, port)) {
               quInfo() << qPrintable(
               quInfo() << qPrintable(
-                tr("Listening for GUI clients on IPv4 %1 port %2 using protocol version %3")
+                tr("Listening for GUI clients on IPv6 %1 port %2 using protocol version %3")
                   .arg(addr.toString())
                   .arg(addr.toString())
-                  .arg(_server.serverPort())
+                  .arg(_v6server.serverPort())
                   .arg(Quassel::buildInfo().protocolVersion)
               );
               success = true;
             } else
               quWarning() << qPrintable(
                   .arg(Quassel::buildInfo().protocolVersion)
               );
               success = true;
             } else
               quWarning() << qPrintable(
-                tr("Could not open IPv4 interface %1:%2: %3")
+                tr("Could not open IPv6 interface %1:%2: %3")
                   .arg(addr.toString())
                   .arg(port)
                   .arg(addr.toString())
                   .arg(port)
-                  .arg(_server.errorString()));
+                  .arg(_v6server.errorString()));
             break;
             break;
-          case QAbstractSocket::IPv6Protocol:
-            if(_v6server.listen(addr, port)) {
+          case QAbstractSocket::IPv4Protocol:
+            if(_server.listen(addr, port)) {
               quInfo() << qPrintable(
               quInfo() << qPrintable(
-                tr("Listening for GUI clients on IPv6 %1 port %2 using protocol version %3")
+                tr("Listening for GUI clients on IPv4 %1 port %2 using protocol version %3")
                   .arg(addr.toString())
                   .arg(addr.toString())
-                  .arg(_v6server.serverPort())
+                  .arg(_server.serverPort())
                   .arg(Quassel::buildInfo().protocolVersion)
               );
               success = true;
             } else {
                   .arg(Quassel::buildInfo().protocolVersion)
               );
               success = true;
             } else {
-              // if v4 succeeded on Any, the port will be already in use - don't display the error then
-              // FIXME: handle this more sanely, make sure we can listen to both v4 and v6 by default!
-              if(!success || _v6server.serverError() != QAbstractSocket::AddressInUseError)
+              // if v6 succeeded on Any, the port will be already in use - don't display the error then
+              if(!success || _server.serverError() != QAbstractSocket::AddressInUseError)
                 quWarning() << qPrintable(
                 quWarning() << qPrintable(
-                  tr("Could not open IPv6 interface %1:%2: %3")
+                  tr("Could not open IPv4 interface %1:%2: %3")
                   .arg(addr.toString())
                   .arg(port)
                   .arg(addr.toString())
                   .arg(port)
-                  .arg(_v6server.errorString()));
+                  .arg(_server.errorString()));
             }
             break;
           default:
             }
             break;
           default: