1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Fixed DNS issue

This commit is contained in:
Mimmo La Fauci 2012-03-15 01:18:43 +01:00
parent a984979b11
commit 84403e2512
6 changed files with 97 additions and 16 deletions

View File

@ -175,4 +175,9 @@ uint8_t WiFiClass::status()
return WiFiDrv::getConnectionStatus();
}
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
{
return WiFiDrv::getHostByName(aHostname, aResult);
}
WiFiClass WiFi;

View File

@ -159,6 +159,15 @@ public:
*/
uint8_t status();
/*
* Resolve the given hostname to an IP address.
* param aHostname: Name to be resolved
* param aResult: IPAddress structure to store the returned IP address
* result: 1 if aIPAddrString was successfully converted to an IP address,
* else error code
*/
int hostByName(const char* aHostname, IPAddress& aResult);
friend class WiFiClient;
friend class WiFiServer;
};

View File

@ -21,22 +21,12 @@ WiFiClient::WiFiClient(uint8_t sock) : _sock(sock) {
}
int WiFiClient::connect(const char* host, uint16_t port) {
/* TODO Add DNS wifi spi function to resolve DNS */
#if 0
// Look up the host first
int ret = 0;
DNSClient dns;
IPAddress remote_addr;
dns.begin(Ethernet.dnsServerIP());
ret = dns.getHostByName(host, remote_addr);
if (ret == 1) {
return connect(remote_addr, port);
} else {
return ret;
}
#endif
return 0;
IPAddress remote_addr;
if (WiFi.hostByName(host, remote_addr))
{
return connect(remote_addr, port);
}
return 0;
}
int WiFiClient::connect(IPAddress ip, uint16_t port) {

View File

@ -376,4 +376,66 @@ int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem)
return networkRssi;
}
uint8_t WiFiDrv::reqHostByName(const char* aHostname)
{
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1);
SpiDrv::sendParam((uint8_t*)aHostname, strlen(aHostname), LAST_PARAM);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _data = 0;
uint8_t _dataLen = 0;
uint8_t result = SpiDrv::waitResponseCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1, &_data, &_dataLen);
SpiDrv::spiSlaveDeselect();
return result;
}
int WiFiDrv::getHostByName(IPAddress& aResult)
{
uint8_t _ipAddr[WL_IPV4_LENGTH];
IPAddress dummy(0xFF,0xFF,0xFF,0xFF);
int result = 0;
WAIT_FOR_SLAVE_SELECT();
// Send Command
SpiDrv::sendCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_0);
//Wait the reply elaboration
SpiDrv::waitForSlaveReady();
// Wait for reply
uint8_t _dataLen = 0;
if (!SpiDrv::waitResponseCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_1, _ipAddr, &_dataLen))
{
WARN("error waitResponse");
}else{
aResult = _ipAddr;
result = (aResult != dummy);
}
SpiDrv::spiSlaveDeselect();
return result;
}
int WiFiDrv::getHostByName(const char* aHostname, IPAddress& aResult)
{
uint8_t retry = 10;
if (reqHostByName(aHostname))
{
while(!getHostByName(aResult) && --retry > 0)
{
delay(500);
}
}else{
return 0;
}
return 1;
}
WiFiDrv wiFiDrv;

View File

@ -31,6 +31,10 @@ private:
*/
static void getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip);
static uint8_t reqHostByName(const char* aHostname);
static int getHostByName(IPAddress& aResult);
public:
/*
@ -181,6 +185,15 @@ public:
*/
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
/*
* Resolve the given hostname to an IP address.
* param aHostname: Name to be resolved
* param aResult: IPAddress structure to store the returned IP address
* result: 1 if aIPAddrString was successfully converted to an IP address,
* else error code
*/
static int getHostByName(const char* aHostname, IPAddress& aResult);
};
extern WiFiDrv wiFiDrv;

View File

@ -45,6 +45,8 @@ enum {
GET_IDX_SSID_CMD = 0x31,
GET_IDX_RSSI_CMD = 0x32,
GET_IDX_ENCT_CMD = 0x33,
REQ_HOST_BY_NAME_CMD= 0x34,
GET_HOST_BY_NAME_CMD= 0x35,
// All command with DATA_FLAG 0x40 send a 16bit Len