QTcpSocket: selecting source interface using bind() for connection to remote host with connectToHost(): don't work, possible bug
-
Hi, i want to use certain source interface for connection to remote host. I have
3 interfaces: eth0 (192.168.230.100), wlan0(10.0.9.100), and lo:Assuming mSocket is class member:
@QTcpSocket mSocket;@
And in constructor we use:
@
bool ret = mSocket.bind(QHostAddress("10.0.9.100"));
@And then in timer we try to connect:
@
void CamComponent::tryToConnect()
{
mSocket.connectToHost(QHostAddress(CameraIpAddr), CameraPort);
}
@And after this i use TCPDUMP to view outgoing packets, and they dont have source IP 10.0.9.100. Using strace i had checked that Qt makes calls to:
socket()
bind()
socket() <- this causes problem, it's QT internal problem
connect()Is this any possibility to workaround this ? Maybe by using own sockets, creating descriptor and providing it to QTcpSocket by @QAbstractSocket::setSocketDescriptor@ ? Is this bug covers also QAbstractSocket::setSocketDescriptor ?
-
Hi.
When you bind a socket using bind method then it randomly select a port number.Here i can see you didn't specify it.may be this cause an error because randomly selected port is not matched to your port.Is your CameraIpAddr same as 10.0.9.100 ?
-
It is not server socket. Addresses are randomly chosen by me, not real. The clue is that bind() dont work for connect to.
-
Just to exclude any constructor overloading trap, have you tried:
@
bool ret=mSocket.bind(QHostAddress(QLatin1String("10.0.9.100")));
@?
-
I think it is related to BUG:
https://bugreports.qt-project.org/browse/QTBUG-29732
So my question, how to workaround this, or when bug will be fixed ?