SWRU368C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
In a one-shot query, discovery result depends on the very first respond received by the discoverer. The function sl_NetAppDnsGetHostByService() is used to perform such task. Upon successful discovery, the function will return:
The following code snippet shows a one-shot query discovering the "_workstation._tcp.local" service:
#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);
}
}