+#include <assert.h>
+
+#include <avahi-client/client.h>
+#include <avahi-client/lookup.h>
+#include <avahi-client/publish.h>
+
+#include <avahi-common/error.h>
+#include <avahi-common/simple-watch.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/timeval.h>
+
+static const AvahiPoll *poll_api = NULL;
+static AvahiSimplePoll *simple_poll = NULL;
+
+static void avahi_client_callback (AvahiClient *c, AvahiClientState state, void *userdata) {
+ printf ("CLIENT: Callback on %p, state -> %d, data -> %s\n", (void*) c, state, (char*)userdata);
+}
+
+static void avahi_entry_group_callback (AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
+ printf ("ENTRY-GROUP: Callback on %p, state -> %d, data -> %s\n", (void*) g, state, (char*)userdata);
+}
+
+static void avahi_entry_group2_callback (AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
+ printf ("ENTRY-GROUP2: Callback on %p, state -> %d, data -> %s\n", (void*) g, state, (char*)userdata);
+}
+
+static void avahi_domain_browser_callback(
+ AvahiDomainBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *domain,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ printf ("DOMAIN-BROWSER: Callback on %p, interface (%d), protocol (%d), event (%d), domain (%s), data (%s)\n", (void*) b, interface, protocol, event, domain ? domain : "NULL", (char*)userdata);
+}
+
+static void avahi_service_resolver_callback(
+ AvahiServiceResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const char *type,
+ const char *domain,
+ const char *host_name,
+ const AvahiAddress *a,
+ uint16_t port,
+ AvahiStringList *txt,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ char addr[64];
+ char *txtr;
+ if (event == AVAHI_RESOLVER_FAILURE) {
+ printf ("SERVICE-RESOLVER: ServiceResolver %p timed out (%s %s)\n", (void*) r, name, type);
+ return;
+ }
+ avahi_address_snprint (addr, sizeof (addr), a);
+ txtr = avahi_string_list_to_string (txt);
+ printf ("SERVICE-RESOLVER: Callback on ServiceResolver, interface (%d), protocol (%d), event (%d), name (%s), type (%s), domain (%s), host_name (%s), address (%s), port (%d), txtdata (%s), data(%s)\n", interface, protocol, event, name, type, domain, host_name, addr, port, txtr, (char*)userdata);
+ avahi_free(txtr);
+}
+
+static void avahi_service_browser_callback (
+ AvahiServiceBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *name,
+ const char *type,
+ const char *domain,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ AvahiServiceResolver *sr;
+
+ printf ("SERVICE-BROWSER: Callback on %p, interface (%d), protocol (%d), event (%d), name (%s), type (%s), domain (%s), data (%s)\n", (void*) b, interface, protocol, event, name ? name : "NULL", type, domain ? domain : "NULL", (char*)userdata);
+
+ if (b && name)
+ {
+ sr = avahi_service_resolver_new (avahi_service_browser_get_client (b), interface, protocol, name, type, domain, AVAHI_PROTO_UNSPEC, 0, avahi_service_resolver_callback, (char*) "xxXXxx");
+ printf("New service resolver %p\n", (void*) sr);
+ }
+}
+
+static void avahi_service_type_browser_callback (
+ AvahiServiceTypeBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *type,
+ const char *domain,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ printf ("SERVICE-TYPE-BROWSER: Callback on %p, interface (%d), protocol (%d), event (%d), type (%s), domain (%s), data (%s)\n", (void*) b, interface, protocol, event, type ? type : "NULL", domain ? domain : "NULL", (char*)userdata);
+}
+
+static void avahi_address_resolver_callback (
+ AVAHI_GCC_UNUSED AvahiAddressResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const AvahiAddress *address,
+ const char *name,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ char addr[64];
+ if (event == AVAHI_RESOLVER_FAILURE) {
+ printf ("ADDRESS-RESOLVER: Callback on AddressResolver, timed out.\n");
+ return;
+ }
+ avahi_address_snprint (addr, sizeof (addr), address);
+ printf ("ADDRESS-RESOLVER: Callback on AddressResolver, interface (%d), protocol (%d), even (%d), address (%s), name (%s), data(%s)\n", interface, protocol, event, addr, name, (char*) userdata);
+}
+
+static void avahi_host_name_resolver_callback (
+ AvahiHostNameResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const AvahiAddress *a,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ AvahiClient *client;
+ AvahiAddressResolver *ar;
+ char addr[64];
+
+ if (event == AVAHI_RESOLVER_FAILURE) {
+ printf ("HOST-NAME-RESOLVER: Callback on HostNameResolver, timed out.\n");
+ return;
+ }
+ client = avahi_host_name_resolver_get_client (r);
+ar = avahi_address_resolver_new(client, interface, protocol, a, 0, avahi_address_resolver_callback, (char*) "omghai6u");
+ if (ar)
+ {
+ printf ("Succesfully created address resolver object\n");
+ } else {
+ printf ("Failed to create AddressResolver\n");
+ }
+ avahi_address_snprint (addr, sizeof (addr), a);
+ printf ("HOST-NAME-RESOLVER: Callback on HostNameResolver, interface (%d), protocol (%d), event (%d), name (%s), address (%s), data (%s)\n", interface, protocol, event, name, addr, (char*)userdata);
+}
+static void test_free_domain_browser(AVAHI_GCC_UNUSED AvahiTimeout *timeout, void* userdata)
+{
+ AvahiServiceBrowser *b = userdata;
+ printf ("Freeing domain browser\n");
+ avahi_service_browser_free (b);
+}