]> git.sur5r.net Git - freertos/commitdiff
Allow IP address to be passed into gethostbyname().
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 18 Feb 2018 19:58:26 +0000 (19:58 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 18 Feb 2018 19:58:26 +0000 (19:58 +0000)
Ensure xNetworkBuffersInitialise() doesn't use a semaphore before it has been tested against NULL.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2529 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c

index a457b7b2fad2496aa4a94432bf9c0679c605699c..4ba27963e1ca67342db6dc4ef244d43d13196b03 100644 (file)
@@ -404,18 +404,29 @@ TickType_t xReadTimeOut_ms = 1200U;
  as gethostbyname() may be called from different threads */\r
 TickType_t xIdentifier = ( TickType_t )usIdentifier++;\r
 \r
+       /* If the supplied hostname is IP address, convert it to uint32_t\r
+       and return. */\r
+       #if( ipconfigINCLUDE_FULL_INET_ADDR == 1 )\r
+       {\r
+               ulIPAddress = FreeRTOS_inet_addr( pcHostName );\r
+       }\r
+       #endif /* ipconfigINCLUDE_FULL_INET_ADDR == 1 */\r
+\r
        /* If a DNS cache is used then check the cache before issuing another DNS\r
        request. */\r
        #if( ipconfigUSE_DNS_CACHE == 1 )\r
        {\r
-               ulIPAddress = FreeRTOS_dnslookup( pcHostName );\r
-               if( ulIPAddress != 0 )\r
-               {\r
-                       FreeRTOS_debug_printf( ( "FreeRTOS_gethostbyname: found '%s' in cache: %lxip\n", pcHostName, ulIPAddress ) );\r
-               }\r
-               else\r
+               if( ulIPAddress == 0UL )\r
                {\r
-                       /* prvGetHostByName will be called to start a DNS lookup. */\r
+                       ulIPAddress = FreeRTOS_dnslookup( pcHostName );\r
+                       if( ulIPAddress != 0 )\r
+                       {\r
+                               FreeRTOS_debug_printf( ( "FreeRTOS_gethostbyname: found '%s' in cache: %lxip\n", pcHostName, ulIPAddress ) );\r
+                       }\r
+                       else\r
+                       {\r
+                               /* prvGetHostByName will be called to start a DNS lookup */\r
+                       }\r
                }\r
        }\r
        #endif /* ipconfigUSE_DNS_CACHE == 1 */\r
index 16ece71495d2bf04d4c1ca6fe43aace9131eece5..63da970b8bf23fd8176d239139af391d395e40b1 100644 (file)
@@ -103,24 +103,25 @@ BaseType_t xReturn, x;
        {\r
                xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );\r
                configASSERT( xNetworkBufferSemaphore );\r
-               #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
-               {\r
-                       vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" );\r
-               }\r
-               #endif /* configQUEUE_REGISTRY_SIZE */\r
-\r
-               /* If the trace recorder code is included name the semaphore for viewing\r
-               in FreeRTOS+Trace.  */\r
-               #if( ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 )\r
-               {\r
-                       extern QueueHandle_t xNetworkEventQueue;\r
-                       vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );\r
-                       vTraceSetQueueName( xNetworkBufferSemaphore, "NetworkBufferCount" );\r
-               }\r
-               #endif /*  ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */\r
 \r
                if( xNetworkBufferSemaphore != NULL )\r
                {\r
+                       #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
+                       {\r
+                               vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" );\r
+                       }\r
+                       #endif /* configQUEUE_REGISTRY_SIZE */\r
+\r
+                       /* If the trace recorder code is included name the semaphore for viewing\r
+                       in FreeRTOS+Trace.  */\r
+                       #if( ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 )\r
+                       {\r
+                               extern QueueHandle_t xNetworkEventQueue;\r
+                               vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );\r
+                               vTraceSetQueueName( xNetworkBufferSemaphore, "NetworkBufferCount" );\r
+                       }\r
+                       #endif /*  ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */\r
+\r
                        vListInitialise( &xFreeBuffersList );\r
 \r
                        /* Initialise all the network buffers.  No storage is allocated to\r
@@ -374,7 +375,7 @@ uint8_t *pucBuffer;
                vReleaseNetworkBuffer( pxNetworkBuffer->pucEthernetBuffer );\r
                pxNetworkBuffer->pucEthernetBuffer = pucBuffer;\r
        }\r
-       \r
+\r
        return pxNetworkBuffer;\r
 }\r
 \r