parent
b84130344d
commit
ee9b5d4f67
|
@ -62,7 +62,7 @@ COMPILE_COMMANDS=(
|
||||||
"$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -l:cli.so -o bin/tools/dumpnbt"
|
"$CXX_WITH_FLAGS src/tools/dumpnbt.cpp -I./include -Lbin/lib -l:nbt.so -l:javacompat.so -l:cli.so -o bin/tools/dumpnbt"
|
||||||
"$CXX_WITH_FLAGS src/tools/arraydump.cpp -I./include -Lbin/lib -l:file.so -l:cli.so -o bin/tools/arraydump"
|
"$CXX_WITH_FLAGS src/tools/arraydump.cpp -I./include -Lbin/lib -l:file.so -l:cli.so -o bin/tools/arraydump"
|
||||||
"$CXX_WITH_FLAGS src/tools/baseconvert.cpp -I./include -Lbin/lib -l:cli.so -o bin/tools/baseconvert"
|
"$CXX_WITH_FLAGS src/tools/baseconvert.cpp -I./include -Lbin/lib -l:cli.so -o bin/tools/baseconvert"
|
||||||
#"$CXX_WITH_FLAGS src/tools/hexnet.cpp -I./include -Lbin/lib -l:cli.so -l:libsockpp.so -o bin/tools/hexnet"
|
"$CXX_WITH_FLAGS src/tools/hexnet.cpp -I./include -Lbin/lib -l:cli.so -l:libsockpp.so -o bin/tools/hexnet"
|
||||||
)
|
)
|
||||||
for command in ${!COMPILE_COMMANDS[@]}; do
|
for command in ${!COMPILE_COMMANDS[@]}; do
|
||||||
echo "${COMPILE_COMMANDS[command]}"
|
echo "${COMPILE_COMMANDS[command]}"
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
//Copyright 2022, FOSS-VG Developers and Contributers
|
//Copyright 2022, FOSS-VG Developers and Contributers
|
||||||
//
|
//
|
||||||
|
// Author(s):
|
||||||
|
// BodgeMaster, Shwoomple
|
||||||
|
//
|
||||||
//This program is free software: you can redistribute it and/or modify it
|
//This program is free software: you can redistribute it and/or modify it
|
||||||
//under the terms of the GNU Affero General Public License as published
|
//under the terms of the GNU Affero General Public License as published
|
||||||
//by the Free Software Foundation, version 3.
|
//by the Free Software Foundation, version 3.
|
||||||
|
@ -13,26 +16,93 @@
|
||||||
//version 3 along with this program.
|
//version 3 along with this program.
|
||||||
//If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
//If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <string>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cctype>
|
|
||||||
#include <sockpp/tcp_acceptor.h>
|
|
||||||
#include <sockpp/tcp6_acceptor.h>
|
|
||||||
#include <sockpp/udp_socket.h>
|
|
||||||
#include <sockpp/udp6_socket.h>
|
|
||||||
#include <thread>
|
|
||||||
#include <mutex>
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "../lib/error.hpp"
|
|
||||||
#include "../lib/cli.hpp"
|
#include "../lib/cli.hpp"
|
||||||
|
#include "../lib/error.hpp"
|
||||||
|
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#define EXIT_RUNTIME 1
|
#define EXIT_RUNTIME 1
|
||||||
#define EXIT_USAGE 2
|
#define EXIT_USAGE 2
|
||||||
#define EXIT_UNIMPLEMENTED 3
|
#define EXIT_UNIMPLEMENTED 3
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
std::mutex mutexStdin;
|
||||||
|
std::mutex mutexStdout;
|
||||||
|
std::mutex mutexNetIncoming;
|
||||||
|
std::mutex mutexNetOutgoing;
|
||||||
|
|
||||||
|
bool ipv4 = false;
|
||||||
|
bool ipv6 = false;
|
||||||
|
bool tcp = false;
|
||||||
|
bool udp = false;
|
||||||
|
|
||||||
|
void signalHandler(int signal) {
|
||||||
|
// shut down gracefully
|
||||||
|
std::cerr << "Received signal " << signal << ", shutting down." << std::endl;
|
||||||
|
std::exit(signal);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
std::signal(SIGINT, signalHandler);
|
||||||
|
std::signal(SIGTERM, signalHandler);
|
||||||
|
|
||||||
|
std::vector<CLI::Flag> flags;
|
||||||
|
flags.push_back(CLI::Flag('4', "ipv4", "use IPv4, either this or IPv6 has to be specified"));
|
||||||
|
flags.push_back(CLI::Flag('6', "ipv6", "use IPv6, either this or IPv4 has to be specified"));
|
||||||
|
flags.push_back(CLI::Flag('t', "tcp", "use TCP, either this or UDP has to be specified"));
|
||||||
|
flags.push_back(CLI::Flag('u', "udp", "use UDP, either this or TCP has to be specified"));
|
||||||
|
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", "make an outgoing connection to HOST instead of listening for an incoming connection"));
|
||||||
|
|
||||||
|
std::vector<CLI::Argument> arguments;
|
||||||
|
arguments.push_back(CLI::Argument("PORT", "the port to lsiten on (or connect to)"));
|
||||||
|
|
||||||
|
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) {
|
||||||
|
std::cout << cliParser.getUsage() << std::endl;
|
||||||
|
return EXIT_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ipv4 = cliParser.getFlag("ipv4").value;
|
||||||
|
ipv6 = cliParser.getFlag("ipv6").value;
|
||||||
|
tcp = cliParser.getFlag("tcp").value;
|
||||||
|
udp = cliParser.getFlag("udp").value;
|
||||||
|
|
||||||
|
if (!(ipv4 || ipv6) || !(tcp || udp)) {
|
||||||
|
std::cout << cliParser.getUsage() << std::endl;
|
||||||
|
return EXIT_USAGE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue