[Interest] Convert IPv6 to IPv4 ?

Benjamin TERRIER b.terrier at gmail.com
Thu Apr 21 16:51:08 CEST 2016


Hi Alexander,

First there is no way to convert an IPv6 to an IPv4.
A given machine can have an IPv6 address without an IPv4 address, or
have an IPv4 address without an IPv6 address, or one of each, or many
addresses of each type.

If you want peerAddress() to only return IPv4 addresses you must
ensure that you cannot be joined with an IPv6 address.
One solution, if you are using an QWebSocketServer, is that when you
process new connections (i.e when you call nextPendingConnection())
you reject them is the peer address is an IPv6 address. The fallback
might be that if a client tries to contact your server through IPv6
first, it might not try IPv4 next and believe that your server is not
available.
Another solution is to remove the AAAA field from your DNS record (if
applicable), but it might make collateral damages if you have multiple
applications running on same server.

My advice on this is that you should not require IPv4 addresses but
must handles both. Especially if your application is going to be used
for a long time.

Regards,

Benjamin


2016-04-21 14:05 GMT+02:00 "Alexander CarĂ´t" <alexander_carot at gmx.net>:
> Hello,
>
> I noticed that retrieving a sender's IP address of a QWebSocket via ->peerAddress() returns an IPv6 socket address.
>
> For certain reasons I need an IPv4 address so I wonder how it is possible to either let ->peerAddress() return an IPv4 address or convert the IPv6 address to an IPv4 address.
>
> Thanks in advance,
> best
>
> Alex
>
> --
> http://www.carot.de
> Email : Alexander at Carot.de
> Tel.: +49 (0)177 5719797
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list