Skip to content

This is a continuation on the topic of adding IPv6 Support to ESP32 Arduino #9016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7b42a93
IPv6 for Arduino 3.0.0
Jason2866 Nov 21, 2023
12be369
Fix warning in WifiUdp
s-hadinger Nov 21, 2023
5987211
remove comment / formating
Jason2866 Nov 22, 2023
b8cc73c
Add zone to IPAddress and update WiFiUDP and WiFiGeneric
me-no-dev Dec 18, 2023
305d276
Add from ip_addr_t conversion and better toString implementation
me-no-dev Dec 18, 2023
41fb1a1
Use constant for IPAddress offset
me-no-dev Dec 18, 2023
b37ce6c
Combine hostByName to support both IPv6 and IPv4 results
me-no-dev Dec 18, 2023
e333afb
implement logic to use v6 dns only when global v6 address is assigned…
me-no-dev Jan 11, 2024
c7e63e6
Rename softAPenableIPv6
me-no-dev Jan 11, 2024
55aaa6f
Rename mDNS methods
me-no-dev Jan 11, 2024
c4f366c
fix IPAddress method to work with const address
me-no-dev Jan 11, 2024
701d35f
Some cleanup and do not print zone in IPAddress
me-no-dev Jan 11, 2024
a1b3f16
Merge branch 'master' into feature/ipv6_support
me-no-dev Jan 11, 2024
cb381f2
rename WiFiMulti method
me-no-dev Jan 11, 2024
726496c
Fix AP DHCPS not properly working on recent IDF
me-no-dev Jan 11, 2024
9012f64
Add option to print the zone at the end of IPv6
me-no-dev Jan 11, 2024
58520a7
remove log prints from hostByName
me-no-dev Jan 11, 2024
aad1041
Use correct array length for listing IPv6 addresses
me-no-dev Jan 12, 2024
04a2034
Merge branch 'master' into feature/ipv6_support
me-no-dev Jan 12, 2024
a2a6bd8
Implement some Tasmota requirements
me-no-dev Jan 14, 2024
1fb442d
add 'const' to IPAddress::addr_type()
me-no-dev Jan 14, 2024
0df3aaa
Fix WiFiUdp not updating mapped v4 address
me-no-dev Jan 15, 2024
4161873
Update WiFiServer.cpp
me-no-dev Jan 15, 2024
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
15 changes: 14 additions & 1 deletion cores/esp32/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ size_t IPAddress::printTo(Print& p, bool includeZone) const
return n;
}

IPAddress::IPAddress(const ip_addr_t *addr){
from_ip_addr_t(addr);
}

void IPAddress::to_ip_addr_t(ip_addr_t* addr) const {
if(_type == IPv6){
addr->type = IPADDR_TYPE_V6;
Expand All @@ -396,7 +400,7 @@ void IPAddress::to_ip_addr_t(ip_addr_t* addr) const {
}
}

IPAddress& IPAddress::from_ip_addr_t(ip_addr_t* addr){
IPAddress& IPAddress::from_ip_addr_t(const ip_addr_t* addr){
if(addr->type == IPADDR_TYPE_V6){
_type = IPv6;
_address.dword[0] = addr->u_addr.ip6.addr[0];
Expand All @@ -413,5 +417,14 @@ IPAddress& IPAddress::from_ip_addr_t(ip_addr_t* addr){
return *this;
}

esp_ip6_addr_type_t IPAddress::addr_type(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this function then be named ip6_addr_type() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TD-er we are procrastinating at this point... I like it the way it is. This PR needs to be merged already so we can progress further. Let's not get overly picky?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just mentioned it as it is a "breaking change" whenever it needs to be changed after this has been merged.

Also shouldn't it be a const function?
Or does the Espressif code prohibit this (maybe you could use a const_cast)

Anyway, do you plan on making a follow-up on this topic after it is merged?
I get it that this is blocking for your other PR with the network rework, so I do see the need for a quick merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can revisit everything after the overhaul. Let's get to use it a bit and see what would need adjusting.

if(_type != IPv6){
return ESP_IP6_ADDR_IS_UNKNOWN;
}
ip_addr_t addr;
to_ip_addr_t(&addr);
return esp_netif_ip6_get_addr_type((esp_ip6_addr_t*)(&(addr.u_addr.ip6)));
}

const IPAddress IN6ADDR_ANY(IPv6);
const IPAddress INADDR_NONE(0,0,0,0);
12 changes: 7 additions & 5 deletions cores/esp32/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Printable.h"
#include "WString.h"
#include "lwip/ip_addr.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to have a separate IPAddressConverter class, that converts to & from LWIP? That would mean you don't need the dependency here. Just an idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it make more sense to have a constructor accepting the LWIP implementation and some set/get-functions?
If you want, you can also wrap those in some #ifdef or #if check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it now as it is. It has the conversion methods and is not a big deal to make them used in constructors, but I would rather not pollute the class with non-Arduino things.

#include "esp_netif_ip_addr.h"

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

virtual size_t printTo(Print& p) const;
size_t printTo(Print& p, bool includeZone) const;
String toString(bool includeZone = false) const;

IPType type() const { return _type; }

uint8_t zone() const { return (type() == IPv6)?_zone:0; }

// LwIP conversions
// Espresif LwIP conversions
IPAddress(const ip_addr_t *addr);
void to_ip_addr_t(ip_addr_t* addr) const;
IPAddress& from_ip_addr_t(ip_addr_t* addr);
IPAddress& from_ip_addr_t(const ip_addr_t* addr);
esp_ip6_addr_type_t addr_type();
uint8_t zone() const { return (type() == IPv6)?_zone:0; }
size_t printTo(Print& p, bool includeZone) const;

friend class UDP;
friend class Client;
Expand Down