From 96777cbab25fb5faceab57428c6ce5e85f014f87 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 8 Jul 2019 17:02:05 +0200 Subject: [PATCH] add support for IPv6 for ParseNetworkAddress --- src/util.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index de65b9a7..f18c70bd 100755 --- a/src/util.cpp +++ b/src/util.cpp @@ -832,15 +832,34 @@ bool NetworkUtil::ParseNetworkAddress ( QString strAddress, // init requested host address with invalid address first HostAddress = CHostAddress(); - // parse input address for the type [IP address]:[port number] - QString strPort = strAddress.section ( ":", 1, 1 ); + // parse input address for the type "IP4 address:port number" or + // "[IP6 address]:port number" assuming the syntax is correctly given + QStringList slAddress = strAddress.split ( ":" ); + QString strSep = ":"; + bool bIsIP6 = false; + + if ( slAddress.count() > 2 ) + { + // IP6 address + bIsIP6 = true; + strSep = "]:"; + } + + QString strPort = strAddress.section ( strSep, 1, 1 ); + if ( !strPort.isEmpty() ) { // a colon is present in the address string, try to extract port number iNetPort = strPort.toInt(); - // extract address port before colon (should be actual internet address) - strAddress = strAddress.section ( ":", 0, 0 ); + // extract address port before separator (should be actual internet address) + strAddress = strAddress.section ( strSep, 0, 0 ); + + if ( bIsIP6 ) + { + // remove "[" at the beginning + strAddress.remove ( 0, 1 ); + } } // first try if this is an IP number an can directly applied to QHostAddress