@@ -271,12 +271,8 @@ void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress,
271271 uint8_t ucMinAgeFound = 0U ;
272272
273273 #if ( ipconfigARP_STORES_REMOTE_ADDRESSES == 0 )
274-
275- /* Only process the IP address if it is on the local network.
276- * Unless: when '*ipLOCAL_IP_ADDRESS_POINTER' equals zero, the IP-address
277- * and netmask are still unknown. */
278- if ( ( ( ulIPAddress & xNetworkAddressing .ulNetMask ) == ( ( * ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing .ulNetMask ) ) ||
279- ( * ipLOCAL_IP_ADDRESS_POINTER == 0UL ) )
274+ /* Only process the IP address if it is on the local network. */
275+ if ( ( ulIPAddress & xNetworkAddressing .ulNetMask ) == ( ( * ipLOCAL_IP_ADDRESS_POINTER ) & xNetworkAddressing .ulNetMask ) )
280276 #else
281277
282278 /* If ipconfigARP_STORES_REMOTE_ADDRESSES is non-zero, IP addresses with
@@ -492,16 +488,6 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
492488
493489 ulAddressToLookup = * pulIPAddress ;
494490
495- #if ( ipconfigUSE_LLMNR == 1 )
496- if ( ulAddressToLookup == ipLLMNR_IP_ADDR ) /* Is in network byte order. */
497- {
498- /* The LLMNR IP-address has a fixed virtual MAC address. */
499- ( void ) memcpy ( pxMACAddress -> ucBytes , xLLMNR_MacAdress .ucBytes , sizeof ( MACAddress_t ) );
500- eReturn = eARPCacheHit ;
501- }
502- else
503- #endif
504-
505491 if ( xIsIPv4Multicast ( ulAddressToLookup ) != 0 )
506492 {
507493 /* Get the lowest 23 bits of the IP-address. */
@@ -522,6 +508,12 @@ eARPLookupResult_t eARPGetCacheEntry( uint32_t * pulIPAddress,
522508 * can be done. */
523509 eReturn = eCantSendPacket ;
524510 }
511+ else if ( * ipLOCAL_IP_ADDRESS_POINTER == * pulIPAddress )
512+ {
513+ /* The address of this device. May be useful for the loopback device. */
514+ eReturn = eARPCacheHit ;
515+ memcpy ( pxMACAddress -> ucBytes , ipLOCAL_MAC_ADDRESS , sizeof ( pxMACAddress -> ucBytes ) );
516+ }
525517 else
526518 {
527519 eReturn = eARPCacheMiss ;
@@ -747,7 +739,7 @@ void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress )
747739 }
748740 #endif /* if defined( ipconfigETHERNET_MINIMUM_PACKET_BYTES ) */
749741
750- if ( xIsCallingFromIPTask () != 0 )
742+ if ( xIsCallingFromIPTask () != pdFALSE )
751743 {
752744 iptraceNETWORK_INTERFACE_OUTPUT ( pxNetworkBuffer -> xDataLength , pxNetworkBuffer -> pucEthernetBuffer );
753745 /* Only the IP-task is allowed to call this function directly. */
@@ -769,7 +761,63 @@ void FreeRTOS_OutputARPRequest( uint32_t ulIPAddress )
769761 }
770762 }
771763}
772- /*--------------------------------------*/
764+ /*-----------------------------------------------------------*/
765+
766+ /**
767+ * @brief Wait for address resolution: look-up the IP-address in the ARP-cache, and if
768+ * needed send an ARP request, and wait for a reply. This function is useful when
769+ * called before FreeRTOS_sendto().
770+ *
771+ * @param[in] ulIPAddress: The IP-address to look-up.
772+ * @param[in] uxTicksToWait: The maximum number of clock ticks to wait for a reply.
773+ *
774+ * @return Zero when successful.
775+ */
776+ BaseType_t xARPWaitResolution ( uint32_t ulIPAddress ,
777+ TickType_t uxTicksToWait )
778+ {
779+ BaseType_t xResult = - pdFREERTOS_ERRNO_EADDRNOTAVAIL ;
780+ TimeOut_t xTimeOut ;
781+ MACAddress_t xMACAddress ;
782+ eARPLookupResult_t xLookupResult ;
783+ size_t uxSendCount = ipconfigMAX_ARP_RETRANSMISSIONS ;
784+
785+ /* The IP-task is not supposed to call this function. */
786+ configASSERT ( xIsCallingFromIPTask () == pdFALSE );
787+
788+ xLookupResult = eARPGetCacheEntry ( & ( ulIPAddress ), & ( xMACAddress ) );
789+
790+ if ( xLookupResult == eARPCacheMiss )
791+ {
792+ const TickType_t uxSleepTime = pdMS_TO_TICKS ( 250U );
793+
794+ /* We might use ipconfigMAX_ARP_RETRANSMISSIONS here. */
795+ vTaskSetTimeOutState ( & xTimeOut );
796+
797+ while ( uxSendCount > 0 )
798+ {
799+ FreeRTOS_OutputARPRequest ( ulIPAddress );
800+
801+ vTaskDelay ( uxSleepTime );
802+
803+ xLookupResult = eARPGetCacheEntry ( & ( ulIPAddress ), & ( xMACAddress ) );
804+
805+ if ( ( xTaskCheckForTimeOut ( & ( xTimeOut ), & ( uxTicksToWait ) ) == pdTRUE ) ||
806+ ( xLookupResult != eARPCacheMiss ) )
807+ {
808+ break ;
809+ }
810+ }
811+ }
812+
813+ if ( xLookupResult == eARPCacheHit )
814+ {
815+ xResult = 0 ;
816+ }
817+
818+ return xResult ;
819+ }
820+ /*-----------------------------------------------------------*/
773821
774822/**
775823 * @brief Generate an ARP request packet by copying various constant details to
0 commit comments