+static void lookup_handle_cname(AvahiSRBLookup *l, AvahiIfIndex interface, AvahiProtocol protocol, AvahiLookupFlags flags, AvahiRecord *r);
+static void lookup_drop_cname(AvahiSRBLookup *l, AvahiIfIndex interface, AvahiProtocol protocol, AvahiLookupFlags flags, AvahiRecord *r);
+
+static void transport_flags_from_domain(AvahiServer *s, AvahiLookupFlags *flags, const char *domain) {
+ assert(flags);
+ assert(domain);
+
+ assert(!((*flags & AVAHI_LOOKUP_USE_MULTICAST) && (*flags & AVAHI_LOOKUP_USE_WIDE_AREA)));
+
+ if (*flags & (AVAHI_LOOKUP_USE_MULTICAST|AVAHI_LOOKUP_USE_WIDE_AREA))
+ return;
+
+ if (!s->wide_area_lookup_engine ||
+ !avahi_wide_area_has_servers(s->wide_area_lookup_engine) ||
+ avahi_domain_ends_with(domain, AVAHI_MDNS_SUFFIX_LOCAL) ||
+ avahi_domain_ends_with(domain, AVAHI_MDNS_SUFFIX_ADDR_IPV4) ||
+ avahi_domain_ends_with(domain, AVAHI_MDNS_SUFFIX_ADDR_IPV6))
+ *flags |= AVAHI_LOOKUP_USE_MULTICAST;
+ else
+ *flags |= AVAHI_LOOKUP_USE_WIDE_AREA;
+}
+
+static AvahiSRBLookup* lookup_new(
+ AvahiSRecordBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiLookupFlags flags,
+ AvahiKey *key) {
+
+ AvahiSRBLookup *l;
+
+ assert(b);
+ assert(AVAHI_IF_VALID(interface));
+ assert(AVAHI_PROTO_VALID(protocol));
+
+ if (b->n_lookups >= AVAHI_LOOKUPS_PER_BROWSER_MAX)
+ /* We don't like cyclic CNAMEs */
+ return NULL;
+
+ if (!(l = avahi_new(AvahiSRBLookup, 1)))
+ return NULL;
+
+ l->ref = 1;
+ l->record_browser = b;
+ l->interface = interface;
+ l->protocol = protocol;
+ l->key = avahi_key_ref(key);
+ l->wide_area = NULL;
+ l->multicast = NULL;
+ l->cname_lookups = NULL;
+ l->flags = flags;
+
+ transport_flags_from_domain(b->server, &l->flags, key->name);
+
+ AVAHI_LLIST_PREPEND(AvahiSRBLookup, lookups, b->lookups, l);
+
+ b->n_lookups ++;