PDA

View Full Version : QTcpServer or QUdpLocal, can't bind to IPv6 link-local



jyavenard
1st May 2012, 12:38
Hi there.

I am trying to bind (QUdpSocket) or listen (QTcpServer) to an IPv6 link-local address.

The address was retrieved via QNetworkInterface::allAddresses().

When I call QTcpServer::listen() or QUdpSocket::bind() on that QHostAddress, I get the error: "The address is not available"

Now I understand that to bind on an IPv6 link-local address, you have to set the scopeId as well.
Eg, for the link-local fe80::ca2a:14ff:fe3f:232 , you need to use fe80::ca2a:14ff:fe3f:232%en0

Interestingly, calling QHostAddress::scopeId(), returns an empty string, I think it should have been set to "en0" automatically here.

I have to manually set the scopeId to what it should be (e.g. QHostAddress::setScopeId("en0").

So, what is the proper way to set a server to listen on an IPv6 link-local addres??
Or at least, how do I retrieve the scopeId of a link-local address, or find the matching network interface for a given IP (then I can call setScopeId myself)

Thanks in advance
Jean-Yves