Qt
  1. Qt
  2. QTBUG-25634

CLONE - QUdpSocket::writeDatagram, results in a NetworkError. when using link-local addressing (e.g. ff02::1) on Mac OS X

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: P2: Important P2: Important
    • Resolution: Done
    • Affects Version/s: 4.6.1, 4.7.4, 4.8.1
    • Fix Version/s: 4.8.x, 5.0.0
    • Component/s: Network
    • Labels:
      None
    • Environment:

      Macbook Pro 15 inch - version 5.4
      Mac OSX - Snow Leopard
      Mac OS X - 10.7.3

      Description

      QUdpSocket::writeDiagram, results in a NetworkError when using IPv6 link-local addressing (e.g. ff02::1) on Mac OS X.
      The specified scope id is definitely correct, and the source code works fine under Windows.
      And it only occurs when no dynamically allocated IPv6 address is set to the interface.

      Testcase:

      QByteArray datagram = "Broadcast message";

      QUdpSocket socket (this);

      QHostAddress addr ("ff02::1");
      addr.setScopeId ("4"); // Scope id 4 is en0 under this system

      if (socket.writeDatagram (datagram, addr, 4545) < 0)
      {
      qDebug () << "Errno: " << socket.error();
      qDebug () << "Errmgs: " << socket.errorString();
      }

      output:

      Errno: QAbstractSocket::NetworkError
      Errmgs: "Unable to send a message"

        Issue Links

          Activity

          Hide
          Jean-Yves Avenard added a comment -

          Re-opening this issue as I'm seeing the exact same behaviour on Mac OS Lion.
          IPv6 Link-Local address are basically unusable with Qt on a mac.
          This have a serious impact on application using ZeroConf or Bonjour as the link-local address are usually the addresses mostly used.

          main.cpp
          #include <QUdpSocket>
          #include <QtDebug>
          
          class Connect : public QObject
          {
              Q_OBJECT
          public:
              Connect()
              {
                      // linux box
          //        m_dest = QHostAddress("FE80::2F4:B9FF:FE65:52DF%eth0");
                      // mac box
                  m_dest = QHostAddress("FE80::2F4:B9FF:FE65:52DF%en0");
                  // non link-local
          //        m_dest = QHostAddress("fd87:41a7:4138::10:11");
          
                  m_sock = new QUdpSocket(this);
                  m_port = 6000;
                  m_sock->bind(QHostAddress::AnyIPv6, m_port);
              };
              ~Connect()
              {
                  delete m_sock;
              };
              void send(QByteArray data)
              {
                  qDebug() << "scope id = " << m_dest.scopeId();
                  qint64 ret = m_sock->writeDatagram(data, m_dest, m_port);
                  if (ret != data.size())
                  {
                      qDebug() << "oops ret " << ret << " error:" << m_sock->error();
                  }
                  else
                  {
                      qDebug() << "success";
                  }
              };
          
          private:
              QUdpSocket   *m_sock;
              QHostAddress  m_dest;
              quint16       m_port;   
          };
          
          int main(int argc, char **arg)
          {
              Connect test;
              test.send("test data");
              return 0;
          }
          
          #include "main.moc"
          
          
          main.pro
          SOURCES = main.cpp
          TARGET = testqt
          CONFIG-=app_bundle
          QT += network
          

          On a mac, when using the IPv6 link-local address
          writeDatagram always return -1 with error = QAbstractSocket::NetworkError.

          Note that using the non-link-local address there's no error

          On Linux or FreeBSD: everything works too with either addresses.

          Show
          Jean-Yves Avenard added a comment - Re-opening this issue as I'm seeing the exact same behaviour on Mac OS Lion. IPv6 Link-Local address are basically unusable with Qt on a mac. This have a serious impact on application using ZeroConf or Bonjour as the link-local address are usually the addresses mostly used. main.cpp #include <QUdpSocket> #include <QtDebug> class Connect : public QObject { Q_OBJECT public : Connect() { // linux box // m_dest = QHostAddress( "FE80::2F4:B9FF:FE65:52DF%eth0" ); // mac box m_dest = QHostAddress( "FE80::2F4:B9FF:FE65:52DF%en0" ); // non link-local // m_dest = QHostAddress( "fd87:41a7:4138::10:11" ); m_sock = new QUdpSocket( this ); m_port = 6000; m_sock->bind(QHostAddress::AnyIPv6, m_port); }; ~Connect() { delete m_sock; }; void send(QByteArray data) { qDebug() << "scope id = " << m_dest.scopeId(); qint64 ret = m_sock->writeDatagram(data, m_dest, m_port); if (ret != data.size()) { qDebug() << "oops ret " << ret << " error:" << m_sock->error(); } else { qDebug() << "success" ; } }; private : QUdpSocket *m_sock; QHostAddress m_dest; quint16 m_port; }; int main( int argc, char **arg) { Connect test; test.send( "test data" ); return 0; } #include "main.moc" main.pro SOURCES = main.cpp TARGET = testqt CONFIG-=app_bundle QT += network On a mac, when using the IPv6 link-local address writeDatagram always return -1 with error = QAbstractSocket::NetworkError. Note that using the non-link-local address there's no error On Linux or FreeBSD: everything works too with either addresses.
          Hide
          Jean-Yves Avenard added a comment -

          The issue I cloned was QTBUG-8710 .. for some reasons it gave an error about not being to link to the previous issue

          Show
          Jean-Yves Avenard added a comment - The issue I cloned was QTBUG-8710 .. for some reasons it gave an error about not being to link to the previous issue
          Hide
          Shane Kearns added a comment -

          https://codereview.qt-project.org/#change,25769 - related issue in QNetworkInterface
          https://codereview.qt-project.org/#change,25770 - this issue
          https://codereview.qt-project.org/#change,25899 - test case for same issue in QTcpServer/QTcpSocket

          Show
          Shane Kearns added a comment - https://codereview.qt-project.org/#change,25769 - related issue in QNetworkInterface https://codereview.qt-project.org/#change,25770 - this issue https://codereview.qt-project.org/#change,25899 - test case for same issue in QTcpServer/QTcpSocket
          Show
          Shane Kearns added a comment - 4.8 changes: https://codereview.qt-project.org/26938 https://codereview.qt-project.org/26939 https://codereview.qt-project.org/26940

            People

            • Assignee:
              Shane Kearns
              Reporter:
              Jean-Yves Avenard
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: