- h->group = avahi_s_entry_group_new (avahi_server, entry_group_callback, h);
-
- if (!avahi_address_parse (h->ip, AVAHI_PROTO_UNSPEC, &a)) {
- avahi_log_error("Static host %s: avahi_address_parse failed", h->host);
- return;
- }
-
- if ((err = avahi_server_add_address(avahi_server, h->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, h->host, &a))) {
- avahi_log_error ("Static host %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err));
- return;
+ if (!(h->group = avahi_s_entry_group_new (avahi_server, entry_group_callback, h))) {
+ avahi_log_error("avahi_s_entry_group_new() failed: %s", avahi_strerror(avahi_server_errno(avahi_server)));
+ return;
+ }
+
+ if (avahi_s_entry_group_is_empty(h->group)) {
+ AvahiProtocol p;
+ int err;
+ const AvahiServerConfig *config;
+ config = avahi_server_get_config(avahi_server);
+
+ p = (h->address.proto == AVAHI_PROTO_INET && config->publish_a_on_ipv6) ||
+ (h->address.proto == AVAHI_PROTO_INET6 && config->publish_aaaa_on_ipv4) ? AVAHI_PROTO_UNSPEC : h->address.proto;
+
+ if ((err = avahi_server_add_address(avahi_server, h->group, AVAHI_IF_UNSPEC, p, 0, h->host, &h->address)) < 0) {
+ avahi_log_error ("Static host name %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err));
+ return;
+ }
+
+ avahi_s_entry_group_commit (h->group);