Re: [Interest] Convert IPv6 to IPv4 ?

2016-04-25 Thread Alexander Carôt
Hello Thiago, Hello Benjamin,

thanks for your replies !

In fact Thiago was precisely right with this:

> You probably mean you've got a v4-mapped IPv6 address, as
> :::192.0.2.1

As a quick hack I first converted this to a string and removed the first 7 
characters but of course Thiagos solution is the way to do it. It works well - 
thanks a lot,

best regards

Alex


--
http://www.carot.de
Email : alexan...@carot.de
Tel.: +49 (0)177 5719797


> Gesendet: Donnerstag, 21. April 2016 um 19:02 Uhr
> Von: "Thiago Macieira" <thiago.macie...@intel.com>
> An: interest@qt-project.org
> Betreff: Re: [Interest] Convert IPv6 to IPv4 ?
>
> On quinta-feira, 21 de abril de 2016 14:05:52 PDT Alexander Carôt wrote:
> > 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.
> 
> Hello Alex
> 
> You probably mean you've got a v4-mapped IPv6 address, as
>   :::192.0.2.1
> 
> You should code as:
> 
>   bool ok;
>   quint32 ipv4 = hostaddr.toIPv4Address();
>   if (ok) {
>   // check my IPv4 ACL
>   } else if (hostaddr.protocol() == QAbstractSocket::IPv6Protocol) {
>   // check my IPv6 ACL
>   } else {
>   // uh... what?
>   }
> 
> 
> -- 
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel Open Source Technology Center
> 
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Convert IPv6 to IPv4 ?

2016-04-21 Thread Thiago Macieira
On quinta-feira, 21 de abril de 2016 14:05:52 PDT Alexander Carôt wrote:
> 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.

Hello Alex

You probably mean you've got a v4-mapped IPv6 address, as
:::192.0.2.1

You should code as:

bool ok;
quint32 ipv4 = hostaddr.toIPv4Address();
if (ok) {
// check my IPv4 ACL
} else if (hostaddr.protocol() == QAbstractSocket::IPv6Protocol) {
// check my IPv6 ACL
} else {
// uh... what?
}


-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Convert IPv6 to IPv4 ?

2016-04-21 Thread Benjamin TERRIER
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  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" :
> 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 : alexan...@carot.de
> Tel.: +49 (0)177 5719797
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest