-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Changes from 1 commit
7b42a93
12be369
5987211
b8cc73c
305d276
41fb1a1
b37ce6c
e333afb
c7e63e6
55aaa6f
c4f366c
701d35f
a1b3f16
cb381f2
726496c
9012f64
58520a7
aad1041
04a2034
a2a6bd8
1fb442d
0df3aaa
4161873
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1546,10 +1546,12 @@ bool WiFiGenericClass::setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2 | |
| // ------------------------------------------------ Generic Network function --------------------------------------------- | ||
| // ----------------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| struct dns_api_msg6 { | ||
| ip_addr_t ip_addr; | ||
| typedef struct gethostbynameParameters { | ||
| const char *hostname; | ||
| ip_addr_t addr; | ||
| uint8_t addr_type; | ||
| int result; | ||
| }; | ||
| } gethostbynameParameters_t; | ||
|
|
||
| /** | ||
| * DNS callback | ||
|
|
@@ -1559,45 +1561,26 @@ struct dns_api_msg6 { | |
| */ | ||
| static void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg) | ||
| { | ||
| gethostbynameParameters_t *parameters = static_cast<gethostbynameParameters_t *>(callback_arg); | ||
| if(ipaddr) { | ||
| (*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->u_addr.ip4.addr; | ||
| if(parameters->result == 0){ | ||
| memcpy(&(parameters->addr), ipaddr, sizeof(ip_addr_t)); | ||
| parameters->result = 1; | ||
| } | ||
| } else { | ||
| parameters->result = -1; | ||
| } | ||
| xEventGroupSetBits(_arduino_event_group, WIFI_DNS_DONE_BIT); | ||
| } | ||
|
|
||
| typedef struct gethostbynameParameters { | ||
| const char *hostname; | ||
| ip_addr_t addr; | ||
| void *callback_arg; | ||
| } gethostbynameParameters_t; | ||
|
|
||
| /** | ||
| * Callback to execute dns_gethostbyname in lwIP's TCP/IP context | ||
| * @param param Parameters for dns_gethostbyname call | ||
| */ | ||
| static esp_err_t wifi_gethostbyname_tcpip_ctx(void *param) | ||
| { | ||
| gethostbynameParameters_t *parameters = static_cast<gethostbynameParameters_t *>(param); | ||
| return dns_gethostbyname(parameters->hostname, ¶meters->addr, &wifi_dns_found_callback, parameters->callback_arg); | ||
| } | ||
|
|
||
| /** | ||
| * IPv6 compatible DNS callback | ||
| * @param name | ||
| * @param ipaddr | ||
| * @param callback_arg | ||
| */ | ||
| static void wifi_dns6_found_callback(const char *name, const ip_addr_t *ipaddr, void *callback_arg) | ||
| { | ||
| struct dns_api_msg6 *msg = (struct dns_api_msg6 *)callback_arg; | ||
|
|
||
| if(ipaddr && !msg->result) { | ||
| msg->ip_addr = *ipaddr; | ||
| msg->result = 1; | ||
| } else { | ||
| msg->result = -1; | ||
| } | ||
| xEventGroupSetBits(_arduino_event_group, WIFI_DNS_DONE_BIT); | ||
| return dns_gethostbyname_addrtype(parameters->hostname, ¶meters->addr, &wifi_dns_found_callback, parameters, parameters->addr_type); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1607,60 +1590,39 @@ static void wifi_dns6_found_callback(const char *name, const ip_addr_t *ipaddr, | |
| * @return 1 if aIPAddrString was successfully converted to an IP address, | ||
| * else error code | ||
| */ | ||
| int WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult) | ||
| int WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult, bool preferV6) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry about changing the signature here. It means that every app that uses this code needs to change. Even if they don't want or aren't ready for IPv6. Rather than add this parameter, can we just do a check inside this function: params.addre_type = (WiFiGenericClass::getStatusBits() & WIFI_WANT_IP6_BIT) ? LWIP_DNS_ADDRTYPE_IPV6_IPV4 : LWIP_DNS_ADDRTYPE_IPV4; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you again looking at the implementation... in the header a default value is given There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you could make it an optional parameter with some define as default. The if-no-defined-Arduino-default could then be Or add a 2nd function signature which then uses a static defined bool (which can be set by the user at runtime) to call the function with this bool argument. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TD-er read my comment. nothing needs to be done. default values are defined in headers, not in source files There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, read your post after a reload of the page. (there is another post here where you even 'beat' me to it by about 45 mins which did not show up when I typed my reply) |
||
| { | ||
| if (!aResult.fromString(aHostname)) | ||
| { | ||
| gethostbynameParameters_t params; | ||
| params.hostname = aHostname; | ||
| params.callback_arg = &aResult; | ||
| aResult = static_cast<uint32_t>(0); | ||
| err_t err = ERR_OK; | ||
| gethostbynameParameters_t params; | ||
|
|
||
| aResult = static_cast<uint32_t>(0); | ||
| params.hostname = aHostname; | ||
| params.addr_type = preferV6?LWIP_DNS_ADDRTYPE_IPV6_IPV4:LWIP_DNS_ADDRTYPE_IPV4_IPV6; | ||
|
||
| params.result = 0; | ||
| aResult.to_ip_addr_t(&(params.addr)); | ||
|
|
||
| if (!aResult.fromString(aHostname)) { | ||
| waitStatusBits(WIFI_DNS_IDLE_BIT, 16000); | ||
| clearStatusBits(WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT); | ||
| err_t err = esp_netif_tcpip_exec(wifi_gethostbyname_tcpip_ctx, ¶ms); | ||
| if(err == ERR_OK && params.addr.u_addr.ip4.addr) { | ||
| aResult = params.addr.u_addr.ip4.addr; | ||
| } else if(err == ERR_INPROGRESS) { | ||
|
|
||
| err = esp_netif_tcpip_exec(wifi_gethostbyname_tcpip_ctx, ¶ms); | ||
| if (err == ERR_OK) { | ||
| aResult.from_ip_addr_t(&(params.addr)); | ||
| } else if (err == ERR_INPROGRESS) { | ||
| waitStatusBits(WIFI_DNS_DONE_BIT, 15000); //real internal timeout in lwip library is 14[s] | ||
| clearStatusBits(WIFI_DNS_DONE_BIT); | ||
| if (params.result == 1) { | ||
| aResult.from_ip_addr_t(&(params.addr)); | ||
| err = ERR_OK; | ||
| } | ||
| } | ||
| setStatusBits(WIFI_DNS_IDLE_BIT); | ||
| if((uint32_t)aResult == 0){ | ||
| log_e("DNS Failed for %s", aHostname); | ||
| } | ||
| } | ||
| return (uint32_t)aResult != 0; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the given hostname to an IP6 address. | ||
| * @param aHostname Name to be resolved | ||
| * @param aResult IPv6Address structure to store the returned IP address | ||
| * @return 1 if aHostname was successfully converted to an IP address, | ||
| * else error code | ||
| */ | ||
| int WiFiGenericClass::hostByName6(const char* aHostname, ip_addr_t& aResult) | ||
| { | ||
| ip_addr_t addr; | ||
| struct dns_api_msg6 arg; | ||
|
|
||
| memset(&arg, 0x0, sizeof(arg)); | ||
| waitStatusBits(WIFI_DNS_IDLE_BIT, 16000); | ||
| clearStatusBits(WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT); | ||
|
|
||
| err_t err = dns_gethostbyname_addrtype(aHostname, &addr, &wifi_dns6_found_callback, | ||
| &arg, LWIP_DNS_ADDRTYPE_IPV6_IPV4); | ||
| if(err == ERR_OK) { | ||
| aResult = addr; | ||
| } else if(err == ERR_INPROGRESS) { | ||
| waitStatusBits(WIFI_DNS_DONE_BIT, 15000); //real internal timeout in lwip library is 14[s] | ||
| clearStatusBits(WIFI_DNS_DONE_BIT); | ||
| if (arg.result == 1) { | ||
| aResult = arg.ip_addr; | ||
| } | ||
| if (err == ERR_OK) { | ||
| return 1; | ||
| } | ||
| setStatusBits(WIFI_DNS_IDLE_BIT); | ||
| return (uint32_t)err == ERR_OK || (err == ERR_INPROGRESS && arg.result == 1); | ||
| log_e("DNS Failed for '%s' with error '%d' and result '%d'", aHostname, err, params.result); | ||
| return err; | ||
| } | ||
|
|
||
| IPAddress WiFiGenericClass::calculateNetworkID(IPAddress ip, IPAddress subnet) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than change the signature, do the check for (WiFiGenericClass::getStatusBits() & WIFI_WANT_IP6_BIT) inside WiFiGeneric
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. left there to remind me to ask for discussion