+ avahi_interface_update_rrs(i, remove_rrs);
+
+ if (m->list_complete &&
+ !remove_rrs &&
+ m->server->config.publish_workstation &&
+ (m->server->state == AVAHI_SERVER_RUNNING)) {
+
+ if (!hw->entry_group)
+ hw->entry_group = avahi_s_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
+
+ if (!hw->entry_group)
+ return; /* OOM */
+
+ if (avahi_s_entry_group_is_empty(hw->entry_group)) {
+ char name[AVAHI_LABEL_MAX], mac[256];
+
+ avahi_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size);
+ snprintf(name, sizeof(name), "%s [%s]", m->server->host_name, mac);
+
+ if (avahi_server_add_service(m->server, hw->entry_group, hw->index, AVAHI_PROTO_UNSPEC, 0, name, "_workstation._tcp", NULL, NULL, 9, NULL) < 0) {
+ avahi_log_warn(__FILE__": avahi_server_add_service() failed: %s", avahi_strerror(m->server->error));
+ avahi_s_entry_group_free(hw->entry_group);
+ hw->entry_group = NULL;
+ } else
+ avahi_s_entry_group_commit(hw->entry_group);
+ }
+
+ } else {
+
+ if (hw->entry_group && !avahi_s_entry_group_is_empty(hw->entry_group)) {
+
+ if (avahi_s_entry_group_get_state(hw->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING)
+ avahi_server_decrease_host_rr_pending(m->server);
+
+ avahi_s_entry_group_reset(hw->entry_group);
+ }
+ }
+}
+
+void avahi_interface_monitor_update_rrs(AvahiInterfaceMonitor *m, int remove_rrs) {
+ AvahiHwInterface *hw;
+
+ assert(m);
+
+ 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;