From 1bce935b05829daf0f1ec3bfc1fc7b5fe7cf8f81 Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Tue, 31 Mar 2020 13:06:21 -0400 Subject: [PATCH] main.cpp : Updates to sockMgrTest() to support supplying an optional NIC device label. --- src/cwtest/main.cpp | 73 ++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/src/cwtest/main.cpp b/src/cwtest/main.cpp index d87d526..f529533 100644 --- a/src/cwtest/main.cpp +++ b/src/cwtest/main.cpp @@ -257,36 +257,61 @@ void socketSrvTcpTest( cw::object_t* cfg, int argc, const char* argv[] ) void sockMgrTest( cw::object_t* cfg, int argc, const char* argv[] ) { - bool tcpFl = false; - unsigned short localPort = 0; - const char* remoteIp = nullptr; - unsigned short remotePort = 0; - + bool tcpFl = false; + const char* localNicDev = nullptr; + unsigned short localPort = 0; + const char* remoteIp = nullptr; + unsigned short remotePort = 0; + int argi = 0; + if( argc <3 ) { - printf("Invalid argument count."); - printf("Usage: ./cw_rt sockMgrTest 'udp | tcp' { }\n"); + printf("Error: Invalid argument count."); goto errLabel; } - - if( argc >= 4 ) - { - remoteIp = argv[3]; - - if( argc >= 5 ) - remotePort = atoi(argv[4]); - - } - + // The first arg. must be 'tcp' or 'udp'. if( strcmp(argv[1],"tcp")!=0 && strcmp(argv[1],"udp")!=0 ) { - printf("The first argument must be 'udp' or 'tcp'\n"); + printf("Error: The first argument must be 'udp' or 'tcp'\n"); goto errLabel; } + + + tcpFl = strcmp(argv[1],"tcp")==0; + + argi = 2; + + // If the next token is 'dev' ... + if( strcmp(argv[argi++],"dev") == 0 ) + { + if( argc <= argi ) + { + printf("Error: No local NIC given.\n"); + goto errLabel; + } + + // .. then the next arg is the localNicDev + localNicDev = argv[argi++]; + } + + if( argc <= argi ) + { + printf("Error: No local port was given.\n"); + goto errLabel; + } + + // get the local port + localPort = atoi(argv[argi++]); + + if( argc > argi) + { + remoteIp = argv[argi++]; + + if( argc > argi) + remotePort = atoi(argv[argi++]); + } - tcpFl = strcmp(argv[1],"tcp")==0; - localPort = atoi(argv[2]); if( remoteIp != nullptr && remotePort == 0 ) { @@ -296,9 +321,15 @@ void sockMgrTest( cw::object_t* cfg, int argc, const char* argv[] ) printf("style:%s local:%i to remote:%s %i\n", argv[1], localPort, cwStringNullGuard(remoteIp), remotePort); - cw::socksrv::testMain( tcpFl, localPort, remoteIp, remotePort ); + cw::socksrv::testMain( tcpFl, localNicDev, localPort, remoteIp, remotePort ); + return; + errLabel: + + // 1 2 3 4 + // 1 2 3 4 5 6 + printf("Usage: ./cwtest sockMgrTest 'udp | tcp' {'dev' } { }\n"); return; }