]> git.meshlink.io Git - catta/blobdiff - src/iface.c
rename everything avahi to catta
[catta] / src / iface.c
index aed4caddf66f0cc08f6299c7070a6d243cd31924..0940d63060f5ccd20916dea1a2fb49c8a2a90dd3 100644 (file)
@@ -1,18 +1,18 @@
 /***
-  This file is part of avahi.
+  This file is part of catta.
 
-  avahi is free software; you can redistribute it and/or modify it
+  catta is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1 of the
   License, or (at your option) any later version.
 
-  avahi is distributed in the hope that it will be useful, but WITHOUT
+  catta is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
   Public License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with avahi; if not, write to the Free Software
+  License along with catta; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
 #include <sys/socket.h>
 #include <netinet/in.h>
 
-#include <avahi/error.h>
-#include <avahi/malloc.h>
-#include <avahi/domain.h>
-#include <avahi/log.h>
+#include <catta/error.h>
+#include <catta/malloc.h>
+#include <catta/domain.h>
+#include <catta/log.h>
 
 #include "iface.h"
 #include "dns.h"
 #include "multicast-lookup.h"
 #include "querier.h"
 
-void avahi_interface_address_update_rrs(AvahiInterfaceAddress *a, int remove_rrs) {
-    AvahiInterfaceMonitor *m;
+void catta_interface_address_update_rrs(CattaInterfaceAddress *a, int remove_rrs) {
+    CattaInterfaceMonitor *m;
 
     assert(a);
     m = a->monitor;
 
     if (m->list_complete &&
-        avahi_interface_address_is_relevant(a) &&
-        avahi_interface_is_relevant(a->interface) &&
+        catta_interface_address_is_relevant(a) &&
+        catta_interface_is_relevant(a->interface) &&
         !remove_rrs &&
         m->server->config.publish_addresses &&
-        (m->server->state == AVAHI_SERVER_RUNNING ||
-        m->server->state == AVAHI_SERVER_REGISTERING)) {
+        (m->server->state == CATTA_SERVER_RUNNING ||
+        m->server->state == CATTA_SERVER_REGISTERING)) {
 
         /* Fill the entry group */
         if (!a->entry_group)
-            a->entry_group = avahi_s_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
+            a->entry_group = catta_s_entry_group_new(m->server, catta_host_rr_entry_group_callback, NULL);
 
         if (!a->entry_group) /* OOM */
             return;
 
-        if (avahi_s_entry_group_is_empty(a->entry_group)) {
-            char t[AVAHI_ADDRESS_STR_MAX];
-            AvahiProtocol p;
+        if (catta_s_entry_group_is_empty(a->entry_group)) {
+            char t[CATTA_ADDRESS_STR_MAX];
+            CattaProtocol p;
 
-            p = (a->interface->protocol == AVAHI_PROTO_INET && m->server->config.publish_a_on_ipv6) ||
-                (a->interface->protocol == AVAHI_PROTO_INET6 && m->server->config.publish_aaaa_on_ipv4) ? AVAHI_PROTO_UNSPEC : a->interface->protocol;
+            p = (a->interface->protocol == CATTA_PROTO_INET && m->server->config.publish_a_on_ipv6) ||
+                (a->interface->protocol == CATTA_PROTO_INET6 && m->server->config.publish_aaaa_on_ipv4) ? CATTA_PROTO_UNSPEC : a->interface->protocol;
 
-            avahi_address_snprint(t, sizeof(t), &a->address);
-            avahi_log_info("Registering new address record for %s on %s.%s.", t, a->interface->hardware->name, p == AVAHI_PROTO_UNSPEC ? "*" : avahi_proto_to_string(p));
+            catta_address_snprint(t, sizeof(t), &a->address);
+            catta_log_info("Registering new address record for %s on %s.%s.", t, a->interface->hardware->name, p == CATTA_PROTO_UNSPEC ? "*" : catta_proto_to_string(p));
 
-            if (avahi_server_add_address(m->server, a->entry_group, a->interface->hardware->index, p, m->server->config.publish_no_reverse ? AVAHI_PUBLISH_NO_REVERSE : 0, NULL, &a->address) < 0) {
-                avahi_log_warn(__FILE__": avahi_server_add_address() failed: %s", avahi_strerror(m->server->error));
-                avahi_s_entry_group_free(a->entry_group);
+            if (catta_server_add_address(m->server, a->entry_group, a->interface->hardware->index, p, m->server->config.publish_no_reverse ? CATTA_PUBLISH_NO_REVERSE : 0, NULL, &a->address) < 0) {
+                catta_log_warn(__FILE__": catta_server_add_address() failed: %s", catta_strerror(m->server->error));
+                catta_s_entry_group_free(a->entry_group);
                 a->entry_group = NULL;
                 return;
             }
 
-            avahi_s_entry_group_commit(a->entry_group);
+            catta_s_entry_group_commit(a->entry_group);
         }
     } else {
 
         /* Clear the entry group */
 
-        if (a->entry_group && !avahi_s_entry_group_is_empty(a->entry_group)) {
-            char t[AVAHI_ADDRESS_STR_MAX];
-            avahi_address_snprint(t, sizeof(t), &a->address);
+        if (a->entry_group && !catta_s_entry_group_is_empty(a->entry_group)) {
+            char t[CATTA_ADDRESS_STR_MAX];
+            catta_address_snprint(t, sizeof(t), &a->address);
 
-            avahi_log_info("Withdrawing address record for %s on %s.", t, a->interface->hardware->name);
+            catta_log_info("Withdrawing address record for %s on %s.", t, a->interface->hardware->name);
 
-            if (avahi_s_entry_group_get_state(a->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING &&
-                m->server->state == AVAHI_SERVER_REGISTERING)
-                avahi_server_decrease_host_rr_pending(m->server);
+            if (catta_s_entry_group_get_state(a->entry_group) == CATTA_ENTRY_GROUP_REGISTERING &&
+                m->server->state == CATTA_SERVER_REGISTERING)
+                catta_server_decrease_host_rr_pending(m->server);
 
-            avahi_s_entry_group_reset(a->entry_group);
+            catta_s_entry_group_reset(a->entry_group);
         }
     }
 }
 
-void avahi_interface_update_rrs(AvahiInterface *i, int remove_rrs) {
-    AvahiInterfaceAddress *a;
+void catta_interface_update_rrs(CattaInterface *i, int remove_rrs) {
+    CattaInterfaceAddress *a;
 
     assert(i);
 
     for (a = i->addresses; a; a = a->address_next)
-        avahi_interface_address_update_rrs(a, remove_rrs);
+        catta_interface_address_update_rrs(a, remove_rrs);
 }
 
-void avahi_hw_interface_update_rrs(AvahiHwInterface *hw, int remove_rrs) {
-    AvahiInterface *i;
-    AvahiInterfaceMonitor *m;
+void catta_hw_interface_update_rrs(CattaHwInterface *hw, int remove_rrs) {
+    CattaInterface *i;
+    CattaInterfaceMonitor *m;
 
     assert(hw);
     m = hw->monitor;
 
     for (i = hw->interfaces; i; i = i->by_hardware_next)
-        avahi_interface_update_rrs(i, remove_rrs);
+        catta_interface_update_rrs(i, remove_rrs);
 
     if (m->list_complete &&
         !remove_rrs &&
         m->server->config.publish_workstation &&
-        (m->server->state == AVAHI_SERVER_RUNNING)) {
+        (m->server->state == CATTA_SERVER_RUNNING)) {
 
         if (!hw->entry_group)
-            hw->entry_group = avahi_s_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
+            hw->entry_group = catta_s_entry_group_new(m->server, catta_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], unescaped[AVAHI_LABEL_MAX], mac[256];
+        if (catta_s_entry_group_is_empty(hw->entry_group)) {
+            char name[CATTA_LABEL_MAX], unescaped[CATTA_LABEL_MAX], mac[256];
             const char *p = m->server->host_name;
 
-            avahi_unescape_label(&p, unescaped, sizeof(unescaped));
-            avahi_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size);
+            catta_unescape_label(&p, unescaped, sizeof(unescaped));
+            catta_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size);
             snprintf(name, sizeof(name), "%s [%s]", unescaped, 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);
+            if (catta_server_add_service(m->server, hw->entry_group, hw->index, CATTA_PROTO_UNSPEC, 0, name, "_workstation._tcp", NULL, NULL, 9, NULL) < 0) {
+                catta_log_warn(__FILE__": catta_server_add_service() failed: %s", catta_strerror(m->server->error));
+                catta_s_entry_group_free(hw->entry_group);
                 hw->entry_group = NULL;
             } else
-                avahi_s_entry_group_commit(hw->entry_group);
+                catta_s_entry_group_commit(hw->entry_group);
         }
 
     } else {
 
-        if (hw->entry_group && !avahi_s_entry_group_is_empty(hw->entry_group)) {
+        if (hw->entry_group && !catta_s_entry_group_is_empty(hw->entry_group)) {
 
-            avahi_log_info("Withdrawing workstation service for %s.", hw->name);
+            catta_log_info("Withdrawing workstation service for %s.", hw->name);
 
-            if (avahi_s_entry_group_get_state(hw->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING &&
-                m->server->state == AVAHI_SERVER_REGISTERING)
-                avahi_server_decrease_host_rr_pending(m->server);
+            if (catta_s_entry_group_get_state(hw->entry_group) == CATTA_ENTRY_GROUP_REGISTERING &&
+                m->server->state == CATTA_SERVER_REGISTERING)
+                catta_server_decrease_host_rr_pending(m->server);
 
-            avahi_s_entry_group_reset(hw->entry_group);
+            catta_s_entry_group_reset(hw->entry_group);
         }
     }
 }
 
-void avahi_interface_monitor_update_rrs(AvahiInterfaceMonitor *m, int remove_rrs) {
-    AvahiHwInterface *hw;
+void catta_interface_monitor_update_rrs(CattaInterfaceMonitor *m, int remove_rrs) {
+    CattaHwInterface *hw;
 
     assert(m);
 
     for (hw = m->hw_interfaces; hw; hw = hw->hardware_next)
-        avahi_hw_interface_update_rrs(hw, remove_rrs);
+        catta_hw_interface_update_rrs(hw, remove_rrs);
 }
 
-static int interface_mdns_mcast_join(AvahiInterface *i, int join) {
-    char at[AVAHI_ADDRESS_STR_MAX];
+static int interface_mdns_mcast_join(CattaInterface *i, int join) {
+    char at[CATTA_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))
+    if ((i->protocol == CATTA_PROTO_INET6 && i->monitor->server->fd_ipv6 < 0) ||
+        (i->protocol == CATTA_PROTO_INET && i->monitor->server->fd_ipv4 < 0))
         return -1;
 
     if (join) {
-        AvahiInterfaceAddress *a;
+        CattaInterfaceAddress *a;
 
         /* Look if there's an address with global scope */
         for (a = i->addresses; a; a = a->address_next)
@@ -203,18 +203,18 @@ static int interface_mdns_mcast_join(AvahiInterface *i, int join) {
         i->local_mcast_address = a->address;
     }
 
-    avahi_log_info("%s mDNS multicast group on interface %s.%s with address %s.",
+    catta_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));
+                   catta_proto_to_string(i->protocol),
+                   catta_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);
+    if (i->protocol == CATTA_PROTO_INET6)
+        r = catta_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);
+        assert(i->protocol == CATTA_PROTO_INET);
 
-        r = avahi_mdns_mcast_join_ipv4(i->monitor->server->fd_ipv4, &i->local_mcast_address.data.ipv4, i->hardware->index, join);
+        r = catta_mdns_mcast_join_ipv4(i->monitor->server->fd_ipv4, &i->local_mcast_address.data.ipv4, i->hardware->index, join);
     }
 
     if (r < 0)
@@ -225,8 +225,8 @@ static int interface_mdns_mcast_join(AvahiInterface *i, int join) {
     return 0;
 }
 
-static int interface_mdns_mcast_rejoin(AvahiInterface *i) {
-    AvahiInterfaceAddress *a, *usable = NULL, *found = NULL;
+static int interface_mdns_mcast_rejoin(CattaInterface *i) {
+    CattaInterfaceAddress *a, *usable = NULL, *found = NULL;
     assert(i);
 
     if (!i->mcast_joined)
@@ -239,7 +239,7 @@ static int interface_mdns_mcast_rejoin(AvahiInterface *i) {
         if (a->global_scope && !usable)
             usable = a;
 
-        if (avahi_address_cmp(&a->address, &i->local_mcast_address) == 0) {
+        if (catta_address_cmp(&a->address, &i->local_mcast_address) == 0) {
 
             if (a->global_scope)
                 /* No action necessary: the address still exists and
@@ -258,79 +258,79 @@ static int interface_mdns_mcast_rejoin(AvahiInterface *i) {
     return interface_mdns_mcast_join(i, 1);
 }
 
-void avahi_interface_address_free(AvahiInterfaceAddress *a) {
+void catta_interface_address_free(CattaInterfaceAddress *a) {
     assert(a);
     assert(a->interface);
 
-    avahi_interface_address_update_rrs(a, 1);
-    AVAHI_LLIST_REMOVE(AvahiInterfaceAddress, address, a->interface->addresses, a);
+    catta_interface_address_update_rrs(a, 1);
+    CATTA_LLIST_REMOVE(CattaInterfaceAddress, address, a->interface->addresses, a);
 
     if (a->entry_group)
-        avahi_s_entry_group_free(a->entry_group);
+        catta_s_entry_group_free(a->entry_group);
 
     interface_mdns_mcast_rejoin(a->interface);
 
-    avahi_free(a);
+    catta_free(a);
 }
 
-void avahi_interface_free(AvahiInterface *i, int send_goodbye) {
+void catta_interface_free(CattaInterface *i, int send_goodbye) {
     assert(i);
 
     /* Handle goodbyes and remove announcers */
-    avahi_goodbye_interface(i->monitor->server, i, send_goodbye, 1);
-    avahi_response_scheduler_force(i->response_scheduler);
+    catta_goodbye_interface(i->monitor->server, i, send_goodbye, 1);
+    catta_response_scheduler_force(i->response_scheduler);
     assert(!i->announcers);
 
     if (i->mcast_joined)
         interface_mdns_mcast_join(i, 0);
 
     /* Remove queriers */
-    avahi_querier_free_all(i);
-    avahi_hashmap_free(i->queriers_by_key);
+    catta_querier_free_all(i);
+    catta_hashmap_free(i->queriers_by_key);
 
     /* Remove local RRs */
-    avahi_interface_update_rrs(i, 1);
+    catta_interface_update_rrs(i, 1);
 
     while (i->addresses)
-        avahi_interface_address_free(i->addresses);
+        catta_interface_address_free(i->addresses);
 
-    avahi_response_scheduler_free(i->response_scheduler);
-    avahi_query_scheduler_free(i->query_scheduler);
-    avahi_probe_scheduler_free(i->probe_scheduler);
-    avahi_cache_free(i->cache);
+    catta_response_scheduler_free(i->response_scheduler);
+    catta_query_scheduler_free(i->query_scheduler);
+    catta_probe_scheduler_free(i->probe_scheduler);
+    catta_cache_free(i->cache);
 
-    AVAHI_LLIST_REMOVE(AvahiInterface, interface, i->monitor->interfaces, i);
-    AVAHI_LLIST_REMOVE(AvahiInterface, by_hardware, i->hardware->interfaces, i);
+    CATTA_LLIST_REMOVE(CattaInterface, interface, i->monitor->interfaces, i);
+    CATTA_LLIST_REMOVE(CattaInterface, by_hardware, i->hardware->interfaces, i);
 
-    avahi_free(i);
+    catta_free(i);
 }
 
-void avahi_hw_interface_free(AvahiHwInterface *hw, int send_goodbye) {
+void catta_hw_interface_free(CattaHwInterface *hw, int send_goodbye) {
     assert(hw);
 
-    avahi_hw_interface_update_rrs(hw, 1);
+    catta_hw_interface_update_rrs(hw, 1);
 
     while (hw->interfaces)
-        avahi_interface_free(hw->interfaces, send_goodbye);
+        catta_interface_free(hw->interfaces, send_goodbye);
 
     if (hw->entry_group)
-        avahi_s_entry_group_free(hw->entry_group);
+        catta_s_entry_group_free(hw->entry_group);
 
-    AVAHI_LLIST_REMOVE(AvahiHwInterface, hardware, hw->monitor->hw_interfaces, hw);
-    avahi_hashmap_remove(hw->monitor->hashmap, &hw->index);
+    CATTA_LLIST_REMOVE(CattaHwInterface, hardware, hw->monitor->hw_interfaces, hw);
+    catta_hashmap_remove(hw->monitor->hashmap, &hw->index);
 
-    avahi_free(hw->name);
-    avahi_free(hw);
+    catta_free(hw->name);
+    catta_free(hw);
 }
 
-AvahiInterface* avahi_interface_new(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, AvahiProtocol protocol) {
-    AvahiInterface *i;
+CattaInterface* catta_interface_new(CattaInterfaceMonitor *m, CattaHwInterface *hw, CattaProtocol protocol) {
+    CattaInterface *i;
 
     assert(m);
     assert(hw);
-    assert(AVAHI_PROTO_VALID(protocol));
+    assert(CATTA_PROTO_VALID(protocol));
 
-    if (!(i = avahi_new(AvahiInterface, 1)))
+    if (!(i = catta_new(CattaInterface, 1)))
         goto fail; /* OOM */
 
     i->monitor = m;
@@ -339,22 +339,22 @@ AvahiInterface* avahi_interface_new(AvahiInterfaceMonitor *m, AvahiHwInterface *
     i->announcing = 0;
     i->mcast_joined = 0;
 
-    AVAHI_LLIST_HEAD_INIT(AvahiInterfaceAddress, i->addresses);
-    AVAHI_LLIST_HEAD_INIT(AvahiAnnouncer, i->announcers);
+    CATTA_LLIST_HEAD_INIT(CattaInterfaceAddress, i->addresses);
+    CATTA_LLIST_HEAD_INIT(CattaAnnouncer, i->announcers);
 
-    AVAHI_LLIST_HEAD_INIT(AvahiQuerier, i->queriers);
-    i->queriers_by_key = avahi_hashmap_new((AvahiHashFunc) avahi_key_hash, (AvahiEqualFunc) avahi_key_equal, NULL, NULL);
+    CATTA_LLIST_HEAD_INIT(CattaQuerier, i->queriers);
+    i->queriers_by_key = catta_hashmap_new((CattaHashFunc) catta_key_hash, (CattaEqualFunc) catta_key_equal, NULL, NULL);
 
-    i->cache = avahi_cache_new(m->server, i);
-    i->response_scheduler = avahi_response_scheduler_new(i);
-    i->query_scheduler = avahi_query_scheduler_new(i);
-    i->probe_scheduler = avahi_probe_scheduler_new(i);
+    i->cache = catta_cache_new(m->server, i);
+    i->response_scheduler = catta_response_scheduler_new(i);
+    i->query_scheduler = catta_query_scheduler_new(i);
+    i->probe_scheduler = catta_probe_scheduler_new(i);
 
     if (!i->cache || !i->response_scheduler || !i->query_scheduler || !i->probe_scheduler)
         goto fail; /* OOM */
 
-    AVAHI_LLIST_PREPEND(AvahiInterface, by_hardware, hw->interfaces, i);
-    AVAHI_LLIST_PREPEND(AvahiInterface, interface, m->interfaces, i);
+    CATTA_LLIST_PREPEND(CattaInterface, by_hardware, hw->interfaces, i);
+    CATTA_LLIST_PREPEND(CattaInterface, interface, m->interfaces, i);
 
     return i;
 
@@ -362,25 +362,25 @@ fail:
 
     if (i) {
         if (i->cache)
-            avahi_cache_free(i->cache);
+            catta_cache_free(i->cache);
         if (i->response_scheduler)
-            avahi_response_scheduler_free(i->response_scheduler);
+            catta_response_scheduler_free(i->response_scheduler);
         if (i->query_scheduler)
-            avahi_query_scheduler_free(i->query_scheduler);
+            catta_query_scheduler_free(i->query_scheduler);
         if (i->probe_scheduler)
-            avahi_probe_scheduler_free(i->probe_scheduler);
+            catta_probe_scheduler_free(i->probe_scheduler);
     }
 
     return NULL;
 }
 
-AvahiHwInterface *avahi_hw_interface_new(AvahiInterfaceMonitor *m, AvahiIfIndex idx) {
-    AvahiHwInterface *hw;
+CattaHwInterface *catta_hw_interface_new(CattaInterfaceMonitor *m, CattaIfIndex idx) {
+    CattaHwInterface *hw;
 
     assert(m);
-    assert(AVAHI_IF_VALID(idx));
+    assert(CATTA_IF_VALID(idx));
 
-    if  (!(hw = avahi_new(AvahiHwInterface, 1)))
+    if  (!(hw = catta_new(CattaHwInterface, 1)))
         return NULL;
 
     hw->monitor = m;
@@ -394,26 +394,26 @@ AvahiHwInterface *avahi_hw_interface_new(AvahiInterfaceMonitor *m, AvahiIfIndex
     hw->ratelimit_begin.tv_usec = 0;
     hw->ratelimit_counter = 0;
 
-    AVAHI_LLIST_HEAD_INIT(AvahiInterface, hw->interfaces);
-    AVAHI_LLIST_PREPEND(AvahiHwInterface, hardware, m->hw_interfaces, hw);
+    CATTA_LLIST_HEAD_INIT(CattaInterface, hw->interfaces);
+    CATTA_LLIST_PREPEND(CattaHwInterface, hardware, m->hw_interfaces, hw);
 
-    avahi_hashmap_insert(m->hashmap, &hw->index, hw);
+    catta_hashmap_insert(m->hashmap, &hw->index, hw);
 
     if (m->server->fd_ipv4 >= 0 || m->server->config.publish_a_on_ipv6)
-        avahi_interface_new(m, hw, AVAHI_PROTO_INET);
+        catta_interface_new(m, hw, CATTA_PROTO_INET);
     if (m->server->fd_ipv6 >= 0 || m->server->config.publish_aaaa_on_ipv4)
-        avahi_interface_new(m, hw, AVAHI_PROTO_INET6);
+        catta_interface_new(m, hw, CATTA_PROTO_INET6);
 
     return hw;
 }
 
-AvahiInterfaceAddress *avahi_interface_address_new(AvahiInterfaceMonitor *m, AvahiInterface *i, const AvahiAddress *addr, unsigned prefix_len) {
-    AvahiInterfaceAddress *a;
+CattaInterfaceAddress *catta_interface_address_new(CattaInterfaceMonitor *m, CattaInterface *i, const CattaAddress *addr, unsigned prefix_len) {
+    CattaInterfaceAddress *a;
 
     assert(m);
     assert(i);
 
-    if (!(a = avahi_new(AvahiInterfaceAddress, 1)))
+    if (!(a = catta_new(CattaInterfaceAddress, 1)))
         return NULL;
 
     a->interface = i;
@@ -424,43 +424,43 @@ AvahiInterfaceAddress *avahi_interface_address_new(AvahiInterfaceMonitor *m, Ava
     a->deprecated = 0;
     a->entry_group = NULL;
 
-    AVAHI_LLIST_PREPEND(AvahiInterfaceAddress, address, i->addresses, a);
+    CATTA_LLIST_PREPEND(CattaInterfaceAddress, address, i->addresses, a);
 
     return a;
 }
 
-void avahi_interface_check_relevant(AvahiInterface *i) {
+void catta_interface_check_relevant(CattaInterface *i) {
     int b;
-    AvahiInterfaceMonitor *m;
+    CattaInterfaceMonitor *m;
 
     assert(i);
     m = i->monitor;
 
-    b = avahi_interface_is_relevant(i);
+    b = catta_interface_is_relevant(i);
 
     if (m->list_complete && b && !i->announcing) {
         interface_mdns_mcast_join(i, 1);
 
         if (i->mcast_joined) {
-            avahi_log_info("New relevant interface %s.%s for mDNS.", i->hardware->name, avahi_proto_to_string(i->protocol));
+            catta_log_info("New relevant interface %s.%s for mDNS.", i->hardware->name, catta_proto_to_string(i->protocol));
 
             i->announcing = 1;
-            avahi_announce_interface(m->server, i);
-            avahi_multicast_lookup_engine_new_interface(m->server->multicast_lookup_engine, i);
+            catta_announce_interface(m->server, i);
+            catta_multicast_lookup_engine_new_interface(m->server->multicast_lookup_engine, i);
         }
 
     } else if (!b && i->announcing) {
-        avahi_log_info("Interface %s.%s no longer relevant for mDNS.", i->hardware->name, avahi_proto_to_string(i->protocol));
+        catta_log_info("Interface %s.%s no longer relevant for mDNS.", i->hardware->name, catta_proto_to_string(i->protocol));
 
         interface_mdns_mcast_join(i, 0);
 
-        avahi_goodbye_interface(m->server, i, 0, 1);
-        avahi_querier_free_all(i);
+        catta_goodbye_interface(m->server, i, 0, 1);
+        catta_querier_free_all(i);
 
-        avahi_response_scheduler_clear(i->response_scheduler);
-        avahi_query_scheduler_clear(i->query_scheduler);
-        avahi_probe_scheduler_clear(i->probe_scheduler);
-        avahi_cache_flush(i->cache);
+        catta_response_scheduler_clear(i->response_scheduler);
+        catta_query_scheduler_clear(i->query_scheduler);
+        catta_probe_scheduler_clear(i->probe_scheduler);
+        catta_cache_flush(i->cache);
 
         i->announcing = 0;
 
@@ -468,73 +468,73 @@ void avahi_interface_check_relevant(AvahiInterface *i) {
         interface_mdns_mcast_rejoin(i);
 }
 
-void avahi_hw_interface_check_relevant(AvahiHwInterface *hw) {
-    AvahiInterface *i;
+void catta_hw_interface_check_relevant(CattaHwInterface *hw) {
+    CattaInterface *i;
 
     assert(hw);
 
     for (i = hw->interfaces; i; i = i->by_hardware_next)
-        avahi_interface_check_relevant(i);
+        catta_interface_check_relevant(i);
 }
 
-void avahi_interface_monitor_check_relevant(AvahiInterfaceMonitor *m) {
-    AvahiInterface *i;
+void catta_interface_monitor_check_relevant(CattaInterfaceMonitor *m) {
+    CattaInterface *i;
 
     assert(m);
 
     for (i = m->interfaces; i; i = i->interface_next)
-        avahi_interface_check_relevant(i);
+        catta_interface_check_relevant(i);
 }
 
-AvahiInterfaceMonitor *avahi_interface_monitor_new(AvahiServer *s) {
-    AvahiInterfaceMonitor *m = NULL;
+CattaInterfaceMonitor *catta_interface_monitor_new(CattaServer *s) {
+    CattaInterfaceMonitor *m = NULL;
 
-    if (!(m = avahi_new0(AvahiInterfaceMonitor, 1)))
+    if (!(m = catta_new0(CattaInterfaceMonitor, 1)))
         return NULL; /* OOM */
 
     m->server = s;
     m->list_complete = 0;
-    m->hashmap = avahi_hashmap_new(avahi_int_hash, avahi_int_equal, NULL, NULL);
+    m->hashmap = catta_hashmap_new(catta_int_hash, catta_int_equal, NULL, NULL);
 
-    AVAHI_LLIST_HEAD_INIT(AvahiInterface, m->interfaces);
-    AVAHI_LLIST_HEAD_INIT(AvahiHwInterface, m->hw_interfaces);
+    CATTA_LLIST_HEAD_INIT(CattaInterface, m->interfaces);
+    CATTA_LLIST_HEAD_INIT(CattaHwInterface, m->hw_interfaces);
 
-    if (avahi_interface_monitor_init_osdep(m) < 0)
+    if (catta_interface_monitor_init_osdep(m) < 0)
         goto fail;
 
     return m;
 
 fail:
-    avahi_interface_monitor_free(m);
+    catta_interface_monitor_free(m);
     return NULL;
 }
 
-void avahi_interface_monitor_free(AvahiInterfaceMonitor *m) {
+void catta_interface_monitor_free(CattaInterfaceMonitor *m) {
     assert(m);
 
     while (m->hw_interfaces)
-        avahi_hw_interface_free(m->hw_interfaces, 1);
+        catta_hw_interface_free(m->hw_interfaces, 1);
 
     assert(!m->interfaces);
 
-    avahi_interface_monitor_free_osdep(m);
+    catta_interface_monitor_free_osdep(m);
 
     if (m->hashmap)
-        avahi_hashmap_free(m->hashmap);
+        catta_hashmap_free(m->hashmap);
 
-    avahi_free(m);
+    catta_free(m);
 }
 
 
-AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol) {
-    AvahiHwInterface *hw;
-    AvahiInterface *i;
+CattaInterface* catta_interface_monitor_get_interface(CattaInterfaceMonitor *m, CattaIfIndex idx, CattaProtocol protocol) {
+    CattaHwInterface *hw;
+    CattaInterface *i;
 
     assert(m);
     assert(idx >= 0);
-    assert(protocol != AVAHI_PROTO_UNSPEC);
+    assert(protocol != CATTA_PROTO_UNSPEC);
 
-    if (!(hw = avahi_interface_monitor_get_hw_interface(m, idx)))
+    if (!(hw = catta_interface_monitor_get_hw_interface(m, idx)))
         return NULL;
 
     for (i = hw->interfaces; i; i = i->by_hardware_next)
@@ -544,28 +544,28 @@ AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m,
     return NULL;
 }
 
-AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx) {
+CattaHwInterface* catta_interface_monitor_get_hw_interface(CattaInterfaceMonitor *m, CattaIfIndex idx) {
     assert(m);
     assert(idx >= 0);
 
-    return avahi_hashmap_lookup(m->hashmap, &idx);
+    return catta_hashmap_lookup(m->hashmap, &idx);
 }
 
-AvahiInterfaceAddress* avahi_interface_monitor_get_address(AvahiInterfaceMonitor *m, AvahiInterface *i, const AvahiAddress *raddr) {
-    AvahiInterfaceAddress *ia;
+CattaInterfaceAddress* catta_interface_monitor_get_address(CattaInterfaceMonitor *m, CattaInterface *i, const CattaAddress *raddr) {
+    CattaInterfaceAddress *ia;
 
     assert(m);
     assert(i);
     assert(raddr);
 
     for (ia = i->addresses; ia; ia = ia->address_next)
-        if (avahi_address_cmp(&ia->address, raddr) == 0)
+        if (catta_address_cmp(&ia->address, raddr) == 0)
             return ia;
 
     return NULL;
 }
 
-void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, uint16_t port) {
+void catta_interface_send_packet_unicast(CattaInterface *i, CattaDnsPacket *p, const CattaAddress *a, uint16_t port) {
     assert(i);
     assert(p);
 
@@ -580,10 +580,10 @@ void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, c
         gettimeofday(&now, NULL);
 
         end = i->hardware->ratelimit_begin;
-        avahi_timeval_add(&end, i->monitor->server->config.ratelimit_interval);
+        catta_timeval_add(&end, i->monitor->server->config.ratelimit_interval);
 
         if (i->hardware->ratelimit_begin.tv_sec <= 0 ||
-            avahi_timeval_compare(&end, &now) < 0) {
+            catta_timeval_compare(&end, &now) < 0) {
 
             i->hardware->ratelimit_begin = now;
             i->hardware->ratelimit_counter = 0;
@@ -595,64 +595,64 @@ void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, c
         i->hardware->ratelimit_counter++;
     }
 
-    if (i->protocol == AVAHI_PROTO_INET && i->monitor->server->fd_ipv4 >= 0)
-        avahi_send_dns_packet_ipv4(i->monitor->server->fd_ipv4, i->hardware->index, p, i->mcast_joined ? &i->local_mcast_address.data.ipv4 : NULL, a ? &a->data.ipv4 : NULL, port);
-    else if (i->protocol == AVAHI_PROTO_INET6 && i->monitor->server->fd_ipv6 >= 0)
-        avahi_send_dns_packet_ipv6(i->monitor->server->fd_ipv6, i->hardware->index, p, i->mcast_joined ? &i->local_mcast_address.data.ipv6 : NULL, a ? &a->data.ipv6 : NULL, port);
+    if (i->protocol == CATTA_PROTO_INET && i->monitor->server->fd_ipv4 >= 0)
+        catta_send_dns_packet_ipv4(i->monitor->server->fd_ipv4, i->hardware->index, p, i->mcast_joined ? &i->local_mcast_address.data.ipv4 : NULL, a ? &a->data.ipv4 : NULL, port);
+    else if (i->protocol == CATTA_PROTO_INET6 && i->monitor->server->fd_ipv6 >= 0)
+        catta_send_dns_packet_ipv6(i->monitor->server->fd_ipv6, i->hardware->index, p, i->mcast_joined ? &i->local_mcast_address.data.ipv6 : NULL, a ? &a->data.ipv6 : NULL, port);
 }
 
-void avahi_interface_send_packet(AvahiInterface *i, AvahiDnsPacket *p) {
+void catta_interface_send_packet(CattaInterface *i, CattaDnsPacket *p) {
     assert(i);
     assert(p);
 
-    avahi_interface_send_packet_unicast(i, p, NULL, 0);
+    catta_interface_send_packet_unicast(i, p, NULL, 0);
 }
 
-int avahi_interface_post_query(AvahiInterface *i, AvahiKey *key, int immediately, unsigned *ret_id) {
+int catta_interface_post_query(CattaInterface *i, CattaKey *key, int immediately, unsigned *ret_id) {
     assert(i);
     assert(key);
 
     if (!i->announcing)
         return 0;
 
-    return avahi_query_scheduler_post(i->query_scheduler, key, immediately, ret_id);
+    return catta_query_scheduler_post(i->query_scheduler, key, immediately, ret_id);
 }
 
-int avahi_interface_withraw_query(AvahiInterface *i, unsigned id) {
+int catta_interface_withraw_query(CattaInterface *i, unsigned id) {
 
-    return avahi_query_scheduler_withdraw_by_id(i->query_scheduler, id);
+    return catta_query_scheduler_withdraw_by_id(i->query_scheduler, id);
 }
 
-int avahi_interface_post_response(AvahiInterface *i, AvahiRecord *record, int flush_cache, const AvahiAddress *querier, int immediately) {
+int catta_interface_post_response(CattaInterface *i, CattaRecord *record, int flush_cache, const CattaAddress *querier, int immediately) {
     assert(i);
     assert(record);
 
     if (!i->announcing)
         return 0;
 
-    return avahi_response_scheduler_post(i->response_scheduler, record, flush_cache, querier, immediately);
+    return catta_response_scheduler_post(i->response_scheduler, record, flush_cache, querier, immediately);
 }
 
-int avahi_interface_post_probe(AvahiInterface *i, AvahiRecord *record, int immediately) {
+int catta_interface_post_probe(CattaInterface *i, CattaRecord *record, int immediately) {
     assert(i);
     assert(record);
 
     if (!i->announcing)
         return 0;
 
-    return avahi_probe_scheduler_post(i->probe_scheduler, record, immediately);
+    return catta_probe_scheduler_post(i->probe_scheduler, record, immediately);
 }
 
-int avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, void* userdata) {
-    AvahiInterface *i;
+int catta_dump_caches(CattaInterfaceMonitor *m, CattaDumpCallback callback, void* userdata) {
+    CattaInterface *i;
     assert(m);
 
     for (i = m->interfaces; i; i = i->interface_next) {
-        if (avahi_interface_is_relevant(i)) {
+        if (catta_interface_is_relevant(i)) {
             char ln[256];
-            snprintf(ln, sizeof(ln), ";;; INTERFACE %s.%s ;;;", i->hardware->name, avahi_proto_to_string(i->protocol));
+            snprintf(ln, sizeof(ln), ";;; INTERFACE %s.%s ;;;", i->hardware->name, catta_proto_to_string(i->protocol));
             callback(ln, userdata);
-            if (avahi_cache_dump(i->cache, callback, userdata) < 0)
+            if (catta_cache_dump(i->cache, callback, userdata) < 0)
                 return -1;
         }
     }
@@ -660,8 +660,8 @@ int avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, void
     return 0;
 }
 
-static int avahi_interface_is_relevant_internal(AvahiInterface *i) {
-    AvahiInterfaceAddress *a;
+static int catta_interface_is_relevant_internal(CattaInterface *i) {
+    CattaInterfaceAddress *a;
 
     assert(i);
 
@@ -669,14 +669,14 @@ static int avahi_interface_is_relevant_internal(AvahiInterface *i) {
         return 0;
 
     for (a = i->addresses; a; a = a->address_next)
-        if (avahi_interface_address_is_relevant(a))
+        if (catta_interface_address_is_relevant(a))
             return 1;
 
     return 0;
 }
 
-int avahi_interface_is_relevant(AvahiInterface *i) {
-    AvahiStringList *l;
+int catta_interface_is_relevant(CattaInterface *i) {
+    CattaStringList *l;
     assert(i);
 
     for (l = i->monitor->server->config.deny_interfaces; l; l = l->next)
@@ -693,11 +693,11 @@ int avahi_interface_is_relevant(AvahiInterface *i) {
     }
 
 good:
-    return avahi_interface_is_relevant_internal(i);
+    return catta_interface_is_relevant_internal(i);
 }
 
-int avahi_interface_address_is_relevant(AvahiInterfaceAddress *a) {
-    AvahiInterfaceAddress *b;
+int catta_interface_address_is_relevant(CattaInterfaceAddress *a) {
+    CattaInterfaceAddress *b;
     assert(a);
 
     /* Publish public and non-deprecated IP addresses */
@@ -717,65 +717,65 @@ int avahi_interface_address_is_relevant(AvahiInterfaceAddress *a) {
     return 1;
 }
 
-int avahi_interface_match(AvahiInterface *i, AvahiIfIndex idx, AvahiProtocol protocol) {
+int catta_interface_match(CattaInterface *i, CattaIfIndex idx, CattaProtocol protocol) {
     assert(i);
 
-    if (idx != AVAHI_IF_UNSPEC && idx != i->hardware->index)
+    if (idx != CATTA_IF_UNSPEC && idx != i->hardware->index)
         return 0;
 
-    if (protocol != AVAHI_PROTO_UNSPEC && protocol != i->protocol)
+    if (protocol != CATTA_PROTO_UNSPEC && protocol != i->protocol)
         return 0;
 
     return 1;
 }
 
-void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, AvahiIfIndex interface, AvahiProtocol protocol, AvahiInterfaceMonitorWalkCallback callback, void* userdata) {
+void catta_interface_monitor_walk(CattaInterfaceMonitor *m, CattaIfIndex interface, CattaProtocol protocol, CattaInterfaceMonitorWalkCallback callback, void* userdata) {
     assert(m);
     assert(callback);
 
-    if (interface != AVAHI_IF_UNSPEC) {
-        if (protocol != AVAHI_PROTO_UNSPEC) {
-            AvahiInterface *i;
+    if (interface != CATTA_IF_UNSPEC) {
+        if (protocol != CATTA_PROTO_UNSPEC) {
+            CattaInterface *i;
 
-            if ((i = avahi_interface_monitor_get_interface(m, interface, protocol)))
+            if ((i = catta_interface_monitor_get_interface(m, interface, protocol)))
                 callback(m, i, userdata);
 
         } else {
-            AvahiHwInterface *hw;
-            AvahiInterface *i;
+            CattaHwInterface *hw;
+            CattaInterface *i;
 
-            if ((hw = avahi_interface_monitor_get_hw_interface(m, interface)))
+            if ((hw = catta_interface_monitor_get_hw_interface(m, interface)))
                 for (i = hw->interfaces; i; i = i->by_hardware_next)
-                    if (avahi_interface_match(i, interface, protocol))
+                    if (catta_interface_match(i, interface, protocol))
                         callback(m, i, userdata);
         }
 
     } else {
-        AvahiInterface *i;
+        CattaInterface *i;
 
         for (i = m->interfaces; i; i = i->interface_next)
-            if (avahi_interface_match(i, interface, protocol))
+            if (catta_interface_match(i, interface, protocol))
                 callback(m, i, userdata);
     }
 }
 
 
-int avahi_address_is_local(AvahiInterfaceMonitor *m, const AvahiAddress *a) {
-    AvahiInterface *i;
-    AvahiInterfaceAddress *ia;
+int catta_address_is_local(CattaInterfaceMonitor *m, const CattaAddress *a) {
+    CattaInterface *i;
+    CattaInterfaceAddress *ia;
     assert(m);
     assert(a);
 
     for (i = m->interfaces; i; i = i->interface_next)
         for (ia = i->addresses; ia; ia = ia->address_next)
-            if (avahi_address_cmp(a, &ia->address) == 0)
+            if (catta_address_cmp(a, &ia->address) == 0)
                 return 1;
 
     return 0;
 }
 
-int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a) {
-    AvahiInterfaceAddress *ia;
+int catta_interface_address_on_link(CattaInterface *i, const CattaAddress *a) {
+    CattaInterfaceAddress *ia;
 
     assert(i);
     assert(a);
@@ -785,7 +785,7 @@ int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a) {
 
     for (ia = i->addresses; ia; ia = ia->address_next) {
 
-        if (a->proto == AVAHI_PROTO_INET) {
+        if (a->proto == CATTA_PROTO_INET) {
             uint32_t m;
 
             m = ~(((uint32_t) -1) >> ia->prefix_len);
@@ -795,7 +795,7 @@ int avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a) {
         } else {
             unsigned j;
             unsigned char pl;
-            assert(a->proto == AVAHI_PROTO_INET6);
+            assert(a->proto == CATTA_PROTO_INET6);
 
             pl = ia->prefix_len;
 
@@ -822,26 +822,26 @@ 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;
+int catta_interface_has_address(CattaInterfaceMonitor *m, CattaIfIndex iface, const CattaAddress *a) {
+    CattaInterface *i;
+    CattaInterfaceAddress *j;
 
     assert(m);
-    assert(iface != AVAHI_IF_UNSPEC);
+    assert(iface != CATTA_IF_UNSPEC);
     assert(a);
 
-    if (!(i = avahi_interface_monitor_get_interface(m, iface, a->proto)))
+    if (!(i = catta_interface_monitor_get_interface(m, iface, a->proto)))
         return 0;
 
     for (j = i->addresses; j; j = j->address_next)
-        if (avahi_address_cmp(a, &j->address) == 0)
+        if (catta_address_cmp(a, &j->address) == 0)
             return 1;
 
     return 0;
 }
 
-AvahiIfIndex avahi_find_interface_for_address(AvahiInterfaceMonitor *m, const AvahiAddress *a) {
-    AvahiInterface *i;
+CattaIfIndex catta_find_interface_for_address(CattaInterfaceMonitor *m, const CattaAddress *a) {
+    CattaInterface *i;
     assert(m);
 
     /* Some stupid OS don't support passing the interface index when a
@@ -851,15 +851,15 @@ AvahiIfIndex avahi_find_interface_for_address(AvahiInterfaceMonitor *m, const Av
      * it. */
 
     for (i = m->interfaces; i; i = i->interface_next) {
-        AvahiInterfaceAddress *ai;
+        CattaInterfaceAddress *ai;
 
         if (i->protocol != a->proto)
             continue;
 
         for (ai = i->addresses; ai; ai = ai->address_next)
-            if (avahi_address_cmp(a, &ai->address) == 0)
+            if (catta_address_cmp(a, &ai->address) == 0)
                 return i->hardware->index;
     }
 
-    return AVAHI_IF_UNSPEC;
+    return CATTA_IF_UNSPEC;
 }