QTcpSocket cannot bind to correct IP address
I am creating a Qt5 / C ++ linux application that runs on a multi-NIC system (multihomed). I need to force my outgoing TCP connection to use a specific NIC / IP. I tried the following code, but netstat confirms that my application is still using the wrong local network adapter.
if (m_tcpSocket->bind(localaddress)) qDebug() << "Bind success";
m_tcpSocket->connectToHost(
remoteaddress,
remoteport,
QTcpSocket::ReadWrite);
}
Am I calling it wrong? I see "bind success", so I assume the call is correct ... but I cannot explain why its not working
Update: I found this bug report: https://bugreports.qt.io/browse/QTBUG-29732
Is there a workaround? I can see setLocalAddress () in QAbstractSocket, but I'm not sure if it is the same
+3
source to share