support literal IPv6 addresses in connection strings v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 06 Aug 2022 12:12:46 +0200
branchv_0
changeset 17 b9dcb7aa75e1
parent 16 63bb2c2038c7
child 18 e16fa75135ad
support literal IPv6 addresses in connection strings
src/CLIParser.h
--- a/src/CLIParser.h	Sat Aug 06 01:05:44 2022 +0200
+++ b/src/CLIParser.h	Sat Aug 06 12:12:46 2022 +0200
@@ -85,14 +85,16 @@
 		// Parse the connection string and convert it to options:
 		if (connectionString.size()) {
 			std::string connectionStringBytes = convertor.to_bytes(connectionString);
-			std::regex pattern("(tcp|udp|sctp)://([^:]+):([0-9]+)|(uds)://(.*)");
+			std::regex pattern("(tcp|udp|sctp)://(([^:]+)|\\[([0-9a-fA-F:]+)\\]):([0-9]+)|(uds)://(.*)");
+			//                  1                23          4                   5        6       7
 			std::smatch match;
 			if (std::regex_match(connectionStringBytes, match, pattern)) {
 				setIfMissing(c.options, OPTION_PROTOCOL, match[1], false);
-				setIfMissing(c.options, OPTION_PROTOCOL, match[4], false);
-				setIfMissing(c.options, OPTION_HOST, match[2], false);
-				setIfMissing(c.options, OPTION_PORT, match[3], false);
-				setIfMissing(c.options, OPTION_PATH, match[5], false);
+				setIfMissing(c.options, OPTION_PROTOCOL, match[6], false);
+				setIfMissing(c.options, OPTION_HOST, match[3], false);
+				setIfMissing(c.options, OPTION_HOST, match[4], false);
+				setIfMissing(c.options, OPTION_PORT, match[5], false);
+				setIfMissing(c.options, OPTION_PATH, match[7], false);
 				if (match[1] == PROTOCOL_TCP) setIfMissing(c.options, OPTION_MODE, MODE_STREAM);
 			} else {
 				throw relpipe::cli::RelpipeCLIException(L"Invalid connection string: " + connectionString, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);