ZHCU938C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
在一次性查询中,发现结果取决于发现器接收的第一个响应。函数 sl_NetAppDnsGetHostByService() 用于执行此类任务。成功发现后,该函数将返回:
以下代码片段显示了发现“_workstation._tcp.local”服务的一次性查询:
#define LISTEN_SERVICE_NAME "_workstation._tcp.local"
void mDNS_Query_OneShot()
{
_u32 pAddr;
_u32 usPort;
_u16 ulTextLen;
_i8 cText[200];
// Set an infinite loop until getting a response
_i32 iretvalmDNS = 1;
while(iretvalmDNS)
{
// Search services on the network by specifying the name
iretvalmDNS = sl_NetAppDnsGetHostByService(
LISTEN_SERVICE_NAME,
(_u8) strlen(LISTEN_SERVICE_NAME),
SL_AF_INET,
(_u32 *) &pAddr, &usPort, &ulTextLen, &cText[0]);
}
// Upon success, 0 is returned and we just need to print out the information
if(iretvalmDNS == 0)
{
cText[ulTextLen] = '\0';
Report("First Response: Addr: %d.%d.%d.%d, Port: %d, Text: %s, TextLength: %d\n\r",
SL_IPV4_BYTE(pAddr, 3), SL_IPV4_BYTE(pAddr, 2),
SL_IPV4_BYTE(pAddr, 1), SL_IPV4_BYTE(pAddr, 0),
usPort, cText, ulTextLen);
}
}