diff --git a/src/util.cpp b/src/util.cpp index 7c4682c99a..1a815fe7c8 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -982,18 +982,26 @@ bool NetworkUtil::ParseNetworkAddress ( QString strAddress, // that the string contains a valid host name string const QHostInfo HostInfo = QHostInfo::fromName ( strAddress ); - if ( HostInfo.error() == QHostInfo::NoError ) + if ( HostInfo.error() != QHostInfo::NoError ) { - // apply IP address to QT object - if ( !HostInfo.addresses().isEmpty() ) - { - // use the first IP address - InetAddr = HostInfo.addresses().first(); - } + return false; // invalid address } - else + + // use the first IPv4 address, if any + bool bFoundIPv4 = false; + foreach ( const QHostAddress HostAddr, HostInfo.addresses() ) { - return false; // invalid address + if ( HostAddr.protocol() == QAbstractSocket::IPv4Protocol ) + { + InetAddr = HostAddr; + bFoundIPv4 = true; + break; + } + } + if ( !bFoundIPv4 ) + { + // only found IPv6 addresses + return false; } }