X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fiface.c;h=ba232e6f358dfc15d044dedb2d24ed4ab82c0f2d;hb=b30495599b156ac933d091bb0cc1ed669c7887b5;hp=86710449744e25fc30bdaf7b14a0874fb807b44b;hpb=4f0a5e7572a4257894b4bfede42c26d65152609e;p=catta diff --git a/avahi-core/iface.c b/avahi-core/iface.c index 8671044..ba232e6 100644 --- a/avahi-core/iface.c +++ b/avahi-core/iface.c @@ -32,6 +32,7 @@ #include #include +#include #include #include "iface.h" @@ -54,32 +55,40 @@ static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a /* Fill the entry group */ if (!a->entry_group) - a->entry_group = avahi_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL); + a->entry_group = avahi_s_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL); if (!a->entry_group) /* OOM */ return; - if (avahi_entry_group_is_empty(a->entry_group)) { + if (avahi_s_entry_group_is_empty(a->entry_group)) { + char t[64]; + avahi_address_snprint(t, sizeof(t), &a->address); + + avahi_log_info("Registering new address %s on %s.", t, a->interface->hardware->name); if (avahi_server_add_address(m->server, a->entry_group, a->interface->hardware->index, a->interface->protocol, 0, NULL, &a->address) < 0) { avahi_log_warn(__FILE__": avahi_server_add_address() failed: %s", avahi_strerror(m->server->error)); - avahi_entry_group_free(a->entry_group); + avahi_s_entry_group_free(a->entry_group); a->entry_group = NULL; return; } - avahi_entry_group_commit(a->entry_group); + avahi_s_entry_group_commit(a->entry_group); } } else { /* Clear the entry group */ - if (a->entry_group && !avahi_entry_group_is_empty(a->entry_group)) { + if (a->entry_group && !avahi_s_entry_group_is_empty(a->entry_group)) { + char t[64]; + avahi_address_snprint(t, sizeof(t), &a->address); - if (avahi_entry_group_get_state(a->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING) + if (avahi_s_entry_group_get_state(a->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING) avahi_server_decrease_host_rr_pending(m->server); + + avahi_log_info("Withdrawing address %s on %s.", t, a->interface->hardware->name); - avahi_entry_group_reset(a->entry_group); + avahi_s_entry_group_reset(a->entry_group); } } } @@ -109,12 +118,12 @@ static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *h m->server->state == AVAHI_SERVER_REGISTERING)) { if (!hw->entry_group) - hw->entry_group = avahi_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL); + 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_entry_group_is_empty(hw->entry_group)) { + if (avahi_s_entry_group_is_empty(hw->entry_group)) { char *name; char *t; @@ -129,22 +138,22 @@ static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *h if (avahi_server_add_service(m->server, hw->entry_group, hw->index, AVAHI_PROTO_UNSPEC, name, "_workstation._tcp", NULL, NULL, 9, NULL) < 0) { avahi_log_warn(__FILE__": avahi_server_add_service() failed."); - avahi_entry_group_free(hw->entry_group); + avahi_s_entry_group_free(hw->entry_group); hw->entry_group = NULL; } else - avahi_entry_group_commit(hw->entry_group); + avahi_s_entry_group_commit(hw->entry_group); avahi_free(name); } } else { - if (hw->entry_group && !avahi_entry_group_is_empty(hw->entry_group)) { + if (hw->entry_group && !avahi_s_entry_group_is_empty(hw->entry_group)) { - if (avahi_entry_group_get_state(hw->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING) + if (avahi_s_entry_group_get_state(hw->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING) avahi_server_decrease_host_rr_pending(m->server); - avahi_entry_group_reset(hw->entry_group); + avahi_s_entry_group_reset(hw->entry_group); } } } @@ -158,7 +167,7 @@ static void free_address(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a) { AVAHI_LLIST_REMOVE(AvahiInterfaceAddress, address, a->interface->addresses, a); if (a->entry_group) - avahi_entry_group_free(a->entry_group); + avahi_s_entry_group_free(a->entry_group); avahi_free(a); } @@ -198,7 +207,7 @@ static void free_hw_interface(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, in free_interface(m, hw->interfaces, send_goodbye); if (hw->entry_group) - avahi_entry_group_free(hw->entry_group); + avahi_s_entry_group_free(hw->entry_group); AVAHI_LLIST_REMOVE(AvahiHwInterface, hardware, m->hw_interfaces, hw); avahi_hashmap_remove(m->hashmap, &hw->index); @@ -344,7 +353,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat AvahiHwInterface *hw; struct rtattr *a = NULL; size_t l; - + if (ifinfomsg->ifi_family != AF_UNSPEC) return; @@ -507,7 +516,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat m->list = LIST_ADDR; } else { m->list = LIST_DONE; - avahi_log_debug("Enumeration complete"); + avahi_log_debug("Network interface enumeration completed"); } } else if (n->nlmsg_type == NLMSG_ERROR && (n->nlmsg_seq == m->query_link_seq || n->nlmsg_seq == m->query_addr_seq)) { @@ -822,3 +831,21 @@ int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a) { return 0; } + +int avahi_interface_has_address(AvahiInterfaceMonitor *m, AvahiIfIndex iface, const AvahiAddress *a) { + AvahiInterface *i; + AvahiInterfaceAddress *j; + + assert(m); + assert(iface != AVAHI_IF_UNSPEC); + assert(a); + + if (!(i = avahi_interface_monitor_get_interface(m, iface, a->family))) + return 0; + + for (j = i->addresses; j; j = j->address_next) + if (avahi_address_cmp(a, &j->address) == 0) + return 1; + + return 0; +}