Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
- Teleinfo TEMPO (BBR) contract (#17160)
- Support for HLK-LD2410 24GHz smart wave motion sensor
- Berry ``mdns`` module (#17202)
- IPv6 preview for ESP32, also working for ESP8266

### Changed
- Serial Bridge default internal serial rx buffer size from 64 to 256 (#17120)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,87 +77,71 @@

#include <IPAddress.h>
#include <lwip/netif.h>
#include "IPAddress46.h"

#if LWIP_IPV6
#define IF_NUM_ADDRESSES (1 + LWIP_IPV6_NUM_ADDRESSES)
#else
#define IF_NUM_ADDRESSES (1)
#endif


namespace esp8266
{

namespace AddressListImplementation
{


struct netifWrapper
{
netifWrapper (netif* netif) : _netif(netif), _num(-1) {}
netifWrapper (const netifWrapper& o) : _netif(o._netif), _num(o._num) {}

netifWrapper& operator= (const netifWrapper& o)
{
_netif = o._netif;
_num = o._num;
return *this;
}

bool equal(const netifWrapper& o)
{
return _netif == o._netif && (!_netif || _num == o._num);
}

// address properties
class IPAddress4 : public IPAddress
{
public:
bool isV6() const
{
return false;
}
bool isLocal() const
{
return false;
}
};
IPAddress4 addr () const { return ipFromNetifNum(); }
bool isLegacy () const { return _num == 0; }
//bool isLocal () const { return addr().isLocal(); }
bool isV4 () const { return addr().isV4(); }
bool isV6 () const { return !addr().isV4(); }
String toString() const { return addr().toString(); }

// related to legacy address (_num=0, ipv4)
IPAddress ipv4 () const { return _netif->ip_addr; }
IPAddress netmask () const { return _netif->netmask; }
IPAddress gw () const { return _netif->gw; }

// common to all addresses of this interface
String ifname () const { return String(_netif->name[0]) + _netif->name[1]; }
const char* ifhostname () const { return _netif->hostname?: emptyString.c_str(); }
const char* ifmac () const { return (const char*)_netif->hwaddr; }
int ifnumber () const { return _netif->num; }
bool ifUp () const { return !!(_netif->flags & NETIF_FLAG_UP); }
const netif* interface () const { return _netif; }

const ip_addr_t* ipFromNetifNum () const
{
netifWrapper (netif* netif) : _netif(netif), _num(-1) {}
netifWrapper (const netifWrapper& o) : _netif(o._netif), _num(o._num) {}

netifWrapper& operator= (const netifWrapper& o)
{
_netif = o._netif;
_num = o._num;
return *this;
}

bool equal(const netifWrapper& o)
{
return _netif == o._netif && (!_netif || _num == o._num);
}

IPAddress46 addr () const { return ipFromNetifNum(); }
bool isLegacy () const { return _num == 0; }
bool isLocal () const { return addr().isLocal(); }
bool isV4 () const { return addr().isV4(); }
bool isV6 () const { return !addr().isV4(); }
String toString() const { return addr().toString(); }

// related to legacy address (_num=0, ipv4)
IPAddress46 ipv4 () const { return _netif->ip_addr; }
IPAddress46 netmask () const { return _netif->netmask; }
IPAddress46 gw () const { return _netif->gw; }

// common to all addresses of this interface
String ifname () const { return String(_netif->name[0]) + _netif->name[1]; }
const char* ifhostname () const { return _netif->hostname?: emptyString.c_str(); }
const char* ifmac () const { return (const char*)_netif->hwaddr; }
int ifnumber () const { return _netif->num; }
bool ifUp () const { return !!(_netif->flags & NETIF_FLAG_UP); }
const netif* interface () const { return _netif; }

const ip_addr_t* ipFromNetifNum () const
{
#if LWIP_IPV6
return _num ? &_netif->ip6_addr[_num - 1] : &_netif->ip_addr;
return _num ? &_netif->ip6_addr[_num - 1] : &_netif->ip_addr;
#else
return &_netif->ip_addr;
return &_netif->ip_addr;
#endif
}
}

// lwIP interface
netif* _netif;
// lwIP interface
netif* _netif;

// address index within interface
// 0: legacy address (IPv4)
// n>0: (_num-1) is IPv6 index for netif->ip6_addr[]
int _num;
// address index within interface
// 0: legacy address (IPv4)
// n>0: (_num-1) is IPv6 index for netif->ip6_addr[]
int _num;
};


Expand Down Expand Up @@ -223,11 +207,10 @@ inline AddressList::const_iterator begin (const AddressList& a) { return a.begin
inline AddressList::const_iterator end (const AddressList& a) { return a.end(); }


} // AddressListImplementation

} // esp8266
} // namespace AddressListImplementation
} // namespace esp8266

extern AddressList addrList;
extern esp8266::AddressListImplementation::AddressList addrList;


#endif
3 changes: 0 additions & 3 deletions lib/libesp32/ESP32-to-ESP8266-compat/src/ESP8266WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#pragma once
#include <WiFi.h>

// sorry, no <AddrList.h>
#undef LWIP_IPV6

#define ENC_TYPE_NONE WIFI_AUTH_OPEN
#define ENC_TYPE_WEP WIFI_AUTH_WEP
#define ENC_TYPE_CCMP WIFI_AUTH_WPA2_PSK
Expand Down
Loading