Skip to content

Commit

Permalink
Merge PR #25: add argument to disable peer checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mguentner committed Apr 29, 2020
2 parents 19fb3be + 7f5ec84 commit aa0f0ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions cannelloni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "make_unique.h"
#include <memory>

#define CANNELLONI_VERSION "1.0.0"
#define CANNELLONI_VERSION "1.0.1"

using namespace cannelloni;

Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -174,6 +178,9 @@ int main(int argc, char** argv) {
case 's':
sortUDP = true;
break;
case 'p':
checkPeer = false;
break;
default:
printUsage();
return -1;
Expand Down Expand Up @@ -279,7 +286,7 @@ int main(int argc, char** argv) {
netThread = std::make_unique<SCTPThread>(debugOptions, remoteAddr, localAddr, sortUDP, remoteIPSupplied, sctpRole);
#endif
} else {
netThread = std::make_unique<UDPThread>(debugOptions, remoteAddr, localAddr, sortUDP, true);
netThread = std::make_unique<UDPThread>(debugOptions, remoteAddr, localAddr, sortUDP, checkPeer);
}
auto canThread = std::make_unique<CANThread>(debugOptions, canInterface);
auto netFrameBuffer = std::make_unique<FrameBuffer>(1000,16000);
Expand Down
2 changes: 1 addition & 1 deletion udpthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit aa0f0ec

Please sign in to comment.