TSG
TSG

Reputation: 4617

QTcpSocket can't bind to right IP

I am building a linux Qt5/C++ app which runs on a system with multiple NIC's (multihomed). I need to force my outgoing TCP connection to use a specific NIC/IP. I have tried the following code but netstat confirms that my app is still using the wrong local NIC/IP.

if (m_tcpSocket->bind(localaddress)) qDebug() << "Bind success";
m_tcpSocket->connectToHost(
            remoteaddress,
            remoteport,
            QTcpSocket::ReadWrite);
}

Am I calling this incorrectly? I see "bind success" so I assume the call is right...but I can't explain why its not working


Update: I found this bug report: https://bugreports.qt.io/browse/QTBUG-29732

Is there a workaround? I see setLocalAddress() in QAbstractSocket but I'm not sure it's the same

Upvotes: 3

Views: 732

Answers (1)

TSG
TSG

Reputation: 4617

I've confirmed the cause is a bug in the Qt library, reported here. This bug has existed since Qt 4.8 and we're at Qt 5.3 today. Hard to believe such a significant bug isn't fixed (significant for any app using network)

Upvotes: 1

Related Questions