mirror of
https://github.com/ChronosX88/Influence-cjdns.git
synced 2024-11-23 15:42:18 +00:00
Added a function that recognizes your IPv6.
This commit is contained in:
parent
d557b16c6a
commit
fd20de0e38
@ -13,7 +13,6 @@ void Network::sendDatagram(QJsonObject j, QString s)
|
|||||||
{
|
{
|
||||||
QHostAddress ip = QHostAddress(s);
|
QHostAddress ip = QHostAddress(s);
|
||||||
QByteArray baDatagram;
|
QByteArray baDatagram;
|
||||||
//QDataStream out(&baDatagram, QIODevice::WriteOnly);
|
|
||||||
QJsonDocument jbuff = QJsonDocument(j);
|
QJsonDocument jbuff = QJsonDocument(j);
|
||||||
quint16 p = 6552;
|
quint16 p = 6552;
|
||||||
baDatagram = jbuff.toJson(QJsonDocument::Compact);
|
baDatagram = jbuff.toJson(QJsonDocument::Compact);
|
||||||
@ -30,7 +29,15 @@ void Network::processTheDatagram()
|
|||||||
|
|
||||||
QJsonDocument jbuff = QJsonDocument::fromJson(baDatagram);
|
QJsonDocument jbuff = QJsonDocument::fromJson(baDatagram);
|
||||||
QJsonObject j = QJsonObject(jbuff.object());
|
QJsonObject j = QJsonObject(jbuff.object());
|
||||||
//QDataStream in(&baDatagram, QIODevice::ReadOnly);
|
|
||||||
//in >> jbuff.fromBinaryData(baDatagram);
|
|
||||||
emit json_received(j);
|
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());
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <QtNetwork>
|
#include <QtNetwork>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
#include <QNetworkInterface>
|
||||||
|
|
||||||
class Network : public QObject
|
class Network : public QObject
|
||||||
{
|
{
|
||||||
@ -12,6 +13,7 @@ class Network : public QObject
|
|||||||
QUdpSocket* udpSocket;
|
QUdpSocket* udpSocket;
|
||||||
public:
|
public:
|
||||||
Network(bool is_server = true);
|
Network(bool is_server = true);
|
||||||
|
static QString local_ipv6();
|
||||||
public slots:
|
public slots:
|
||||||
void sendDatagram(QJsonObject j, QString s);
|
void sendDatagram(QJsonObject j, QString s);
|
||||||
signals:
|
signals:
|
||||||
|
Loading…
Reference in New Issue
Block a user