SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
Hosts are mostly identified by their name and not their IP address, because the IP address might change, but the host name remains the same. Even in cases where the IP address is reserved permanently, it is common to remember names, and not IP addresses. For example, the IP address of Google® is not familiar to users even though it is reserved permanently. On the contrary, socket APIs use IP addresses, not names, and sl_NetAppDnsGetHostByName() APIs are designed to bridge that gap. If successful, sl_NetAppDnsGetHostByName() resolves the IP address. To resolve an IP address, sl_NetAppDnsGetHostByName() sends the UDP DNS request several times, and with every retry the time-out increases. The number of retries and time-out parameters are configurable. The command sl_NetAppDnsGetHostByName() is a blocking command, so if failure occurs it may take some time to return.
An example of the host application setting sl_NetAppDnsGetHostByName() parameters:
_i16 Status;
SlNetAppDnsClientTime_t Time;
Time.MaxResponseTime = 2000; // Max DNS retry timeout, DNS request timeout changed every retry, start with 100Ms up to MaxResponseTime Ms
Time.NumOfRetries = 30; // number DNS retries before sl_NetAppDnsGetHostByName failed
Status = sl_NetAppSet(SL_NETAPP_DNS_CLIENT_ID, SL_NETAPP_DNS_CLIENT_TIME, sizeof(Time), (_u8 *)&Time);
if( Status )
{
// error
}
An example of resolving the IPv4 address:
_i16 Status;
_u32 Ipv4Addr = 0;
Status = sl_NetAppDnsGetHostByName("www.google.com", strlen("www.google.com"), &Ipv4Addr, SL_AF_INET);
if( Status )
{
// error
}
An example of resolving the IPv6 address:
_i16 Status;
_u32 Ipv6Addr[4] = {0};
Status = sl_NetAppDnsGetHostByName("www.facebook.com", strlen("www.facebook.com"), Ipv6Addr, SL_AF_INET6);
if( Status )
{
// error
}