@@ -889,6 +889,31 @@ QSize CMinimumStackedLayout::sizeHint() const
889889* Other Classes *
890890\******************************************************************************/
891891// Network utility functions ---------------------------------------------------
892+ bool NetworkUtil::ParseNetworkAddressString ( QString strAddress, QHostAddress& InetAddr, bool bEnableIPv6 )
893+ {
894+ // try to get host by name, assuming
895+ // that the string contains a valid host name string or IP address
896+ const QHostInfo HostInfo = QHostInfo::fromName ( strAddress );
897+
898+ if ( HostInfo.error () != QHostInfo::NoError )
899+ {
900+ // qInfo() << qUtf8Printable ( QString ( "Invalid hostname" ) );
901+ return false ; // invalid address
902+ }
903+
904+ foreach ( const QHostAddress HostAddr, HostInfo.addresses () )
905+ {
906+ // qInfo() << qUtf8Printable ( QString ( "Resolved network address to %1 for proto %2" ) .arg ( HostAddr.toString() ) .arg (
907+ // HostAddr.protocol() ) );
908+ if ( HostAddr.protocol () == QAbstractSocket::IPv4Protocol || ( bEnableIPv6 && HostAddr.protocol () == QAbstractSocket::IPv6Protocol ) )
909+ {
910+ InetAddr = HostAddr;
911+ return true ;
912+ }
913+ }
914+ return false ;
915+ }
916+
892917bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAddress, bool bEnableIPv6 )
893918{
894919 QHostAddress InetAddr;
@@ -970,31 +995,7 @@ bool NetworkUtil::ParseNetworkAddress ( QString strAddress, CHostAddress& HostAd
970995 return false ; // invalid address
971996 }
972997
973- // try to get host by name, assuming
974- // that the string contains a valid host name string
975- const QHostInfo HostInfo = QHostInfo::fromName ( strAddress );
976-
977- if ( HostInfo.error () != QHostInfo::NoError )
978- {
979- // qInfo() << qUtf8Printable ( QString ( "Invalid hostname" ) );
980- return false ; // invalid address
981- }
982-
983- bool bFoundAddr = false ;
984-
985- foreach ( const QHostAddress HostAddr, HostInfo.addresses () )
986- {
987- // qInfo() << qUtf8Printable ( QString ( "Resolved network address to %1 for proto %2" ) .arg ( HostAddr.toString() ) .arg (
988- // HostAddr.protocol() ) );
989- if ( HostAddr.protocol () == QAbstractSocket::IPv4Protocol || ( bEnableIPv6 && HostAddr.protocol () == QAbstractSocket::IPv6Protocol ) )
990- {
991- InetAddr = HostAddr;
992- bFoundAddr = true ;
993- break ;
994- }
995- }
996-
997- if ( !bFoundAddr )
998+ if ( !ParseNetworkAddressString ( strAddress, InetAddr, bEnableIPv6 ) )
998999 {
9991000 // no valid address found
10001001 // qInfo() << qUtf8Printable ( QString ( "No IP address found for hostname" ) );
0 commit comments