Browse Source

IP4 class: ensure it really is an IPv4 address

Make sure we don't accidentally get confused by IPv6 addresses
returned by DNS queries.
H. Peter Anvin 1 year ago
parent
commit
0aaa831586
5 changed files with 4 additions and 2 deletions
  1. 4 2
      esp32/max80/IP4.h
  2. BIN
      esp32/output/max80.ino.bin
  3. BIN
      fpga/output/max80.fw
  4. BIN
      fpga/output/v1.fw
  5. BIN
      fpga/output/v2.fw

+ 4 - 2
esp32/max80/IP4.h

@@ -24,8 +24,10 @@ public:
     constexpr IP4(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) :
 	b{b0,b1,b2,b3} { }
     IP4(const IPAddress & ip) : l{ip} { }
-    constexpr IP4(const ip_addr_t & ip) : l{ip.u_addr.ip4.addr} { }
-    constexpr IP4(const esp_ip_addr_t & ip) : l{ip.u_addr.ip4.addr} { }
+    constexpr IP4(const ip_addr_t & ip) :
+	l{ip.type == IPADDR_TYPE_V4 ? ip.u_addr.ip4.addr : 0} { }
+    constexpr IP4(const esp_ip_addr_t & ip) :
+	l{ip.type == IPADDR_TYPE_V4 ? ip.u_addr.ip4.addr : 0} { }
     IP4(const char *str);
 
     operator uint32_t () { return l; }

BIN
esp32/output/max80.ino.bin


BIN
fpga/output/max80.fw


BIN
fpga/output/v1.fw


BIN
fpga/output/v2.fw