Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
functions.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_COMMS_IP_FUNCTIONS_HPP_
2#define IV_SRC_COMMS_IP_FUNCTIONS_HPP_
3
4#include <algorithm>
5#include <set>
6#include <string>
7#include <vector>
8
9namespace iv::comms::ip
10{
11
12bool isAllowedIP(const std::string &sourceIp, const std::set<std::string> &allowedIPs)
13{
14 static const std::vector<std::string> exceptions {"127.0.0.255", "127.0.0.1", "localhost", "::1", "0.0.0.0"};
15 static const auto findIp = [sourceIp](const std::string &ip) { return ip == sourceIp; };
16 return std::ranges::any_of(exceptions, findIp) || std::ranges::any_of(allowedIPs, findIp);
17}
18
19void showLANMessage(uint32_t timestamp, uint32_t msgId, const uint8_t *bytes)
20{
21#ifndef NDEBUG
22 char *chrEnv = getenv("SHOW_LAN_MESSAGE");
23
24 if (chrEnv != nullptr && strcmp(chrEnv, "1") == 0)
25 {
26 printf(">>>>> LAN >>>>> Time: %10u, ID: %08X, ", timestamp, msgId);
27 printf("Data: ");
28
29 for (int32_t bIndex = 0; bIndex < 8; bIndex++)
30 {
31 printf("%02X ", bytes[bIndex]);
32 }
33
34 printf("\n");
35 }
36#endif
37}
38}// namespace iv::comms::ip
39
40#endif//IV_SRC_COMMS_IP_FUNCTIONS_HPP_
Definition enums.hpp:5
bool isAllowedIP(const std::string &sourceIp, const std::set< std::string > &allowedIPs)
Definition functions.hpp:12
void showLANMessage(uint32_t timestamp, uint32_t msgId, const uint8_t *bytes)
Definition functions.hpp:19