[Interest] Handling IP V4 and V6 as a QTcpServer?

Jason H jhihn at gmx.com
Tue Jan 21 15:23:53 CET 2020



> Sent: Monday, January 13, 2020 at 5:57 PM
> From: "Thiago Macieira" <thiago.macieira at intel.com>
> To: "interestqt-project.org" <interest at qt-project.org>
> Subject: Re: [Interest] Handling IP V4 and V6 as a QTcpServer?
>
> On Monday, 13 January 2020 10:49:38 PST Jason H wrote:
> > I an starting to see QHostAddress::toString() return things like:
> > "::ffff:192.168.34.3", which is a IPv6 mapping. However when I try to
> > connect to this address it does not work. That server is a QTcpServer bound
> > as: _server.listen(QHostAddress::Any, PORT);
>
> How are you trying to connect to that address?

The client is told what address to connect to, which is a IPv4 address, as a QString passed to QTcpSocket::connectToHost, which comes from a config file, whose address is a static IPv4 address on the network.

> > When the QHostAddress resolves to a IPv4 address, everything works. When it
> > resolves to IPv6, it does not. When implementing servers with QTcpServer,
> > how do I provide a service that works with both protocols? At the
> > application level, I don't [want to] care with protocol they use.
>
> The one thing you have to do is not hardcode any addresses or use the
> constants with "IPv4". QtNetwork will prefer IPv6 (as it should) and
> QTcpServer will accept IPv4 connections as you've seen.
>
> > Lastly, is this documented anywhere?
>
> There isn't anything to document because it's not what you need to do. It's
> just removing incorrect assumptions from your code.

You are absolutely correct. I don't want to care at all, but later down the line, there is a test to see if the address connected to is a particular address. I guess the proper way to do that is to use QHostAddress::toIPv6Address() at all times?





More information about the Interest mailing list