CEndPoint & CEndPoint::operator--()
{
	if( protocol() == QAbstractSocket::IPv4Protocol )
	{
		quint32 result = toIPv4Address();
		setAddress(--result);
		return *this;
	}
	else
	{
		Q_IPV6ADDR result = toIPv6Address();
		quint8 carry = 1, i = 8;
		while (carry && i)
		{
			result[i-1] -= carry;
			if (result[i-1] < 0x0000 || !result[i-1])
			{
				carry = 1;
				result[i-1] &= 0x0000;
			} else {
				carry = 0;
			}
			i--;
		}
		setAddress(result);
		return *this;
	}
}
Esempio n. 2
0
// (?)
std::string QHostAddress::toString() const
{
    if (m_pImpl->getProtocol() == QAbstractSocket::IPv4Protocol) 
    {
        quint32 ip = toIPv4Address();
        
        return ToStdString(ip);
    }

    return std::string();
}
bool CEndPoint::isFirewalled() const
{
	if ( isNull() )
		return true;

	if ( protocol() == 0 ) // IPv4
	{
		quint32 nIp = qToBigEndian( toIPv4Address() );

		if ( (nIp & 0xffff) == 0xa8c0 ) return true; // 192.168
		if ( (nIp & 0xff  ) == 0x0a   ) return true; // 10
		if ( (nIp & 0xf0ff) == 0x10ac ) return true; // 172.16
		if ( (nIp & 0xffff) == 0xfea9 ) return true; // 169.254
		if ( (nIp & 0xff  ) == 0x7f   ) return true; // 127
	}

	return false;
}
IpCalculator::IpCalculator(const QString &addressInput) :
    addressInput(addressInput),
    ipAddress(0),
    prefixLength(0),
    calculatedSubnetMask(0xFFFFFFFF)
{
    QStringList inputList = addressInput.split("/", QString::SkipEmptyParts);

    if (inputList.size() == 0) {
        return;
    }

    ipAddress = toIPv4Address(inputList[0]);


    if (inputList.size() == 2) {
        prefixLength = inputList[1].toInt();
    } else {
        prefixLength = defaultPrefixLengthFromAddress(ipAddress);
    }
    calculatedSubnetMask <<= (32-prefixLength);
}