Skip to content

Commit a2a6bd8

Browse files
committed
Implement some Tasmota requirements
Added constructor that takes `const ip_addr_t *`. Added `addr_type()` getter Organize header to highlight the Espressif additions to IPAddress
1 parent 04a2034 commit a2a6bd8

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

cores/esp32/IPAddress.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ size_t IPAddress::printTo(Print& p, bool includeZone) const
380380
return n;
381381
}
382382

383+
IPAddress::IPAddress(const ip_addr_t *addr){
384+
from_ip_addr_t(addr);
385+
}
386+
383387
void IPAddress::to_ip_addr_t(ip_addr_t* addr) const {
384388
if(_type == IPv6){
385389
addr->type = IPADDR_TYPE_V6;
@@ -396,7 +400,7 @@ void IPAddress::to_ip_addr_t(ip_addr_t* addr) const {
396400
}
397401
}
398402

399-
IPAddress& IPAddress::from_ip_addr_t(ip_addr_t* addr){
403+
IPAddress& IPAddress::from_ip_addr_t(const ip_addr_t* addr){
400404
if(addr->type == IPADDR_TYPE_V6){
401405
_type = IPv6;
402406
_address.dword[0] = addr->u_addr.ip6.addr[0];
@@ -413,5 +417,14 @@ IPAddress& IPAddress::from_ip_addr_t(ip_addr_t* addr){
413417
return *this;
414418
}
415419

420+
esp_ip6_addr_type_t IPAddress::addr_type(){
421+
if(_type != IPv6){
422+
return ESP_IP6_ADDR_IS_UNKNOWN;
423+
}
424+
ip_addr_t addr;
425+
to_ip_addr_t(&addr);
426+
return esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)(&(addr.u_addr.ip6)));
427+
}
428+
416429
const IPAddress IN6ADDR_ANY(IPv6);
417430
const IPAddress INADDR_NONE(0,0,0,0);

cores/esp32/IPAddress.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Printable.h"
2424
#include "WString.h"
2525
#include "lwip/ip_addr.h"
26+
#include "esp_netif_ip_addr.h"
2627

2728
#define IPADDRESS_V4_BYTES_INDEX 12
2829
#define IPADDRESS_V4_DWORD_INDEX 3
@@ -93,16 +94,17 @@ class IPAddress : public Printable {
9394
IPAddress& operator=(const IPAddress& address);
9495

9596
virtual size_t printTo(Print& p) const;
96-
size_t printTo(Print& p, bool includeZone) const;
9797
String toString(bool includeZone = false) const;
9898

9999
IPType type() const { return _type; }
100100

101-
uint8_t zone() const { return (type() == IPv6)?_zone:0; }
102-
103-
// LwIP conversions
101+
// Espresif LwIP conversions
102+
IPAddress(const ip_addr_t *addr);
104103
void to_ip_addr_t(ip_addr_t* addr) const;
105-
IPAddress& from_ip_addr_t(ip_addr_t* addr);
104+
IPAddress& from_ip_addr_t(const ip_addr_t* addr);
105+
esp_ip6_addr_type_t addr_type();
106+
uint8_t zone() const { return (type() == IPv6)?_zone:0; }
107+
size_t printTo(Print& p, bool includeZone) const;
106108

107109
friend class UDP;
108110
friend class Client;

0 commit comments

Comments
 (0)