#include "qgnetworkinterface.h"

#include "mydebug.h"

static QHostAddress qgHostAddress=QHostAddress::LocalHost;
static QHostAddress qgBroadcastAddress=QHostAddress::LocalHost;

void QgNetworkInterface::setNetworkInterface(const QHostAddress& adr)
{
   qgHostAddress=adr;
   quint32 ip=adr.toIPv4Address();
   //if (!adr.isLoopback())
    ip|=255;

   qgBroadcastAddress=QHostAddress(ip);
   MyDebug.logMsg( type_log_info, origin_msg_generic ,QString("QgNetworkInterface: %1").arg(adr.toString()));
}

QHostAddress QgNetworkInterface::networkInterface()
{
    return qgHostAddress;
}

QHostAddress QgNetworkInterface::networkBroadcast()
{
    return qgBroadcastAddress;
}

QString QgNetworkInterface::networkIP()
{
    return qgHostAddress.toString();
}

void QgNetworkInterface::setNetworkIP(const QString& str)
{
    qgHostAddress=QHostAddress(str);
}

unsigned int QgNetworkInterface::networkMTU()
{
    return 1536;
}
void QgNetworkInterface::setNetworkMTU(unsigned int)
{
    return;
}

unsigned int QgNetworkInterface::networkUdpMTU()
{
    return networkMTU()-(20+8);
}
