support IPv6 link local addresses not only in the „host“ option but also in the connection string v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 07 Aug 2022 15:31:51 +0200
branchv_0
changeset 20 ad21bff45051
parent 19 7a9a52e949b9
child 21 1c6c86697837
support IPv6 link local addresses not only in the „host“ option but also in the connection string
src/CLIParser.h
--- a/src/CLIParser.h	Sun Aug 07 15:09:47 2022 +0200
+++ b/src/CLIParser.h	Sun Aug 07 15:31:51 2022 +0200
@@ -85,16 +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-9a-fA-F:]+)\\]):([0-9]+)|(uds)://(.*)");
-			//                  1                23          4                   5        6       7
+			std::regex pattern("(tcp|udp|sctp)://(([^:]+)|\\[([0-9a-fA-F:]+(%[a-zA-Z0-9]+))\\]):([0-9]+)|(uds)://(.*)");
+			//                  1                23          4             5                    6        7       8
 			std::smatch match;
 			if (std::regex_match(connectionStringBytes, match, pattern)) {
 				setIfMissing(c.options, OPTION_PROTOCOL, match[1], false);
-				setIfMissing(c.options, OPTION_PROTOCOL, match[6], false);
+				setIfMissing(c.options, OPTION_PROTOCOL, match[7], 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);
+				setIfMissing(c.options, OPTION_PORT, match[6], false);
+				setIfMissing(c.options, OPTION_PATH, match[8], 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);