From fd20de0e38b48a931df03f8f6c8b266fbc8c45e5 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Fri, 22 Jun 2018 15:07:02 +0300 Subject: [PATCH] Added a function that recognizes your IPv6. --- src/kernel/network.cpp | 13 ++++++++++--- src/kernel/network.hpp | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/kernel/network.cpp b/src/kernel/network.cpp index 26b37d1..f90cf17 100644 --- a/src/kernel/network.cpp +++ b/src/kernel/network.cpp @@ -13,7 +13,6 @@ void Network::sendDatagram(QJsonObject j, QString s) { QHostAddress ip = QHostAddress(s); QByteArray baDatagram; - //QDataStream out(&baDatagram, QIODevice::WriteOnly); QJsonDocument jbuff = QJsonDocument(j); quint16 p = 6552; baDatagram = jbuff.toJson(QJsonDocument::Compact); @@ -30,7 +29,15 @@ void Network::processTheDatagram() QJsonDocument jbuff = QJsonDocument::fromJson(baDatagram); QJsonObject j = QJsonObject(jbuff.object()); - //QDataStream in(&baDatagram, QIODevice::ReadOnly); - //in >> jbuff.fromBinaryData(baDatagram); emit json_received(j); } + +QString Network::local_ipv6() +{ + QHostAddress address; + foreach (address, QNetworkInterface::allAddresses()) { + if (address.protocol() == QAbstractSocket::IPv6Protocol && address != QHostAddress(QHostAddress::LocalHost)) + break; + } + return(address.toString()); +} diff --git a/src/kernel/network.hpp b/src/kernel/network.hpp index 5eb40bb..6b0679f 100644 --- a/src/kernel/network.hpp +++ b/src/kernel/network.hpp @@ -3,6 +3,7 @@ #include #include #include +#include class Network : public QObject { @@ -12,6 +13,7 @@ class Network : public QObject QUdpSocket* udpSocket; public: Network(bool is_server = true); + static QString local_ipv6(); public slots: void sendDatagram(QJsonObject j, QString s); signals: