From 7f5ec84496493b406d866e9e88038b8862db3a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remigiusz=20Ko=C5=82=C5=82=C4=85taj?= Date: Fri, 27 Mar 2020 19:09:41 +0100 Subject: [PATCH] - add argument to disable peer checking on frame reception. - Fix strncpy warining (-Wstringop-truncation). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Remigiusz Kołłątaj --- cannelloni.cpp | 19 +++++++++++++------ udpthread.cpp | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cannelloni.cpp b/cannelloni.cpp index a77268a..2ed71ef 100644 --- a/cannelloni.cpp +++ b/cannelloni.cpp @@ -46,7 +46,7 @@ #include "make_unique.h" #include -#define CANNELLONI_VERSION "1.0.0" +#define CANNELLONI_VERSION "1.0.1" using namespace cannelloni; @@ -66,6 +66,7 @@ void printUsage() { std::cout << "\t -t timeout \t\t buffer timeout for can messages (us), default: 100000" << std::endl; std::cout << "\t -T table.csv \t\t path to csv with individual timeouts" << std::endl; std::cout << "\t -s \t\t enable frame sorting" << std::endl; + std::cout << "\t -p \t\t no peer checking" << std::endl; std::cout << "\t -d [cubt]\t\t enable debug, can be any of these: " << std::endl; std::cout << "\t\t\t c : enable debugging of can frames" << std::endl; #ifdef SCTP_SUPPORT @@ -84,6 +85,7 @@ int main(int argc, char** argv) { int opt; bool remoteIPSupplied = false; bool sortUDP = false; + bool checkPeer = true; bool useSCTP = false; #ifdef SCTP_SUPPORT SCTPThreadRole sctpRole = CLIENT; @@ -101,9 +103,9 @@ int main(int argc, char** argv) { struct debugOptions_t debugOptions = { /* can */ 0, /* udp */ 0, /* buffer */ 0, /* timer */ 0 }; #ifdef SCTP_SUPPORT - const std::string argument_options = "S:l:L:r:R:I:t:T:d:hs"; + const std::string argument_options = "S:l:L:r:R:I:t:T:d:hsp"; #else - const std::string argument_options = "Sl:L:r:R:I:t:T:d:hs"; + const std::string argument_options = "Sl:L:r:R:I:t:T:d:hsp"; #endif while ((opt = getopt(argc, argv, argument_options.c_str())) != -1) { @@ -140,13 +142,15 @@ int main(int argc, char** argv) { localPort = strtoul(optarg, NULL, 10); break; case 'L': - strncpy(localIP, optarg, INET_ADDRSTRLEN); + strncpy(localIP, optarg, INET_ADDRSTRLEN-1); + localIP[INET_ADDRSTRLEN-1] = '\0'; break; case 'r': remotePort = strtoul(optarg, NULL, 10); break; case 'R': - strncpy(remoteIP, optarg, INET_ADDRSTRLEN); + strncpy(remoteIP, optarg, INET_ADDRSTRLEN-1); + remoteIP[INET_ADDRSTRLEN-1] = '\0'; remoteIPSupplied = true; break; case 'I': @@ -174,6 +178,9 @@ int main(int argc, char** argv) { case 's': sortUDP = true; break; + case 'p': + checkPeer = false; + break; default: printUsage(); return -1; @@ -279,7 +286,7 @@ int main(int argc, char** argv) { netThread = std::make_unique(debugOptions, remoteAddr, localAddr, sortUDP, remoteIPSupplied, sctpRole); #endif } else { - netThread = std::make_unique(debugOptions, remoteAddr, localAddr, sortUDP, true); + netThread = std::make_unique(debugOptions, remoteAddr, localAddr, sortUDP, checkPeer); } auto canThread = std::make_unique(debugOptions, canInterface); auto netFrameBuffer = std::make_unique(1000,16000); diff --git a/udpthread.cpp b/udpthread.cpp index 8c61893..936c899 100644 --- a/udpthread.cpp +++ b/udpthread.cpp @@ -91,7 +91,7 @@ bool UDPThread::parsePacket(uint8_t *buffer, uint16_t len, struct sockaddr_in &c } else { if ((memcmp(&(clientAddr.sin_addr), &(m_remoteAddr.sin_addr), sizeof(struct in_addr)) != 0) && m_checkPeer) { lwarn << "Received a packet from " << clientAddrStr - << ", which is not set as a remote." << std::endl; + << ", which is not set as a remote. Restart with -p argument to override." << std::endl; } else { if (m_debugOptions.udp) {