From 8614491aa1a19973f2039c5c5f2e5551cc535b8c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 11 Mar 2021 13:50:56 -0800 Subject: QAbstractSocket: fake a bind(QHostAddress::SpecialAddress) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because this is misleading: socket.bind(QHostAddress::AnyIPv4); The conversion of enum to int has preference over the construction of QHostAddress from enum, so that ends up calling bind(6), which attempts to bind to privileged port 6 and just returns with error. Meanwhile, socket.bind(QHostAddress::AnyIPv4, 0); does construct the QHostAddress because that is preferred to converting the int to the BindMode enum. Ideally we'd simply add the overload to QAbstractSocket but we can't do that because QHostAddress depends on QAbstractSocket. So I've added a Qt7 task to invert that dependency. Change-Id: I26b8286f61534f88b649fffd166b683266597796 Reviewed-by: MÃ¥rten Nordheim --- src/network/socket/qabstractsocket.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/network/socket/qabstractsocket.h') diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h index bf1ff7e9a2..5874ddb8e8 100644 --- a/src/network/socket/qabstractsocket.h +++ b/src/network/socket/qabstractsocket.h @@ -148,7 +148,15 @@ public: virtual bool bind(const QHostAddress &address, quint16 port = 0, BindMode mode = DefaultForPlatform); +#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(Q_CLANG_QDOC) + // ### Qt7: this requires that QHostAddress stop depending on QAbstractSocket::NetworkLayerProtocol + bool bind(QHostAddress::SpecialAddress addr, quint16 port = 0, BindMode mode = DefaultForPlatform) + { return bind(QHostAddress(addr), port, mode); } + bool bind(quint16 port = 0, BindMode mode = DefaultForPlatform) + { retrurn bind(QHostAddress::Any, port, mode); } +#else bool bind(quint16 port = 0, BindMode mode = DefaultForPlatform); +#endif virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode = ReadWrite, NetworkLayerProtocol protocol = AnyIPProtocol); void connectToHost(const QHostAddress &address, quint16 port, OpenMode mode = ReadWrite); -- cgit v1.2.3