tools/hexnet: add server/client concept to arguments parser

BodgeMaster-unfinished
BodgeMaster 2022-07-13 06:03:41 +02:00
parent b3cd8709fb
commit 6a5096dfa3
1 changed files with 11 additions and 1 deletions

View File

@ -18,7 +18,7 @@
#include <cstdint>
#include <cctype>
#define usage std::cerr << "Usage: " << argv[0] << " [-4|-6] [-t|-u] <port>" << std::endl << "<port> may be hexadecimal (prefixed with 0x) or binary (prefixed with 0b)." << std::endl
#define usage std::cerr << "Usage: " << argv[0] << " [-4|-6] [-t|-u] <<host> <port> | -l <port>>" << std::endl << "<port> may be hexadecimal (prefixed with 0x) or binary (prefixed with 0b)." << std::endl
int main(int argc, char* argv[]){
@ -27,6 +27,7 @@ int main(int argc, char* argv[]){
bool ipv6 = true;
bool tcp = true;
bool udp = true;
bool server = false;
uint16_t port;
if (argc<2) {
usage;
@ -54,6 +55,10 @@ int main(int argc, char* argv[]){
udp = true;
continue;
}
if (argument=="-l") {
server = true;
continue;
}
if (argument=="-h") {
usage;
return 0;
@ -62,6 +67,11 @@ int main(int argc, char* argv[]){
usage;
return 0;
}
if (!server && i==argc-2) {
//TODO: check if valid host
std::cerr << "Host argument parsing is not yet implemented." << std::endl;
return 3;
}
if (i==argc-1) {
if (argument.substr(0, 2)=="0b" || argument.substr(0, 2)=="0B") {
// check for 16 bit binary number