+static AvahiLegacyUnicastReflectSlot* allocate_slot(AvahiServer *s) {
+ unsigned n, idx = (unsigned) -1;
+ AvahiLegacyUnicastReflectSlot *slot;
+
+ assert(s);
+
+ if (!s->legacy_unicast_reflect_slots)
+ s->legacy_unicast_reflect_slots = avahi_new0(AvahiLegacyUnicastReflectSlot*, AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS);
+
+ for (n = 0; n < AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS; n++, s->legacy_unicast_reflect_id++) {
+ idx = s->legacy_unicast_reflect_id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
+
+ if (!s->legacy_unicast_reflect_slots[idx])
+ break;
+ }
+
+ if (idx == (unsigned) -1 || s->legacy_unicast_reflect_slots[idx])
+ return NULL;
+
+ if (!(slot = avahi_new(AvahiLegacyUnicastReflectSlot, 1)))
+ return NULL; /* OOM */
+
+ s->legacy_unicast_reflect_slots[idx] = slot;
+ slot->id = s->legacy_unicast_reflect_id++;
+ slot->server = s;
+
+ return slot;
+}
+
+static void deallocate_slot(AvahiServer *s, AvahiLegacyUnicastReflectSlot *slot) {
+ unsigned idx;
+
+ assert(s);
+ assert(slot);
+
+ idx = slot->id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
+
+ assert(s->legacy_unicast_reflect_slots[idx] == slot);
+
+ avahi_time_event_free(slot->time_event);
+
+ avahi_free(slot);
+ s->legacy_unicast_reflect_slots[idx] = NULL;
+}
+
+static void free_slots(AvahiServer *s) {
+ unsigned idx;
+ assert(s);
+
+ if (!s->legacy_unicast_reflect_slots)
+ return;
+
+ for (idx = 0; idx < AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS; idx ++)
+ if (s->legacy_unicast_reflect_slots[idx])
+ deallocate_slot(s, s->legacy_unicast_reflect_slots[idx]);
+
+ avahi_free(s->legacy_unicast_reflect_slots);
+ s->legacy_unicast_reflect_slots = NULL;
+}
+
+static AvahiLegacyUnicastReflectSlot* find_slot(AvahiServer *s, uint16_t id) {
+ unsigned idx;
+
+ assert(s);
+
+ if (!s->legacy_unicast_reflect_slots)
+ return NULL;
+
+ idx = id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
+
+ if (!s->legacy_unicast_reflect_slots[idx] || s->legacy_unicast_reflect_slots[idx]->id != id)
+ return NULL;
+
+ return s->legacy_unicast_reflect_slots[idx];
+}
+
+static void legacy_unicast_reflect_slot_timeout(AvahiTimeEvent *e, void *userdata) {
+ AvahiLegacyUnicastReflectSlot *slot = userdata;
+
+ assert(e);
+ assert(slot);
+ assert(slot->time_event == e);
+
+ deallocate_slot(slot->server, slot);
+}
+
+static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, uint16_t port) {
+ AvahiLegacyUnicastReflectSlot *slot;
+ AvahiInterface *j;
+
+ assert(s);
+ assert(p);
+ assert(i);
+ assert(a);
+ assert(port > 0);
+ assert(i->protocol == a->proto);