ESP32/ESP8266 Firewall 1.0.0
a software firewall for ESP23 or ESP8266
Utils.cpp
1#include "Utils.hpp"
2
3namespace fw
4{
5 String protocol_to_string(firewall_protocol_t &protocol)
6 {
7 switch (protocol)
8 {
9 case PROTOCOL_TCP:
10 return "TCP";
11 case PROTOCOL_UDP:
12 return "UDP";
13 default:
14 return "ALL";
15 }
16 }
17
18 firewall_protocol_t string_to_protocol(String &protocol)
19 {
20 if (protocol.equals("TCP"))
21 return PROTOCOL_TCP;
22 else if (protocol.equals("UDP"))
23 return PROTOCOL_UDP;
24 else
25 return PROTOCOL_ALL;
26 }
27
28 String target_to_string(firewall_target_t &target)
29 {
30 switch (target)
31 {
32 case TARGET_DROP:
33 return "DROP";
34 default:
35 return "ACCEPT";
36 }
37 }
38
39 firewall_target_t string_to_target(String &target)
40 {
41 if (target.equals("DROP"))
42 return TARGET_DROP;
43 else
44 return TARGET_ACCEPT;
45 }
46
47 void endless_loop()
48 {
49 Serial.printf("Something went wrong. Running endless loop until fixed...");
50 while (true)
51 delay(500);
52 }
53
54 bool is_in_range(const uint16_t number, const uint16_t lower, const uint16_t upper)
55 {
56 return lower <= number && number <= upper;
57 }
58}