tools/hexnet: Put the new usage generator to use and remove prefixes for IPv4 and IPv6
The prefixes were part of a planned feature but since a connection is either IPv4 or IPv6 but never both, it would have been completely useless to specify which to use. Instead, only TCP and UDP will need to be specified.BodgeMaster-unfinished
							parent
							
								
									a1f16e6f6b
								
							
						
					
					
						commit
						8048dc8891
					
				|  | @ -57,7 +57,7 @@ void signalHandler(int signal) { | |||
|     tcp6Acceptor.shutdown(); | ||||
|     // tell sockpp to close TCP socket if open because it blocks when trying
 | ||||
|     // to read and there is no data
 | ||||
|      | ||||
| 
 | ||||
|     if (tcpSocket != nullptr && *tcpSocket) { | ||||
|         // Intentionally not using the mutex here
 | ||||
|         std::cout << "test\n"; | ||||
|  | @ -149,17 +149,19 @@ int main(int argc, char* argv[]){ | |||
|     flags.push_back(CLI::Flag('u', "udp", "use UDP, defaults to both when -t and -u are omitted, otherwise uses what is specified")); | ||||
|     flags.push_back(CLI::Flag('n', "no-color", "disable coloring the output (intended for terminals that don't work well with color escape sequences)")); | ||||
|     flags.push_back(CLI::Flag('e', "echo-back", "echo input back to stdout")); | ||||
|     flags.push_back(CLI::Flag('h', "help", "print this information and exit")); | ||||
|     flags.push_back(CLI::Flag('l', "license", "print license information and exit")); | ||||
| 
 | ||||
|     std::vector<CLI::Option> options; | ||||
|     options.push_back(CLI::Option('c', "connect", "HOST", "connect to HOST, listen for incoming connections if omitted")); | ||||
|     options.push_back(CLI::Option('m', "mtu-optimize", "MTU", "Optimize for a specific maximum transfer unit by reading MTU bytes at a time.")); | ||||
|     options.push_back(CLI::Option( | ||||
|         'p', "print-prefixes", "TCPv4i:UDPv4i:TCPv6i:UDPv6i:TCPv4o:UDPv4o:TCPv6o:UDPv6o", | ||||
|         "override default prefixes for output (defaults to spaces + coloring the output or \"t4:u4:t6:u6:T4:U4:T6:U6\" in no-color mode)" | ||||
|         'p', "print-prefixes", "TCPin:UDPin:TCPout:UDPout", | ||||
|         "override default prefixes for output (defaults to spaces + coloring the output or \"t:u:T:U\" in no-color mode)" | ||||
|     )); | ||||
|     options.push_back(CLI::Option( | ||||
|         'i', "input-prefixes", "TCP:UDP:IPv4:IPv6", | ||||
|         "override default prefixes for input (defaults to \"t:u:4:6\")" | ||||
|         'i', "input-prefixes", "TCP:UDP", | ||||
|         "override default prefixes for input (defaults to \"t:u\")" | ||||
|     )); | ||||
| 
 | ||||
|     std::vector<CLI::Argument> arguments; | ||||
|  | @ -167,25 +169,51 @@ int main(int argc, char* argv[]){ | |||
| 
 | ||||
|     CLI::ArgumentsParser cliParser = CLI::ArgumentsParser(argc, argv, flags, options, arguments, "Arbitrary tcp/udp connections in hex format."); | ||||
| 
 | ||||
|     if (cliParser.getFlag("help").value){ | ||||
|         std::cout << cliParser.getUsage() << std::endl; | ||||
|         return EXIT_SUCCESS; | ||||
|     } | ||||
|     if (cliParser.getFlag("license").value){ | ||||
|         std::cout | ||||
|             << "Copyright 2022, FOSS-VG Developers and Contributers\n" | ||||
|             << "\n" | ||||
|             << "Hexnet is part of the FOSS-VG development tool suite.\n" | ||||
|             << "\n" | ||||
|             << "This program is free software: you can redistribute it and/or modify it\n" | ||||
|             << "under the terms of the GNU Affero General Public License as published\n" | ||||
|             << "by the Free Software Foundation, version 3.\n" | ||||
|             << "\n" | ||||
|             << "This program is distributed in the hope that it will be useful,\n" | ||||
|             << "but WITHOUT ANY WARRANTY; without even the implied\n" | ||||
|             << "warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | ||||
|             << "See the GNU Affero General Public License for more details.\n" | ||||
|             << "\n" | ||||
|             << "You should have received a copy of the GNU Affero General Public License\n" | ||||
|             << "version 3 along with this program.\n" | ||||
|             << "If not, see https://www.gnu.org/licenses/agpl-3.0.en.html" | ||||
|             << std::endl; | ||||
|         return EXIT_SUCCESS; | ||||
|     } | ||||
| 
 | ||||
|     if (cliParser.wrongUsage) { | ||||
|         //TODO: spit out usage information generated by the parser
 | ||||
|         std::cout << cliParser.getUsage() << std::endl; | ||||
|         return EXIT_USAGE; | ||||
|     } | ||||
|     if (cliParser.getFlag('4').value || cliParser.getFlag('6').value) { | ||||
|         ipv4 = cliParser.getFlag('4').value; | ||||
|         ipv6 = cliParser.getFlag('6').value; | ||||
|     if (cliParser.getFlag("ipv4").value || cliParser.getFlag("ipv6").value) { | ||||
|         ipv4 = cliParser.getFlag("ipv4").value; | ||||
|         ipv6 = cliParser.getFlag("ipv4").value; | ||||
|     } | ||||
|     if (cliParser.getFlag('t').value || cliParser.getFlag('u').value) { | ||||
|         tcp = cliParser.getFlag('t').value; | ||||
|         udp = cliParser.getFlag('u').value; | ||||
|     if (cliParser.getFlag("tcp").value || cliParser.getFlag("udp").value) { | ||||
|         tcp = cliParser.getFlag("tcp").value; | ||||
|         udp = cliParser.getFlag("udp").value; | ||||
|     } | ||||
|     if (cliParser.getOption('c').errorCode == ErrorCodes::NOT_PRESENT) { | ||||
|         listenMode = true; | ||||
|     } | ||||
|     if (cliParser.getOption('m').errorCode == ErrorCodes::SUCCESS) { | ||||
|         mtu = std::stol(cliParser.getOption('m').value); | ||||
|     if (cliParser.getOption("mtu-optimize").errorCode == ErrorCodes::SUCCESS) { | ||||
|         mtu = std::stol(cliParser.getOption("mtu-optimize").value); | ||||
|     } | ||||
|     host = cliParser.getOption('c').value; | ||||
|     host = cliParser.getOption("connect").value; | ||||
|     //FIXME: use a function that returns a fixed-width data type instead,
 | ||||
|     //       ensure that the given value is a valid port
 | ||||
|     port = (in_port_t) std::stoi(cliParser.getArgument(0).value); | ||||
|  | @ -256,7 +284,7 @@ int main(int argc, char* argv[]){ | |||
|             delete tcpSocket; | ||||
|             return EXIT_SUCCESS; | ||||
|         } | ||||
|          | ||||
| 
 | ||||
|     } else { | ||||
|         std::cerr << "Client mode is not implemented yet." << std::endl; | ||||
|         return EXIT_UNIMPLEMENTED; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 BodgeMaster
						BodgeMaster