Name

cyg_mdns_discovery_query — Issue a DNS-SD query

Synopsis

#include <mdns.h>

cyg_bool cyg_mdns_discovery_query(const cyg_uint8 * const *name, struct netif *cnetif, cyg_uint16 type);

Description

This function is used to transmit a query to the selected lwIP network interface. The name should reference a NULL terminated set of pointers to the individual field entries for the query name. The type should be a RFC1035 defined resource record value. If the supplied cnetif is NULL then the code will transmit the query to all active interfaces. An IPv4 query will always be generated, and if lwIP IPv6 is configured than the code will also generate an IPv6 query.

[Note]Note

This function is not available if the system is not configured with CYGIMP_NET_MDNS_DNSSD enabled.

The following example source fragment demonstrates the “vector of pointers” structure used to hold the name to be used for the query. This example will issue a query across all interfaces asking for HTTP server information:

static const cyg_uint8 label_http[] = { 0x05,'_','h','t','t','p' };

static const cyg_uint8 * const services_http[] = {
    label_http,cyg_mdns_label_tcp,cyg_mdns_label_local,NULL
};

if (cyg_mdns_discovery_query(services_http,NULL,MDNS_RRTYPE_PTR)) {
    // success
} else {
    // failed
}

The <mdns.h> header file contains manifests (prefixed MDNS_RRTYPE_) for the main RFC1035 defined Resource Record types. Though, for DNS-SD use, normally only the MDNS_RRTYPE_PTR, MDNS_RRTYPE_SRV, MDNS_RRTYPE_A and MDNS_RRTYPE_AAAA types would be used during network service discovery.

[Note]Note

As discussed previously the process of generating queries is distinct from the system for registering callbacks to process responses. It is perfectly possible to generate requests when no callbacks are in place to handle responses (though this would not be of much use), and similarly it is expected that a callback may be registered for the lifetime of the application, with it asynchronously processing relevant responses that may have been triggered by the use of this query function.

Return value

Boolean true if the operation has completed OK, or false on failure. A failure may result if the operation cannot be posted to the lwIP layer for processing (this will trigger an assert when an ASSERT enabled configuration is being used), or (more likely) if there are no active (“link up”) network interfaces on which to send the query.