X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-daemon%2Fstatic-hosts.c;h=ebc358df2e3663233a8b3ae9571dd2ba3c37a958;hb=bbf6b92f662ed909d5b4fca4a43b19e815812b3e;hp=17b268beea535ec233e983e2d0a8fa3bc43f112d;hpb=cc7cabaf6b1b8e67a7d1fc92c97ad708ec270859;p=catta diff --git a/avahi-daemon/static-hosts.c b/avahi-daemon/static-hosts.c index 17b268b..ebc358d 100644 --- a/avahi-daemon/static-hosts.c +++ b/avahi-daemon/static-hosts.c @@ -98,7 +98,8 @@ static void static_host_free(StaticHost *s) { AVAHI_LLIST_REMOVE(StaticHost, hosts, hosts, s); - avahi_s_entry_group_free (s->group); + if (s->group) + avahi_s_entry_group_free (s->group); avahi_free(s->host); avahi_free(s->ip); @@ -109,17 +110,27 @@ static void static_host_free(StaticHost *s) { static void add_static_host_to_server(StaticHost *h) { AvahiAddress a; + AvahiProtocol p; int err; + const AvahiServerConfig *config; if (!h->group) - h->group = avahi_s_entry_group_new (avahi_server, entry_group_callback, h); + 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_address_parse (h->ip, AVAHI_PROTO_UNSPEC, &a)) { avahi_log_error("Static host name %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))) { + config = avahi_server_get_config(avahi_server); + + p = (a.proto == AVAHI_PROTO_INET && config->publish_a_on_ipv6) || + (a.proto == AVAHI_PROTO_INET6 && config->publish_aaaa_on_ipv4) ? AVAHI_PROTO_UNSPEC : a.proto; + + if ((err = avahi_server_add_address(avahi_server, h->group, AVAHI_IF_UNSPEC, p, 0, h->host, &a)) < 0) { avahi_log_error ("Static host name %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err)); return; } @@ -129,7 +140,8 @@ static void add_static_host_to_server(StaticHost *h) static void remove_static_host_from_server(StaticHost *h) { - avahi_s_entry_group_reset (h->group); + if (h->group) + avahi_s_entry_group_reset (h->group); } void static_hosts_add_to_server(void) {