@@ -1447,28 +1447,31 @@ static void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, v
1447
1447
}
1448
1448
1449
1449
/* *
1450
- * Resolve the given hostname to an IP address.
1451
- * @param aHostname Name to be resolved
1450
+ * Resolve the given hostname to an IP address. If passed hostname is an IP address, it will be parsed into IPAddress structure.
1451
+ * @param aHostname Name to be resolved or string containing IP address
1452
1452
* @param aResult IPAddress structure to store the returned IP address
1453
1453
* @return 1 if aIPAddrString was successfully converted to an IP address,
1454
1454
* else error code
1455
1455
*/
1456
1456
int WiFiGenericClass::hostByName (const char * aHostname, IPAddress& aResult)
1457
1457
{
1458
- ip_addr_t addr;
1459
- aResult = static_cast <uint32_t >(0 );
1460
- waitStatusBits (WIFI_DNS_IDLE_BIT, 16000 );
1461
- clearStatusBits (WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT);
1462
- err_t err = dns_gethostbyname (aHostname, &addr, &wifi_dns_found_callback, &aResult);
1463
- if (err == ERR_OK && addr.u_addr .ip4 .addr ) {
1464
- aResult = addr.u_addr .ip4 .addr ;
1465
- } else if (err == ERR_INPROGRESS) {
1466
- waitStatusBits (WIFI_DNS_DONE_BIT, 15000 ); // real internal timeout in lwip library is 14[s]
1467
- clearStatusBits (WIFI_DNS_DONE_BIT);
1468
- }
1469
- setStatusBits (WIFI_DNS_IDLE_BIT);
1470
- if ((uint32_t )aResult == 0 ){
1471
- log_e (" DNS Failed for %s" , aHostname);
1458
+ if (!aResult.fromString (aHostname))
1459
+ {
1460
+ ip_addr_t addr;
1461
+ aResult = static_cast <uint32_t >(0 );
1462
+ waitStatusBits (WIFI_DNS_IDLE_BIT, 16000 );
1463
+ clearStatusBits (WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT);
1464
+ err_t err = dns_gethostbyname (aHostname, &addr, &wifi_dns_found_callback, &aResult);
1465
+ if (err == ERR_OK && addr.u_addr .ip4 .addr ) {
1466
+ aResult = addr.u_addr .ip4 .addr ;
1467
+ } else if (err == ERR_INPROGRESS) {
1468
+ waitStatusBits (WIFI_DNS_DONE_BIT, 15000 ); // real internal timeout in lwip library is 14[s]
1469
+ clearStatusBits (WIFI_DNS_DONE_BIT);
1470
+ }
1471
+ setStatusBits (WIFI_DNS_IDLE_BIT);
1472
+ if ((uint32_t )aResult == 0 ){
1473
+ log_e (" DNS Failed for %s" , aHostname);
1474
+ }
1472
1475
}
1473
1476
return (uint32_t )aResult != 0 ;
1474
1477
}
0 commit comments