+
+ for (hw = m->hw_interfaces; hw; hw = hw->hardware_next)
+ avahi_hw_interface_update_rrs(hw, remove_rrs);
+}
+
+static int interface_mdns_mcast_join(AvahiInterface *i, int join) {
+ char at[AVAHI_ADDRESS_STR_MAX];
+ int r;
+ assert(i);
+
+ if (!!join == !!i->mcast_joined)
+ return 0;
+
+ if ((i->protocol == AVAHI_PROTO_INET6 && i->monitor->server->fd_ipv6 < 0) ||
+ (i->protocol == AVAHI_PROTO_INET && i->monitor->server->fd_ipv4 < 0))
+ return -1;
+
+ if (join) {
+ AvahiInterfaceAddress *a;
+
+ /* Look if there's an address with global scope */
+ for (a = i->addresses; a; a = a->address_next)
+ if (a->global_scope)
+ break;
+
+ /* No address with a global scope has been found, so let's use
+ * any. */
+ if (!a)
+ a = i->addresses;
+
+ /* Hmm, there is no address available. */
+ if (!a)
+ return -1;
+
+ i->local_mcast_address = a->address;
+ }
+
+ avahi_log_info("%s mDNS multicast group on interface %s.%s with address %s.",
+ join ? "Joining" : "Leaving",
+ i->hardware->name,
+ avahi_proto_to_string(i->protocol),
+ avahi_address_snprint(at, sizeof(at), &i->local_mcast_address));
+
+ if (i->protocol == AVAHI_PROTO_INET6)
+ r = avahi_mdns_mcast_join_ipv6(i->monitor->server->fd_ipv6, &i->local_mcast_address.data.ipv6, i->hardware->index, join);
+ else {
+ assert(i->protocol == AVAHI_PROTO_INET);
+
+ r = avahi_mdns_mcast_join_ipv4(i->monitor->server->fd_ipv4, &i->local_mcast_address.data.ipv4, i->hardware->index, join);
+ }
+
+ if (r < 0)
+ i->mcast_joined = 0;
+ else
+ i->mcast_joined = join;
+
+ return 0;
+}
+
+static int interface_mdns_mcast_rejoin(AvahiInterface *i) {
+ AvahiInterfaceAddress *a, *usable = NULL, *found = NULL;
+ assert(i);
+
+ if (!i->mcast_joined)
+ return 0;
+
+ /* Check whether old address we joined with is still available. If
+ * not, rejoin using an other address. */
+
+ for (a = i->addresses; a; a = a->address_next) {
+ if (a->global_scope && !usable)
+ usable = a;
+
+ if (avahi_address_cmp(&a->address, &i->local_mcast_address) == 0) {
+
+ if (a->global_scope)
+ /* No action necessary: the address still exists and
+ * has global scope. */
+ return 0;
+
+ found = a;
+ }
+ }
+
+ if (found && !usable)
+ /* No action necessary: the address still exists and no better one has been found */
+ return 0;
+
+ interface_mdns_mcast_join(i, 0);
+ return interface_mdns_mcast_join(i, 1);
+}
+
+void avahi_interface_address_free(AvahiInterfaceAddress *a) {