mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
Properly check for a peer is on one of our subnets
This commit is contained in:
@@ -767,23 +767,20 @@ Servent::printCurrentTransfers()
|
|||||||
bool
|
bool
|
||||||
Servent::isIPWhitelisted( QHostAddress ip )
|
Servent::isIPWhitelisted( QHostAddress ip )
|
||||||
{
|
{
|
||||||
typedef QPair<QHostAddress, int> range;
|
typedef QPair< QHostAddress, int > range;
|
||||||
static QList<range> whitelist;
|
QList< range > subnetEntries;
|
||||||
if( whitelist.isEmpty() )
|
|
||||||
|
QList< QNetworkInterface > networkInterfaces = QNetworkInterface::allInterfaces();
|
||||||
|
foreach( QNetworkInterface interface, networkInterfaces )
|
||||||
{
|
{
|
||||||
whitelist << range( QHostAddress( "10.0.0.0" ), 8 )
|
QList< QNetworkAddressEntry > addressEntries = interface.addressEntries();
|
||||||
<< range( QHostAddress( "172.16.0.0" ), 12 )
|
foreach( QNetworkAddressEntry addressEntry, addressEntries )
|
||||||
<< range( QHostAddress( "192.168.0.0" ), 16 )
|
{
|
||||||
<< range( QHostAddress( "169.254.0.0" ), 16 )
|
if ( ip.isInSubnet( addressEntry.ip(), addressEntry.prefixLength() ) )
|
||||||
<< range( QHostAddress( "127.0.0.0" ), 24 );
|
return true;
|
||||||
|
}
|
||||||
// tDebug( LOGVERBOSE ) << "Loaded whitelist IP range:" << whitelist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( const range& r, whitelist )
|
|
||||||
if( ip.isInSubnet( r ) )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user