![Texas Instruments CC3220 Скачать руководство пользователя страница 90](http://html.mh-extra.com/html/texas-instruments/cc3220/cc3220_programmers-manual_1094609090.webp)
DNS
90
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
Example:
_i16 Sd, Channel = 11;
Sd = sl_Socket(SL_AF_RF, SL_SOCK_RAW, Channel);
if
( 0 > Sd )
{
// error
}
6.6
DNS
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_gethostbyName APIs are designed to bridge that gap. If successful, sl_gethostbyName
resolves the IP address. To resolve an IP address, sl_gethostbyName 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_gethostbyName is a blocking command so if failure occurs it may take
some time to return.
An example of the host application setting sl_gethostbyName 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
}