cc3000 hostdriver with the mbed socket interface

Dependents:   cc3000_hello_world_demo cc3000_simple_socket_demo cc3000_ntp_demo cc3000_ping_demo ... more

Files at this revision

API Documentation at this revision

Comitter:
SolderSplashLabs
Date:
Wed Oct 02 21:57:28 2013 +0000
Parent:
17:14b6a3a2b622
Child:
19:9fdf8b4e41bf
Child:
21:fb34ac8d9af5
Commit message:
Websocket demo showed that if gethostbyname failed and returned 0.0.0.0 it still went ahead. Added checking to the gethostbyname call in Endpoint.cpp

Changed in this revision

Socket/Endpoint.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/Endpoint.cpp	Wed Oct 02 20:29:31 2013 +0200
+++ b/Socket/Endpoint.cpp	Wed Oct 02 21:57:28 2013 +0000
@@ -78,6 +78,7 @@
 int Endpoint::set_address(const char* host, const int port) {
     reset_address();
 
+    int resolveRetCode;
     char address[5];
     char *p_address = address;
 
@@ -93,15 +94,25 @@
     if (result != 4) {
         //Resolve DNS address or populate hard-coded IP address
         uint32_t address_integer;
-        _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer);
-
-        uint32_t ip = 0;
-        ip = (ip | (address_integer >> 24));
-        ip = (ip | ((address_integer & 0x00FF0000) >> 8));
-        ip = (ip | ((address_integer & 0x0000FF00) << 8));
-        ip = (ip | ((address_integer & 0x000000FF) << 24));
-        _remote_host.sin_addr.s_addr = ip;
-        inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
+        resolveRetCode = _cc3000_module->_socket.gethostbyname((uint8_t *)host, strlen(host) , &address_integer);
+        
+        if ((resolveRetCode > -1) && ( 0 != address_integer ))
+        {
+            // Resolved address
+            uint32_t ip = 0;
+            ip = (ip | (address_integer >> 24));
+            ip = (ip | ((address_integer & 0x00FF0000) >> 8));
+            ip = (ip | ((address_integer & 0x0000FF00) << 8));
+            ip = (ip | ((address_integer & 0x000000FF) << 24));
+            _remote_host.sin_addr.s_addr = ip;
+            inet_ntoa_r(_remote_host.sin_addr, _ipAddress, sizeof(_ipAddress));
+        }
+        else
+        {
+            // Failed to resolve the address
+            DBG_SOCKET("Failed to resolve the hostname : %s",host);
+            return ( -1 );
+        }
     } else {
         std::memcpy((char*)&_remote_host.sin_addr.s_addr, p_address, 4);
     }