Skip to content

DNS callback to use new xDNSDoCallback API #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions source/FreeRTOS_DNS_Parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,15 +786,7 @@
{
BaseType_t xCallbackResult;

#if ( ipconfigUSE_IPv6 != 0 )
{
xCallbackResult = xDNSDoCallback( pxSet, ( ppxAddressInfo != NULL ) ? *( ppxAddressInfo ) : NULL );
}
#else
{
xCallbackResult = xDNSDoCallback( pxSet, pxSet->ulIPAddress );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good find. Thank you.
Please check once why this "integer to pointer" assignment is not being treated as an error in our build.

}
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
xCallbackResult = xDNSDoCallback( pxSet, ( ppxAddressInfo != NULL ) ? *( ppxAddressInfo ) : NULL );

/* See if any asynchronous call was made to FreeRTOS_gethostbyname_a() */
if( xCallbackResult != pdFALSE )
Expand Down
141 changes: 59 additions & 82 deletions tools/tcp_utilities/plus_tcp_demo_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,9 @@ static struct freertos_addrinfo * pxDNSLookup( char * pcHost,
BaseType_t xAsynchronous,
BaseType_t xDoClear );

#if ( ipconfigUSE_IPv6 == 0 )
/* In the old days, an IP-address was just a number. */
static void vDNSEvent( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress );
#else
/* freertos_addrinfo can contain either an IPv4 or an IPv6 address. */
static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo );
#endif
static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo );

#if ( ipconfigMULTI_INTERFACE != 0 )
/* Defined in FreeRTOS_DNS.c */
Expand Down Expand Up @@ -1485,95 +1477,80 @@ void xHandleTesting()
#endif /* ( ipconfigMULTI_INTERFACE != 0 ) */
/*-----------------------------------------------------------*/

#if ( ipconfigUSE_IPv6 != 0 )
static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo )

static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo )
{
( void ) pvSearchID;

if( pxAddrInfo == NULL )
{
FreeRTOS_printf( ( "vDNSEvent(%s) : nothing found\n", pcName ) );
}
else
{
( void ) pvSearchID;
FreeRTOS_printf( ( "vDNSEvent: family = %d\n", ( int ) pxAddrInfo->ai_family ) );

if( pxAddrInfo == NULL )
{
FreeRTOS_printf( ( "vDNSEvent(%s) : nothing found\n", pcName ) );
}
else
switch( pxAddrInfo->ai_family )
{
FreeRTOS_printf( ( "vDNSEvent: family = %d\n", ( int ) pxAddrInfo->ai_family ) );
#if ( ipconfigUSE_IPv4 != 0 )
case FREERTOS_AF_INET:
{
uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4;

switch( pxAddrInfo->ai_family )
{
#if ( ipconfigUSE_IPv4 != 0 )
case FREERTOS_AF_INET:
if( ulIPaddress == 0uL )
{
uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4;

if( ulIPaddress == 0uL )
{
FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) );
}
FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) );
}
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

#if ( ipconfigUSE_IPv6 != 0 )
case FREERTOS_AF_INET6:
else
{
BaseType_t xIsEmpty = pdTRUE, xIndex;
FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) );
}
}
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ )
{
if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u )
{
xIsEmpty = pdFALSE;
break;
}
}
#if ( ipconfigUSE_IPv6 != 0 )
case FREERTOS_AF_INET6:
{
BaseType_t xIsEmpty = pdTRUE, xIndex;

if( xIsEmpty )
{
FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) );
}
else
for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ )
{
if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u )
{
FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) );
xIsEmpty = pdFALSE;
break;
}
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "vDNSEvent: Undefined Family Type \n" ) );
break;
}
}
if( xIsEmpty )
{
FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) );
}
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

if( xServerWorkTaskHandle != NULL )
{
xDNSCount++;
xTaskNotifyGive( xServerWorkTaskHandle );
default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "vDNSEvent: Undefined Family Type \n" ) );
break;
}
}
#else /* if ( ipconfigUSE_IPv6 != 0 ) */
static void vDNSEvent( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress )
{
( void ) pvSearchID;

FreeRTOS_printf( ( "vDNSEvent: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPAddress ) ) );

if( xServerWorkTaskHandle != NULL )
{
xDNSCount++;
xTaskNotifyGive( xServerWorkTaskHandle );
}
if( xServerWorkTaskHandle != NULL )
{
xDNSCount++;
xTaskNotifyGive( xServerWorkTaskHandle );
}
#endif /* if ( ipconfigUSE_IPv6 != 0 ) */
}

/*-----------------------------------------------------------*/

#if ( ipconfigMULTI_INTERFACE != 0 )
Expand Down