Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-108515

QTcpServer, addresses and IPv6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.7, 6.4.1
    • Network: Sockets
    • None
    • Windows 11
    • Windows

    Description

      Return value QHostAddress of QTcpSocket::localAddress() and QTcpSocket::peerAddress() is incorrect using with QTcpServer. No matter inside overrided incomingConnection() or in the newConnection() signal. There is the issue QTBUG-47348. In that incident, the author did not manage to explain to the developers what exactly the problem was.

      QTcpSocket::localAddress() and QTcpSocket::peerAddress() allways return protocol() == QAbstractSocket::IPv6Protocol. In conjunction with QTcpServer only. When QTcpSocket is used as a client, everything is fine.

      It's very easy to reproduce this problem using standat Qt examples fortuneclient and fortuneserver.

       

      For Server:

      Add 

          qDebug() << clientConnection->localAddress().toString();
          qDebug() << clientConnection->localAddress().protocol();
          qDebug() << clientConnection->peerAddress().toString();    
          qDebug() << clientConnection->peerAddress().protocol();

      after

      QTcpSocket *clientConnection = tcpServer->nextPendingConnection();

      inside 

      void Server::sendFortune()

       

      For Client:

      Add 

      qDebug() << tcpSocket->localAddress().toString(); 
      qDebug() << tcpSocket->localAddress().protocol(); 
      qDebug() << tcpSocket->peerAddress().toString(); 
      qDebug() << tcpSocket->peerAddress().protocol();

      in the very beginning of

      void Client::readFortune()

       

      Start this examples and look at results. 

      For address 127.0.0.1

      Client output:

      "127.0.0.1"
      QAbstractSocket::IPv4Protocol
      "127.0.0.1"
      QAbstractSocket::IPv4Protocol

       

      Server output:

      "::ffff:127.0.0.1"
      QAbstractSocket::IPv6Protocol
      "::ffff:127.0.0.1"
      QAbstractSocket::IPv6Protocol

       

      For address 192.168.2.1

      Client output:

      "192.168.2.1"
      QAbstractSocket::IPv4Protocol
      "192.168.2.1"
      QAbstractSocket::IPv4Protocol

      Server output:

      "::ffff:192.168.2.1"
      QAbstractSocket::IPv6Protocol
      "::ffff:192.168.2.1"
      QAbstractSocket::IPv6Protocol

      And so on and so on.

      There is no way to determine the correct protocol version and clear IP-address on the server side. Arguments about the fact that this is how it was intended (not a bug but a feature) do not stand up to criticism, because everything works correctly on the client side.

       

      Probably, the core of the problem in QTcpSocket::setSocketDescriptor().
       

      Attachments

        Activity

          People

            manordheim Mårten Nordheim
            alex_161 Alexei Ter-Osipov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: