1
0
mirror of https://github.com/FreeRTOS/FreeRTOS-Plus-TCP synced 2025-10-23 18:38:33 +08:00
Files
FreeRTOS-Plus-TCP/source/FreeRTOS_DNS_Cache.c
Tony Josi 0e9628796c Fixing doxygen comments (#728)
* updating doxygen config

* fixing doxygen comments

* adding IPv6 files and fixing comments

* fix doxygen cfg and file names in comments

* wip doxygen v6 docs

* adding doxygen comments

* include RA src file to doxgendocs generation

* fix spell check issues

* Uncrustify: triggered by comment.

* fix minor build issue

* fix spell check issues

* Uncrustify: triggered by comment

* fix trailing white space

* Dev integration hein.v8 (#738)

* Updating tcp utilities

* Some more change in dev_integration_hein.v8

* In FreeRTOS_DNS_Parser.c : use 'ipUDP_PAYLOAD_OFFSET_IPv4' in stead of 'ipIP_PAYLOAD_OFFSET'

* And a few more corrections

* Changes to WinPCap network interface, removed debugging code

* After applying uncrustify

* Oops, I forgot the push changes in include files.

* Now removing it, hopefully

---------

Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com>
Co-authored-by: Monika Singh <108652024+moninom1@users.noreply.github.com>

* Fix CBMC proofs for DNS (#718)

* Use CBMC XML output to enable VSCode debugger (#673)

Prior to this commit, CBMC would emit logging information in plain text
format, which does not contain information required for the CBMC VSCode
debugger. This commit makes CBMC use XML instead of plain text.

Co-authored-by: Mark Tuttle <tuttle@acm.org>

* wip

* wip DNSgetHostByName

* wip DNSgetHostByName

* fixed cbmc proof for DNS_ReadNameField

* wip DNSgetHostByName_a_harness

* Fix CBMC prooff for DNSgetHostByName

* wip fix DNSgetHostByName_a CBMC proof

* fixed cbmc target func not called issue in DNSclear

* fixed cbmc target func not called issue in DNSlookup

* fix DNSgetHostByName_a CBMC proof

* update comments

* more asserts

* fixing formatting

* updating as per review comments

* fix dns after review comments

* adding more asserts

* adds more asserts

* minor fix

* fixing comments

* fixing comments

* fixing minor issue

* fixing DNS_ReadReply() signature

* making code more consistant

* adding more  asserts

* making code more consistent

---------

Co-authored-by: Kareem Khazem <karkhaz@amazon.com>
Co-authored-by: Mark Tuttle <tuttle@acm.org>

* Uncrustify: triggered by comment

* fixing formatting

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Hein Tibosch <hein_tibosch@yahoo.es>
Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com>
Co-authored-by: Monika Singh <108652024+moninom1@users.noreply.github.com>
Co-authored-by: Kareem Khazem <karkhaz@amazon.com>
Co-authored-by: Mark Tuttle <tuttle@acm.org>
2023-02-24 13:58:53 +05:30

665 lines
26 KiB
C

/*
* FreeRTOS+TCP <DEVELOPMENT BRANCH>
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/**
* @file FreeRTOS_DNS_Cache.c
* @brief File that handles the DNS caching option
*/
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkBufferManagement.h"
#include "NetworkInterface.h"
#include "FreeRTOS_DNS_Cache.h"
#include "FreeRTOS_DNS_Globals.h"
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#if ( ( ipconfigUSE_DNS != 0 ) && ( ipconfigUSE_DNS_CACHE == 1 ) )
/**
* @brief cache entry format structure
*/
typedef struct xDNS_CACHE_TABLE_ROW
{
IPv46_Address_t xAddresses[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ]; /*!< The IP address(es) of an ARP cache entry. */
char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /*!< The name of the host */
uint32_t ulTTL; /*!< Time-to-Live (in seconds) from the DNS server. */
uint32_t ulTimeWhenAddedInSeconds; /*!< time at which the entry was added */
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
uint8_t ucNumIPAddresses; /*!< number of ip addresses for the same entry */
uint8_t ucCurrentIPAddress; /*!< current ip address index */
#endif
} DNSCacheRow_t;
/*!
* @brief DNS cache structure instantiation
*/
static DNSCacheRow_t xDNSCache[ ipconfigDNS_CACHE_ENTRIES ] = { 0x0 };
/*!
* @brief indicates the index of a free entry in the cache structure
* \a DNSCacheRow_t
*/
static UBaseType_t uxFreeEntry = 0U;
/** returns the index of the hostname entry in the dns cache. */
static BaseType_t prvFindEntryIndex( const char * pcName,
IPv46_Address_t * pxIP,
UBaseType_t * uxResult );
/** get entry at \p index from the cache. */
static BaseType_t prvGetCacheIPEntry( UBaseType_t uxIndex,
IPv46_Address_t * pxIP,
uint32_t ulCurrentTimeSeconds,
struct freertos_addrinfo ** ppxAddressInfo );
/** update entry at \p index in the cache. */
static void prvUpdateCacheEntry( UBaseType_t uxIndex,
uint32_t ulTTL,
IPv46_Address_t * pxIP,
uint32_t ulCurrentTimeSeconds );
/** insert entry in the cache. */
static void prvInsertCacheEntry( const char * pcName,
uint32_t ulTTL,
IPv46_Address_t * pxIP,
uint32_t ulCurrentTimeSeconds );
#if ( ipconfigUSE_DNS_CACHE == 1 )
/** Copy DNS cache entries at xIndex to a linked struct addrinfo. */
static void prvReadDNSCache( BaseType_t uxIndex,
struct freertos_addrinfo ** ppxAddressInfo );
#endif
/*-----------------------------------------------------------*/
/**
* @brief perform a dns lookup in the local cache
* @param pcHostName the lookup name
* @return ulIPAddress with the value from the cache else returns a zero if the
* cache is not enabled or the lookup is not successful
* @post the global structure \a xDNSCache might be modified
*/
uint32_t FreeRTOS_dnslookup( const char * pcHostName )
{
IPv46_Address_t xIPv46_Address;
/* Looking up an IPv4 address in the DNS cache. */
( void ) memset( &xIPv46_Address, 0, sizeof( xIPv46_Address ) );
( void ) FreeRTOS_ProcessDNSCache( pcHostName,
&( xIPv46_Address ),
0,
pdTRUE,
NULL );
return xIPv46_Address.ulIPAddress;
}
/*-----------------------------------------------------------*/
/**
* @brief Perform a dns lookup in the local cache (IPv6)
* @param pcHostName The lookup name
* @param pxAddress_IPv6 The IPv6 address looked up from the cache if the return value is non zero.
* @return ulReturn Non zero if name is found in cache else returns a zero if the
* cache is not enabled or the lookup is not successful
* @post the global structure \a xDNSCache might be modified
*/
uint32_t FreeRTOS_dnslookup6( const char * pcHostName,
IPv6_Address_t * pxAddress_IPv6 )
{
IPv46_Address_t xIPv46_Address;
BaseType_t xResult;
uint32_t ulReturn = 0U;
/* Looking up an IPv6 address in the DNS cache. */
( void ) memset( &xIPv46_Address, 0, sizeof xIPv46_Address );
/* Let FreeRTOS_ProcessDNSCache only return IPv6 addresses. */
xIPv46_Address.xIs_IPv6 = pdTRUE;
xResult = FreeRTOS_ProcessDNSCache( pcHostName, &xIPv46_Address, 0, pdTRUE, NULL );
if( xResult != pdFALSE )
{
( void ) memcpy( pxAddress_IPv6->ucBytes, xIPv46_Address.xAddress_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS );
ulReturn = 1U;
}
return ulReturn;
}
/*-----------------------------------------------------------*/
/**
* @brief perform a dns update in the local cache
* @param pcName the lookup name
* @param pxIP the ip value to insert/replace (IPv4/v6)
* @param ulTTL Time To live (in seconds)
* @param xLookUp Ignored
* @param ppxAddressInfo A pointer to a pointer where the find results
* will be stored.
* @return this is a dummy return, we are actually ignoring the return value
* from this function
* @post the global structure \a xDNSCache might be modified
*/
BaseType_t FreeRTOS_dns_update( const char * pcName,
IPv46_Address_t * pxIP,
uint32_t ulTTL,
BaseType_t xLookUp,
struct freertos_addrinfo ** ppxAddressInfo )
{
/* _HT_ we can as well remove the parameter 'xLookUp'. */
( void ) xLookUp;
( void ) FreeRTOS_ProcessDNSCache( pcName,
pxIP,
ulTTL,
pdFALSE,
ppxAddressInfo );
return pdTRUE;
}
/**
* @brief perform a dns clear in the local cache
* @post the global structure \a xDNSCache is modified
*/
void FreeRTOS_dnsclear( void )
{
( void ) memset( xDNSCache, 0x0, sizeof( xDNSCache ) );
uxFreeEntry = 0U;
}
/**
* @brief process a DNS Cache request (get, update, or insert)
*
* @param[in] pcName: the name of the host
* @param[in,out] pxIP: when doing a lookup, will be set, when doing an update,
* will be read.
* @param[in] ulTTL: Time To Live (in seconds)
* @param[in] xLookUp: pdTRUE if a look-up is expected, pdFALSE, when the DNS cache must
* be updated.
* @param[in,out] ppxAddressInfo: A pointer to a pointer where the find results
* will be stored.
* @return whether the operation was successful
* @post the global structure \a xDNSCache might be modified
*/
BaseType_t FreeRTOS_ProcessDNSCache( const char * pcName,
IPv46_Address_t * pxIP,
uint32_t ulTTL,
BaseType_t xLookUp,
struct freertos_addrinfo ** ppxAddressInfo )
{
UBaseType_t uxIndex;
BaseType_t xResult;
/* Get the current time in clock-ticks. */
TickType_t xCurrentTickCount = xTaskGetTickCount();
/* In milliseconds. */
uint32_t ulCurrentTimeSeconds;
configASSERT( ( pcName != NULL ) );
if( xLookUp != pdFALSE )
{
pxIP->ulIPAddress = 0U;
}
ulCurrentTimeSeconds = ( xCurrentTickCount / portTICK_PERIOD_MS ) / 1000U;
xResult = prvFindEntryIndex( pcName, pxIP, &uxIndex );
if( xResult == pdTRUE )
{ /* Element found */
/* Is this function called for a lookup or to add/update an IP address? */
if( xLookUp == pdTRUE )
{
/* This statement can only be reached when xResult is true; which
* implies that the entry is present and a 'get' operation will result
* in success. Therefore, it is safe to ignore the return value of the
* below function. */
( void ) prvGetCacheIPEntry( uxIndex,
pxIP,
ulCurrentTimeSeconds,
ppxAddressInfo );
}
else
{
prvUpdateCacheEntry( uxIndex,
ulTTL,
pxIP,
ulCurrentTimeSeconds );
}
}
else /* Element not Found xResult = pdFALSE */
{
if( xLookUp == pdTRUE )
{
pxIP->ulIPAddress = 0U;
}
else
{
prvInsertCacheEntry( pcName,
ulTTL,
pxIP,
ulCurrentTimeSeconds );
}
}
#if ( ipconfigHAS_DEBUG_PRINTF != 0 )
if( ( xLookUp == pdFALSE ) || ( pxIP->ulIPAddress != 0U ) )
{
char pcAddress[ 40 ];
IP_Address_t xAddress;
BaseType_t xFamily = FREERTOS_AF_INET;
if( pxIP->xIs_IPv6 != 0U )
{
( void ) memcpy( xAddress.xIP_IPv6.ucBytes, pxIP->xAddress_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS );
if( pxIP->xIs_IPv6 != 0U )
{
xFamily = FREERTOS_AF_INET6;
}
}
else
{
xAddress.ulIP_IPv4 = pxIP->ulIPAddress;
}
( void ) FreeRTOS_inet_ntop( xFamily,
( const void * ) xAddress.xIP_IPv6.ucBytes,
pcAddress,
( socklen_t ) sizeof( pcAddress ) );
FreeRTOS_debug_printf( ( "FreeRTOS_ProcessDNSCache: %s: '%s' @ %s (TTL %u)\n",
( xLookUp != 0 ) ? "look-up" : "add",
pcName,
pcAddress,
( unsigned ) FreeRTOS_ntohl( ulTTL ) ) );
}
#endif /* ( ipconfigHAS_DEBUG_PRINTF != 0 ) */
return xResult;
}
/**
* @brief returns the index of the hostname entry in the dns cache.
* @param[in] pcName find it in the cache
* @param[in] pxIP ip address
* @param [out] uxResult index number
* @returns res pdTRUE if index in found else pdFALSE
*/
static BaseType_t prvFindEntryIndex( const char * pcName,
IPv46_Address_t * pxIP,
UBaseType_t * uxResult )
{
BaseType_t xReturn = pdFALSE;
UBaseType_t uxIndex;
/* For each entry in the DNS cache table. */
for( uxIndex = 0; uxIndex < ipconfigDNS_CACHE_ENTRIES; uxIndex++ )
{
if( xDNSCache[ uxIndex ].pcName[ 0 ] == ( char ) 0 )
{ /* empty slot */
continue;
}
if( strcmp( xDNSCache[ uxIndex ].pcName, pcName ) == 0 )
{ /* hostname found */
/* IPv6 is enabled, See if the cache entry has the correct type. */
if( pxIP->xIs_IPv6 == xDNSCache[ uxIndex ].xAddresses[ 0 ].xIs_IPv6 )
{
xReturn = pdTRUE;
*uxResult = uxIndex;
break;
}
}
}
return xReturn;
}
/*-----------------------------------------------------------*/
/**
* @brief get entry at \p index from the cache
* @param[in] uxIndex : index in the cache
* @param[out] pxIP fill it with the result
* @param[in] ulCurrentTimeSeconds current time
* @param[out] ppxAddressInfo Target to store the DNS entries.
* @returns \c pdTRUE if the value is valid \c pdFALSE otherwise
* @post the global structure \a xDNSCache might be modified
*
*/
static BaseType_t prvGetCacheIPEntry( UBaseType_t uxIndex,
IPv46_Address_t * pxIP,
uint32_t ulCurrentTimeSeconds,
struct freertos_addrinfo ** ppxAddressInfo )
{
BaseType_t isRead;
uint32_t ulIPAddressIndex = 0;
uint32_t ulAge = ulCurrentTimeSeconds - xDNSCache[ uxIndex ].ulTimeWhenAddedInSeconds;
/* Confirm that the record is still fresh.
* The field ulTTL was stored as network-endian. */
if( ulAge < FreeRTOS_ntohl( xDNSCache[ uxIndex ].ulTTL ) )
{
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
uint8_t ucIndex;
/* The ucCurrentIPAddress value increments without bound and will rollover, */
/* modulo it by the number of IP addresses to keep it in range. */
/* Also perform a final modulo by the max number of IP addresses */
/* per DNS cache entry to prevent out-of-bounds access in the event */
/* that ucNumIPAddresses has been corrupted. */
ucIndex = xDNSCache[ uxIndex ].ucCurrentIPAddress % xDNSCache[ uxIndex ].ucNumIPAddresses;
ucIndex = ucIndex % ( uint8_t ) ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY;
ulIPAddressIndex = ucIndex;
xDNSCache[ uxIndex ].ucCurrentIPAddress++;
#endif /* if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 ) */
( void ) memcpy( pxIP, &( xDNSCache[ uxIndex ].xAddresses[ ulIPAddressIndex ] ), sizeof( *pxIP ) );
isRead = pdTRUE;
if( ppxAddressInfo != NULL )
{
/* Copy all entries from position 'uxIndex' to a linked struct addrinfo. */
prvReadDNSCache( uxIndex, ppxAddressInfo );
}
}
else
{
/* Age out the old cached record. */
xDNSCache[ uxIndex ].pcName[ 0 ] = ( char ) 0;
isRead = pdFALSE;
}
return isRead;
}
/*-----------------------------------------------------------*/
/**
* @brief update entry at \p index in the cache
* @param[in] uxIndex : index in the cache
* @param[in] ulTTL time to live (in seconds)
* @param[in] pxIP ip to update the cache with
* @param[in] ulCurrentTimeSeconds current time
* @post the global structure \a xDNSCache is modified
*/
static void prvUpdateCacheEntry( UBaseType_t uxIndex,
uint32_t ulTTL,
IPv46_Address_t * pxIP,
uint32_t ulCurrentTimeSeconds )
{
uint32_t ulIPAddressIndex = 0;
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
if( xDNSCache[ uxIndex ].ucNumIPAddresses <
( uint8_t ) ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY )
{
/* If more answers exist than there are IP address storage
* slots they will overwrite entry 0 */
ulIPAddressIndex = xDNSCache[ uxIndex ].ucNumIPAddresses;
xDNSCache[ uxIndex ].ucNumIPAddresses++;
}
#endif
( void ) memcpy( &( xDNSCache[ uxIndex ].xAddresses[ ulIPAddressIndex ] ), pxIP, sizeof( *pxIP ) );
xDNSCache[ uxIndex ].ulTTL = ulTTL;
xDNSCache[ uxIndex ].ulTimeWhenAddedInSeconds = ulCurrentTimeSeconds;
}
/*-----------------------------------------------------------*/
/**
* @brief insert entry in the cache
* @param[in] pcName cache entry key
* @param[in] ulTTL time to live (in seconds)
* @param[in] pxIP ip address
* @param[in] ulCurrentTimeSeconds current time
* @post the global structure \a xDNSCache is modified
*/
static void prvInsertCacheEntry( const char * pcName,
uint32_t ulTTL,
IPv46_Address_t * pxIP,
uint32_t ulCurrentTimeSeconds )
{
/* Add or update the item. */
if( strlen( pcName ) < ( size_t ) ipconfigDNS_CACHE_NAME_LENGTH )
{
( void ) strcpy( xDNSCache[ uxFreeEntry ].pcName, pcName );
( void ) memcpy( &( xDNSCache[ uxFreeEntry ].xAddresses[ 0 ] ), pxIP, sizeof( *pxIP ) );
xDNSCache[ uxFreeEntry ].ulTTL = ulTTL;
xDNSCache[ uxFreeEntry ].ulTimeWhenAddedInSeconds = ulCurrentTimeSeconds;
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
xDNSCache[ uxFreeEntry ].ucNumIPAddresses = 1;
xDNSCache[ uxFreeEntry ].ucCurrentIPAddress = 0;
/* Initialize all remaining IP addresses in this entry to 0 */
( void ) memset( &xDNSCache[ uxFreeEntry ].xAddresses[ 1 ],
0,
sizeof( xDNSCache[ uxFreeEntry ].xAddresses[ 1 ] ) *
( ( uint32_t ) ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY - 1U ) );
#endif
uxFreeEntry++;
if( uxFreeEntry == ipconfigDNS_CACHE_ENTRIES )
{
uxFreeEntry = 0;
}
}
}
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_DNS_CACHE == 1 )
/**
* @brief Copy DNS cache entries at uxIndex to a linked struct addrinfo.
* @param[in] uxIndex: The index from where entries must be copied.
* @param[out] ppxAddressInfo: Target to store the DNS entries.
*/
static void prvReadDNSCache( BaseType_t uxIndex,
struct freertos_addrinfo ** ppxAddressInfo )
{
size_t uxIPAddressIndex;
size_t uxNumIPAddresses = 1U;
IPv46_Address_t * pxAddresses;
struct freertos_addrinfo * pxNewAddress;
struct freertos_addrinfo * pxLastAddress;
struct freertos_addrinfo ** ppxLastAddress = &( pxLastAddress );
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
uxNumIPAddresses = ( size_t ) xDNSCache[ uxIndex ].ucNumIPAddresses;
if( uxNumIPAddresses > ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY )
{
/* Make this a configASSERT()? */
uxNumIPAddresses = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY;
}
#endif /* ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 ) */
for( uxIPAddressIndex = 0; uxIPAddressIndex < uxNumIPAddresses; uxIPAddressIndex++ )
{
pxAddresses = &( xDNSCache[ uxIndex ].xAddresses[ uxIPAddressIndex ] );
if( pxAddresses->xIs_IPv6 != pdFALSE )
{
pxNewAddress = pxNew_AddrInfo( xDNSCache[ uxIndex ].pcName, FREERTOS_AF_INET6, pxAddresses->xAddress_IPv6.ucBytes );
}
else
{
uint8_t * ucBytes = ( uint8_t * ) &( pxAddresses->ulIPAddress );
pxNewAddress = pxNew_AddrInfo( xDNSCache[ uxIndex ].pcName, FREERTOS_AF_INET4, ucBytes );
}
if( pxNewAddress != NULL )
{
if( *( ppxAddressInfo ) == NULL )
{
/* For the first address found. */
*( ppxAddressInfo ) = pxNewAddress;
}
else
{
/* For the next address found. */
*( ppxLastAddress ) = pxNewAddress;
}
ppxLastAddress = &( pxNewAddress->ai_next );
}
}
}
#endif /* #if( ipconfigUSE_DNS_CACHE == 1 ) */
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_DNS_CACHE == 1 )
/**
* @brief Lookup the given hostname in the DNS cache
* @param[in] pcHostName: THe host name to lookup
* @param[in] xFamily: IP type FREERTOS_AF_INET6 / FREERTOS_AF_INET4
* @param[out] ppxAddressInfo: Target to store the DNS entries.
* @returns This function returns either a valid IPv4 address, or
* in case of an IPv6 lookup, it will return a non-zero.
*/
uint32_t Prepare_CacheLookup( const char * pcHostName,
BaseType_t xFamily,
struct freertos_addrinfo ** ppxAddressInfo )
{
uint32_t ulIPAddress = 0U;
IPv46_Address_t xIPv46_Address;
if( xFamily == FREERTOS_AF_INET6 )
{
BaseType_t xFound;
xIPv46_Address.xIs_IPv6 = pdTRUE;
xFound = FreeRTOS_ProcessDNSCache( pcHostName, &( xIPv46_Address ), 0, pdTRUE, ppxAddressInfo );
if( xFound != 0 )
{
if( ( ppxAddressInfo != NULL ) && ( *( ppxAddressInfo ) != NULL ) )
{
/* This function returns either a valid IPv4 address, or
* in case of an IPv6 lookup, it will return a non-zero */
ulIPAddress = 1U;
}
}
else
{
/* prvGetHostByName will be called to start a DNS lookup. */
}
}
else
{
BaseType_t xFound;
xIPv46_Address.xIs_IPv6 = pdFALSE;
xFound = FreeRTOS_ProcessDNSCache( pcHostName, &( xIPv46_Address ), 0, pdTRUE, ppxAddressInfo );
if( xFound != 0 )
{
if( ( ppxAddressInfo != NULL ) && ( *( ppxAddressInfo ) != NULL ) )
{
struct freertos_sockaddr * sockaddr = ( *( ppxAddressInfo ) )->ai_addr;
ulIPAddress = sockaddr->sin_addr;
}
}
else
{
/* prvGetHostByName will be called to start a DNS lookup. */
}
}
return ulIPAddress;
}
#endif /* ( ipconfigUSE_DNS_CACHE == 1 ) */
/*-----------------------------------------------------------*/
#if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 )
/**
* @brief For debugging only: prints the contents of the DNS cache table.
*/
void vShowDNSCacheTable()
{
UBaseType_t xEntry;
UBaseType_t xSubEntry;
for( xEntry = 0; xEntry < ipconfigDNS_CACHE_ENTRIES; xEntry++ )
{
DNSCacheRow_t * pxRow = &( xDNSCache[ xEntry ] );
if( pxRow->pcName[ 0 ] != ( char ) 0 )
{
FreeRTOS_printf( ( "Entry %2u: %s use %u/%u\n",
( unsigned ) xEntry,
pxRow->pcName,
( unsigned ) pxRow->ucCurrentIPAddress,
( unsigned ) pxRow->ucNumIPAddresses ) );
for( xSubEntry = 0; xSubEntry < pxRow->ucNumIPAddresses; xSubEntry++ )
{
char pcAddress[ 40 ] = "";
#if ( ipconfigUSE_IPv6 != 0 )
/* The first entry determines the type of row:
* either IPv4 or IPv6. */
if( pxRow->xAddresses[ 0 ].xIs_IPv6 != pdFALSE )
{
FreeRTOS_inet_ntop( FREERTOS_AF_INET6,
( const void * ) pxRow->xAddresses[ xSubEntry ].xAddress_IPv6.ucBytes,
pcAddress,
sizeof( pcAddress ) );
}
else
#endif /* if ( ipconfigUSE_IPv6 != 0 ) */
{
FreeRTOS_inet_ntop( FREERTOS_AF_INET4,
( const void * ) &( pxRow->xAddresses[ xSubEntry ].ulIPAddress ),
pcAddress,
sizeof( pcAddress ) );
}
FreeRTOS_printf( ( " %2u: %s\n",
( unsigned ) xSubEntry,
pcAddress ) );
}
}
}
}
#endif /* if ( ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY > 1 ) */
/*-----------------------------------------------------------*/
#endif /* if ( ( ipconfigUSE_DNS != 0 ) && ( ipconfigUSE_DNS_CACHE == 1 ) ) */