@@ -617,7 +617,47 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
617
617
}
618
618
619
619
DEBUG_WIFI_GENERIC (" [hostByName] request IP for: %s\n " , aHostname);
620
+ #if LWIP_IPV4 && LWIP_IPV6
621
+ err_t err = dns_gethostbyname_addrtype (aHostname, &addr, &wifi_dns_found_callback, &aResult,LWIP_DNS_ADDRTYPE_DEFAULT);
622
+ #else
620
623
err_t err = dns_gethostbyname (aHostname, &addr, &wifi_dns_found_callback, &aResult);
624
+ #endif
625
+ if (err == ERR_OK) {
626
+ aResult = IPAddress (&addr);
627
+ } else if (err == ERR_INPROGRESS) {
628
+ _dns_lookup_pending = true ;
629
+ delay (timeout_ms);
630
+ // will resume on timeout or when wifi_dns_found_callback fires
631
+ _dns_lookup_pending = false ;
632
+ // will return here when dns_found_callback fires
633
+ if (aResult.isSet ()) {
634
+ err = ERR_OK;
635
+ }
636
+ }
637
+
638
+ if (err != 0 ) {
639
+ DEBUG_WIFI_GENERIC (" [hostByName] Host: %s lookup error: %d!\n " , aHostname, (int )err);
640
+ } else {
641
+ DEBUG_WIFI_GENERIC (" [hostByName] Host: %s IP: %s\n " , aHostname, aResult.toString ().c_str ());
642
+ }
643
+
644
+ return (err == ERR_OK) ? 1 : 0 ;
645
+ }
646
+
647
+ #if LWIP_IPV4 && LWIP_IPV6
648
+ int ESP8266WiFiGenericClass::hostByName (const char * aHostname, IPAddress& aResult, uint32_t timeout_ms, uint8_t resolveType)
649
+ {
650
+ ip_addr_t addr;
651
+ aResult = static_cast <uint32_t >(0 );
652
+
653
+ if (aResult.fromString (aHostname)) {
654
+ // Host name is a IP address use it!
655
+ DEBUG_WIFI_GENERIC (" [hostByName] Host: %s is a IP!\n " , aHostname);
656
+ return 1 ;
657
+ }
658
+
659
+ DEBUG_WIFI_GENERIC (" [hostByName] request IP for: %s\n " , aHostname);
660
+ err_t err = dns_gethostbyname_addrtype (aHostname, &addr, &wifi_dns_found_callback, &aResult,resolveType & 3 ); // limit to defined types 0 -3
621
661
if (err == ERR_OK) {
622
662
aResult = IPAddress (&addr);
623
663
} else if (err == ERR_INPROGRESS) {
@@ -639,6 +679,7 @@ int ESP8266WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResul
639
679
640
680
return (err == ERR_OK) ? 1 : 0 ;
641
681
}
682
+ #endif
642
683
643
684
/* *
644
685
* DNS callback
0 commit comments