resolve-service.c \
dns.c dns.h \
core.h \
- llist.h
+ llist.h \
+ log.c log.h
libavahi_core_la_CFLAGS = $(AM_CFLAGS)
libavahi_core_la_LIBADD = $(AM_LDADD) $(COMMON_LDADD)
dns_test_SOURCES = \
dns.c dns.h \
- dns-test.c
+ dns-test.c \
+ log.c log.h
dns_test_CFLAGS = $(AM_CFLAGS)
dns_test_LDADD = $(AM_LDADD) $(STATIC_COMMON_LDADD)
static void next_state(AvahiAnnouncement *a) {
g_assert(a);
-/* g_message("%i -- %u", a->state, a->n_iteration); */
+/* avahi_log_debug("%i -- %u", a->state, a->n_iteration); */
if (a->state == AVAHI_WAITING) {
/* gchar *t; */
-/* g_message("Enough probes for record [%s]", t = avahi_record_to_string(a->entry->record)); */
+/* avahi_log_debug("Enough probes for record [%s]", t = avahi_record_to_string(a->entry->record)); */
/* g_free(t); */
if (a->entry->group) {
/* gchar *t; */
/* Announcing done */
-/* g_message("Enough announcements for record [%s]", t = avahi_record_to_string(a->entry->record)); */
+/* avahi_log_debug("Enough announcements for record [%s]", t = avahi_record_to_string(a->entry->record)); */
/* g_free(t); */
a->state = AVAHI_ESTABLISHED;
g_assert(e);
g_assert(!e->dead);
-/* g_message("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record)); */
+/* avahi_log_debug("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record)); */
/* g_free(t); */
if (!avahi_interface_match(i, e->interface, e->protocol) || !i->announcing || !avahi_entry_commited(e))
go_to_initial_state(a, FALSE);
-/* g_message("New announcement on interface %s.%i for entry [%s] state=%i", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record), a->state); */
+/* avahi_log_debug("New announcement on interface %s.%i for entry [%s] state=%i", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record), a->state); */
/* g_free(t); */
}
g_assert(r);
-/* g_message("Preparing goodbye for record [%s]", t = avahi_record_to_string(r)); */
+/* avahi_log_debug("Preparing goodbye for record [%s]", t = avahi_record_to_string(r)); */
/* g_free(t); */
g = avahi_record_copy(r);
g_assert(s);
g_assert(i);
-/* g_message("goodbye interface: %s.%u", i->hardware->name, i->protocol); */
+/* avahi_log_debug("goodbye interface: %s.%u", i->hardware->name, i->protocol); */
if (goodbye && avahi_interface_relevant(i)) {
AvahiEntry *e;
while (i->announcements)
remove_announcement(s, i->announcements);
-/* g_message("goodbye interface done: %s.%u", i->hardware->name, i->protocol); */
+/* avahi_log_debug("goodbye interface done: %s.%u", i->hardware->name, i->protocol); */
}
g_assert(s);
g_assert(e);
-/* g_message("goodbye entry: %p", e); */
+/* avahi_log_debug("goodbye entry: %p", e); */
if (goodbye && !e->dead)
avahi_interface_monitor_walk(s->monitor, 0, AF_UNSPEC, send_goodbye_callback, e);
while (e->announcements)
remove_announcement(s, e->announcements);
-/* g_message("goodbye entry done: %p", e); */
+/* avahi_log_debug("goodbye entry done: %p", e); */
}
g_assert(s);
-/* g_message("goodbye all"); */
+/* avahi_log_debug("goodbye all"); */
for (e = s->entries; e; e = e->entries_next)
if (!e->dead)
avahi_goodbye_entry(s, e, goodbye);
-/* g_message("goodbye all done"); */
+/* avahi_log_debug("goodbye all done"); */
}
#include <stdlib.h>
#include <avahi-core/core.h>
+#include <avahi-core/log.h>
static AvahiEntryGroup *group = NULL;
static AvahiServer *server = NULL;
g_assert(interface > 0);
g_assert(protocol != AF_UNSPEC);
- g_message("SUBSCRIPTION: record [%s] on %i.%i is %s", t = avahi_record_to_string(record), interface, protocol,
+ avahi_log_debug("SUBSCRIPTION: record [%s] on %i.%i is %s", t = avahi_record_to_string(record), interface, protocol,
event == AVAHI_BROWSER_NEW ? "new" : "remove");
g_free(t);
static void create_entries(gboolean new_name);
static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata) {
- g_message("entry group state: %i", state);
+ avahi_log_debug("entry group state: %i", state);
if (state == AVAHI_ENTRY_GROUP_COLLISION) {
remove_entries();
create_entries(TRUE);
- g_message("Service name conflict, retrying with <%s>", service_name);
+ avahi_log_debug("Service name conflict, retrying with <%s>", service_name);
} else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
- g_message("Service established under name <%s>", service_name);
+ avahi_log_debug("Service established under name <%s>", service_name);
}
}
static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) {
- g_message("server state: %i", state);
+ avahi_log_debug("server state: %i", state);
if (state == AVAHI_SERVER_RUNNING) {
- g_message("Server startup complete. Host name is <%s>", avahi_server_get_host_name_fqdn(s));
+ avahi_log_debug("Server startup complete. Host name is <%s>", avahi_server_get_host_name_fqdn(s));
create_entries(FALSE);
} else if (state == AVAHI_SERVER_COLLISION) {
gchar *n;
n = avahi_alternative_host_name(avahi_server_get_host_name(s));
- g_message("Host name conflict, retrying with <%s>", n);
+ avahi_log_debug("Host name conflict, retrying with <%s>", n);
avahi_server_set_host_name(s, n);
g_free(n);
}
if (a)
avahi_address_snprint(t, sizeof(t), a);
- g_message("HNR: (%i.%i) <%s> -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", event == AVAHI_RESOLVER_FOUND ? "found" : "timeout");
+ avahi_log_debug("HNR: (%i.%i) <%s> -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", event == AVAHI_RESOLVER_FOUND ? "found" : "timeout");
}
static void ar_callback(AvahiAddressResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
avahi_address_snprint(t, sizeof(t), a);
- g_message("AR: (%i.%i) %s -> <%s> [%s]", iface, protocol, t, hostname ? hostname : "n/a", event == AVAHI_RESOLVER_FOUND ? "found" : "timeout");
+ avahi_log_debug("AR: (%i.%i) %s -> <%s> [%s]", iface, protocol, t, hostname ? hostname : "n/a", event == AVAHI_RESOLVER_FOUND ? "found" : "timeout");
}
static void db_callback(AvahiDomainBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
- g_message("DB: (%i.%i) <%s> [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+ avahi_log_debug("DB: (%i.%i) <%s> [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
static void stb_callback(AvahiServiceTypeBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) {
- g_message("STB: (%i.%i) %s in <%s> [%s]", iface, protocol, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+ avahi_log_debug("STB: (%i.%i) %s in <%s> [%s]", iface, protocol, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
static void sb_callback(AvahiServiceBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *service_type, const gchar *domain, gpointer userdata) {
- g_message("SB: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+ avahi_log_debug("SB: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
static void sr_callback(AvahiServiceResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *service_name, const gchar*service_type, const gchar*domain_name, const gchar*hostname, const AvahiAddress *a, guint16 port, AvahiStringList *txt, gpointer userdata) {
if (event == AVAHI_RESOLVER_TIMEOUT)
- g_message("SR: (%i.%i) <%s> as %s in <%s> [timeout]", iface, protocol, service_name, service_type, domain_name);
+ avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [timeout]", iface, protocol, service_name, service_type, domain_name);
else {
gchar t[64], *s;
avahi_address_snprint(t, sizeof(t), a);
s = avahi_string_list_to_string(txt);
- g_message("SR: (%i.%i) <%s> as %s in <%s>: %s/%s:%i (%s) [found]", iface, protocol, service_name, service_type, domain_name, hostname, t, port, s);
+ avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s>: %s/%s:%i (%s) [found]", iface, protocol, service_name, service_type, domain_name, hostname, t, port, s);
g_free(s);
}
}
#include "browse.h"
#include "util.h"
+#include "log.h"
struct AvahiServiceTypeBrowser {
AvahiServer *server;
return;
fail:
- g_warning("Invalid service type '%s'", n);
+ avahi_log_warn("Invalid service type '%s'", n);
g_free(n);
}
#include "browse.h"
#include "util.h"
+#include "log.h"
struct AvahiServiceBrowser {
AvahiServer *server;
return;
fail:
- g_warning("Invalid service '%s'", n);
+ avahi_log_warn("Invalid service '%s'", n);
g_free(n);
}
if (s->n_query++ <= 8)
s->sec_delay *= 2;
-/* g_message("%i. Continuous querying for %s", s->n_query, t = avahi_key_to_string(s->key)); */
+/* avahi_log_debug("%i. Continuous querying for %s", s->n_query, t = avahi_key_to_string(s->key)); */
/* g_free(t); */
avahi_elapse_time(&tv, s->sec_delay*1000, 0);
g_assert(c);
g_assert(e);
-/* g_message("removing from cache: %p %p", c, e); */
+/* avahi_log_debug("removing from cache: %p %p", c, e); */
/* Remove from hash table */
t = g_hash_table_lookup(c->hash_table, e->record->key);
if (e->state == AVAHI_CACHE_FINAL) {
remove_entry(e->cache, e);
-/* g_message("Removing entry from cache due to expiration"); */
+/* avahi_log_debug("Removing entry from cache due to expiration"); */
} else {
guint percent = 0;
/* Request a cache update, if we are subscribed to this entry */
if (avahi_is_subscribed(e->cache->server, e->cache->interface, e->record->key)) {
-/* g_message("Requesting cache entry update at %i%%.", percent); */
+/* avahi_log_debug("Requesting cache entry update at %i%%.", percent); */
avahi_interface_post_query(e->cache->interface, e->record->key, TRUE);
}
g_assert(c);
g_assert(r && r->ref >= 1);
-/* g_message("cache update: %s", (txt = avahi_record_to_string(r))); */
+/* avahi_log_debug("cache update: %s", (txt = avahi_record_to_string(r))); */
/* g_free(txt); */
if (r->ttl == 0) {
if (e) {
-/* g_message("found matching cache entry"); */
+/* avahi_log_debug("found matching cache entry"); */
/* We need to update the hash table key if we replace the
* record */
} else {
/* No entry found, therefore we create a new one */
-/* g_message("couldn't find matching cache entry"); */
+/* avahi_log_debug("couldn't find matching cache entry"); */
if (c->n_entries >= AVAHI_MAX_CACHE_ENTRIES)
return;
age = avahi_timeval_diff(&now, &e->timestamp)/1000000;
-/* g_message("age: %u, ttl/2: %u", age, e->record->ttl); */
+/* avahi_log_debug("age: %u, ttl/2: %u", age, e->record->ttl); */
return age >= e->record->ttl/2;
}
#include "core.h"
#include "util.h"
#include "alternative.h"
+#include "log.h"
static gchar *name = NULL;
static AvahiEntryGroup *group = NULL;
if (state == AVAHI_ENTRY_GROUP_COLLISION)
create_service(NULL);
else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
- g_message("ESTABLISHED !!!!");
+ avahi_log_debug("ESTABLISHED !!!!");
try = 0;
}
}
static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) {
- g_message("server state: %i", state);
+ avahi_log_debug("server state: %i", state);
}
int main(int argc, char *argv[]) {
#include "dns.h"
#include "util.h"
+#include "log.h"
int main(int argc, char *argv[]) {
gchar t[256], *a, *b, *c, *d;
avahi_hexdump(AVAHI_DNS_PACKET_DATA(p), p->size);
avahi_dns_packet_consume_name(p, t, sizeof(t));
- g_message(">%s<", t);
+ avahi_log_debug(">%s<", t);
g_assert(avahi_domain_equal(a, t));
avahi_dns_packet_consume_name(p, t, sizeof(t));
- g_message(">%s<", t);
+ avahi_log_debug(">%s<", t);
g_assert(avahi_domain_equal(b, t));
avahi_dns_packet_consume_name(p, t, sizeof(t));
- g_message(">%s<", t);
+ avahi_log_debug(">%s<", t);
g_assert(avahi_domain_equal(c, t));
avahi_dns_packet_consume_name(p, t, sizeof(t));
- g_message(">%s<", t);
+ avahi_log_debug(">%s<", t);
g_assert(avahi_domain_equal(d, t));
avahi_dns_packet_free(p);
g_assert(p);
g_assert(ret_cache_flush);
-/* g_message("consume_record()"); */
+/* avahi_log_debug("consume_record()"); */
if (avahi_dns_packet_consume_name(p, name, sizeof(name)) < 0 ||
avahi_dns_packet_consume_uint16(p, &type) < 0 ||
p->rindex + rdlength > p->size)
goto fail;
-/* g_message("name = %s, rdlength = %u", name, rdlength); */
+/* avahi_log_debug("name = %s, rdlength = %u", name, rdlength); */
*ret_cache_flush = !!(class & AVAHI_DNS_CACHE_FLUSH);
class &= ~AVAHI_DNS_CACHE_FLUSH;
case AVAHI_DNS_TYPE_PTR:
case AVAHI_DNS_TYPE_CNAME:
-/* g_message("ptr"); */
+/* avahi_log_debug("ptr"); */
if (avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0)
goto fail;
case AVAHI_DNS_TYPE_SRV:
-/* g_message("srv"); */
+/* avahi_log_debug("srv"); */
if (avahi_dns_packet_consume_uint16(p, &r->data.srv.priority) < 0 ||
avahi_dns_packet_consume_uint16(p, &r->data.srv.weight) < 0 ||
case AVAHI_DNS_TYPE_HINFO:
-/* g_message("hinfo"); */
+/* avahi_log_debug("hinfo"); */
if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0)
goto fail;
case AVAHI_DNS_TYPE_TXT:
-/* g_message("txt"); */
+/* avahi_log_debug("txt"); */
if (rdlength > 0) {
r->data.txt.string_list = avahi_string_list_parse(avahi_dns_packet_get_rptr(p), rdlength);
case AVAHI_DNS_TYPE_A:
-/* g_message("A"); */
+/* avahi_log_debug("A"); */
if (avahi_dns_packet_consume_bytes(p, &r->data.a.address, sizeof(AvahiIPv4Address)) < 0)
goto fail;
case AVAHI_DNS_TYPE_AAAA:
-/* g_message("aaaa"); */
+/* avahi_log_debug("aaaa"); */
if (avahi_dns_packet_consume_bytes(p, &r->data.aaaa.address, sizeof(AvahiIPv6Address)) < 0)
goto fail;
default:
-/* g_message("generic"); */
+/* avahi_log_debug("generic"); */
if (rdlength > 0) {
break;
}
-/* g_message("%i == %u ?", (guint8*) avahi_dns_packet_get_rptr(p) - (guint8*) start, rdlength); */
+/* avahi_log_debug("%i == %u ?", (guint8*) avahi_dns_packet_get_rptr(p) - (guint8*) start, rdlength); */
/* Check if we read enough data */
if ((guint8*) avahi_dns_packet_get_rptr(p) - (guint8*) start != rdlength)
size = avahi_string_list_serialize(r->data.txt.string_list, NULL, 0);
-/* g_message("appending string: %u %p", size, r->data.txt.string_list); */
+/* avahi_log_debug("appending string: %u %p", size, r->data.txt.string_list); */
if (!(data = avahi_dns_packet_extend(p, size)))
goto fail;
size = avahi_dns_packet_extend(p, 0) - start;
g_assert(size <= 0xFFFF);
-/* g_message("appended %u", size); */
+/* avahi_log_debug("appended %u", size); */
* (guint16*) l = g_htons((guint16) size);
#include "socket.h"
#include "announce.h"
#include "util.h"
+#include "log.h"
static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a, gboolean remove) {
g_assert(m);
b = avahi_interface_relevant(i);
if (b && !i->announcing) {
- g_message("New relevant interface %s.%i (#%i)", i->hardware->name, i->protocol, i->hardware->index);
+ avahi_log_debug("New relevant interface %s.%i (#%i)", i->hardware->name, i->protocol, i->hardware->index);
if (i->protocol == AF_INET)
avahi_mdns_mcast_join_ipv4(i->hardware->index, m->server->fd_ipv4);
avahi_announce_interface(m->server, i);
avahi_browser_new_interface(m->server, i);
} else if (!b && i->announcing) {
- g_message("Interface %s.%i no longer relevant", i->hardware->name, i->protocol);
+ avahi_log_debug("Interface %s.%i no longer relevant", i->hardware->name, i->protocol);
if (i->protocol == AF_INET)
avahi_mdns_mcast_leave_ipv4(i->hardware->index, m->server->fd_ipv4);
m->list = LIST_DONE;
if (netlink_list_items(m->netlink, RTM_GETADDR, &m->query_addr_seq) < 0)
- g_warning("NETLINK: Failed to list addrs: %s", strerror(errno));
+ avahi_log_warn("NETLINK: Failed to list addrs: %s", strerror(errno));
else
m->list = LIST_ADDR;
} else {
m->list = LIST_DONE;
- g_message("Enumeration complete");
+ avahi_log_debug("Enumeration complete");
}
} else if (n->nlmsg_type == NLMSG_ERROR && (n->nlmsg_seq == m->query_link_seq || n->nlmsg_seq == m->query_addr_seq)) {
struct nlmsgerr *e = NLMSG_DATA (n);
if (e->error)
- g_warning("NETLINK: Failed to browse: %s", strerror(-e->error));
+ avahi_log_warn("NETLINK: Failed to browse: %s", strerror(-e->error));
}
}
g_assert(!a || a->family == i->protocol);
/* if (a) */
-/* g_message("unicast sending on '%s.%i' to %s:%u", i->hardware->name, i->protocol, avahi_address_snprint(t, sizeof(t), a), port); */
+/* avahi_log_debug("unicast sending on '%s.%i' to %s:%u", i->hardware->name, i->protocol, avahi_address_snprint(t, sizeof(t), a), port); */
/* else */
-/* g_message("multicast sending on '%s.%i'", i->hardware->name, i->protocol); */
+/* avahi_log_debug("multicast sending on '%s.%i'", i->hardware->name, i->protocol); */
if (i->protocol == AF_INET && i->monitor->server->fd_ipv4 >= 0)
avahi_send_dns_packet_ipv4(i->monitor->server->fd_ipv4, i->hardware->index, p, a ? &a->data.ipv4 : NULL, port);
break;
}
-/* g_message("%p. iface-relevant: %i %i %i %i %i %i", i, relevant_address, */
+/* avahi_log_debug("%p. iface-relevant: %i %i %i %i %i %i", i, relevant_address, */
/* (i->hardware->flags & IFF_UP), */
/* (i->hardware->flags & IFF_RUNNING), */
/* !(i->hardware->flags & IFF_LOOPBACK), */
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi 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
+ 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
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "log.h"
+
+static AvahiLogFunction log_function = NULL;
+
+void avahi_set_log_function(AvahiLogFunction function) {
+ log_function = function;
+}
+
+void avahi_log_ap(AvahiLogLevel level, const gchar*format, va_list ap) {
+ char txt[256];
+
+ vsnprintf(txt, sizeof(txt), format, ap);
+
+ if (log_function)
+ log_function(level, txt);
+ else
+ fprintf(stderr, "%s\n", txt);
+}
+
+void avahi_log(AvahiLogLevel level, const gchar*format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ avahi_log_ap(level, format, ap);
+ va_end(ap);
+}
+
+void avahi_log_error(const gchar*format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ avahi_log_ap(AVAHI_LOG_ERROR, format, ap);
+ va_end(ap);
+}
+
+void avahi_log_warn(const gchar*format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ avahi_log_ap(AVAHI_LOG_WARN, format, ap);
+ va_end(ap);
+}
+
+void avahi_log_notice(const gchar*format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ avahi_log_ap(AVAHI_LOG_NOTICE, format, ap);
+ va_end(ap);
+}
+
+void avahi_log_info(const gchar*format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ avahi_log_ap(AVAHI_LOG_INFO, format, ap);
+ va_end(ap);
+}
+
+void avahi_log_debug(const gchar*format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ avahi_log_ap(AVAHI_LOG_DEBUG, format, ap);
+ va_end(ap);
+}
--- /dev/null
+#ifndef foologhfoo
+#define foologhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi 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
+ 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
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <stdarg.h>
+#include <glib.h>
+
+#ifdef __GNUC__
+#define AVAHI_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
+#else
+/** Macro for usage of GCC's printf compilation warnings */
+#define AVAHI_GCC_PRINTF_ATTR(a,b)
+#endif
+
+#define AVAHI_GCC_PRINTF_ATTR12 AVAHI_GCC_PRINTF_ATTR(1,2)
+#define AVAHI_GCC_PRINTF_ATTR23 AVAHI_GCC_PRINTF_ATTR(2,3)
+
+/** Log level for avahi_log_xxx() */
+typedef enum {
+ AVAHI_LOG_ERROR = 0, /**< Error messages */
+ AVAHI_LOG_WARN = 1, /**< Warning messages */
+ AVAHI_LOG_NOTICE = 2, /**< Notice messages */
+ AVAHI_LOG_INFO = 3, /**< Info messages */
+ AVAHI_LOG_DEBUG = 4, /**< Debug messages */
+ AVAHI_LOG_LEVEL_MAX
+} AvahiLogLevel;
+
+/** Prototype for a user supplied log function */
+typedef void (*AvahiLogFunction)(AvahiLogLevel level, const gchar *txt);
+
+/** Set a user supplied log function, replacing the default which
+ * prints to log messages unconditionally to STDERR. Pass NULL for
+ * resetting to the default log function */
+void avahi_set_log_function(AvahiLogFunction function);
+
+/** Issue a log message using a va_list object */
+void avahi_log_ap(AvahiLogLevel level, const gchar *format, va_list ap);
+
+/** Issue a log message by passing a log level and a format string */
+void avahi_log(AvahiLogLevel level, const gchar*format, ...) AVAHI_GCC_PRINTF_ATTR23;
+
+/** Shortcut for avahi_log(AVAHI_LOG_ERROR, ...) */
+void avahi_log_error(const gchar*format, ...) AVAHI_GCC_PRINTF_ATTR12;
+
+/** Shortcut for avahi_log(AVAHI_LOG_WARN, ...) */
+void avahi_log_warn(const gchar*format, ...) AVAHI_GCC_PRINTF_ATTR12;
+
+/** Shortcut for avahi_log(AVAHI_LOG_NOTICE, ...) */
+void avahi_log_notice(const gchar*format, ...) AVAHI_GCC_PRINTF_ATTR12;
+
+/** Shortcut for avahi_log(AVAHI_LOG_INFO, ...) */
+void avahi_log_info(const gchar*format, ...) AVAHI_GCC_PRINTF_ATTR12;
+
+/** Shortcut for avahi_log(AVAHI_LOG_DEBUG, ...) */
+void avahi_log_debug(const gchar*format, ...) AVAHI_GCC_PRINTF_ATTR12;
+
+#endif
#include <sys/ioctl.h>
#include "netlink.h"
+#include "log.h"
struct AvahiNetlink {
GMainContext *context;
if (errno == EAGAIN || errno == EINTR)
break;
- g_warning("NETLINK: recv() failed: %s", strerror(errno));
+ avahi_log_warn("NETLINK: recv() failed: %s", strerror(errno));
return FALSE;
}
if (nl->callback) {
for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) {
if (!NLMSG_OK(p, (size_t) bytes)) {
- g_warning("NETLINK: packet truncated");
+ avahi_log_warn("NETLINK: packet truncated");
return FALSE;
}
m->nlmsg_flags |= NLM_F_ACK;
if (send(nl->fd, m, m->nlmsg_len, 0) < 0) {
- g_warning("NETLINK: send(): %s\n", strerror(errno));
+ avahi_log_warn("NETLINK: send(): %s\n", strerror(errno));
return -1;
}
if (n->parent) {
g_assert(n->prev);
if (n->parent->left == n) {
- if (n->parent->right != NULL) {
- g_message("fuck");
- for (;;);
-
- }
-
g_assert(n->parent->right == NULL);
n->parent->left = NULL;
} else {
#include "probe-sched.h"
#include "util.h"
+#include "log.h"
#define AVAHI_PROBE_HISTORY_MSEC 150
#define AVAHI_PROBE_DEFER_MSEC 50
avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_QDCOUNT, 1);
avahi_interface_send_packet(s->interface, p);
} else
- g_warning("Probe record too large, cannot send");
+ avahi_log_warn("Probe record too large, cannot send");
avahi_dns_packet_free(p);
job_mark_done(s, pj);
continue;
if (!avahi_dns_packet_append_record(p, pj->record, FALSE, 0)) {
- g_warning("Bad probe size estimate!");
+ avahi_log_warn("Bad probe size estimate!");
/* Unmark all following jobs */
for (; pj; pj = pj->jobs_next)
pj->time_event = avahi_time_event_queue_add(s->time_event_queue, &pj->delivery, elapse_callback, pj);
-/* g_message("Accepted new probe job."); */
+/* avahi_log_debug("Accepted new probe job."); */
return TRUE;
}
g_assert(key);
if ((qj = find_history_job(s, key))) {
-/* g_message("Query suppressed by local duplicate suppression (history)"); */
+/* avahi_log_debug("Query suppressed by local duplicate suppression (history)"); */
return FALSE;
}
if ((qj = find_scheduled_job(s, key))) {
/* Duplicate questions suppression */
-/* g_message("Query suppressed by local duplicate suppression (scheduled)"); */
+/* avahi_log_debug("Query suppressed by local duplicate suppression (scheduled)"); */
if (avahi_timeval_compare(&tv, &qj->delivery) < 0) {
/* If the new entry should be scheduled earlier,
return TRUE;
} else {
-/* g_message("Accepted new query job.\n"); */
+/* avahi_log_debug("Accepted new query job.\n"); */
qj = job_new(s, key, FALSE);
qj->delivery = tv;
* "DUPLICATE QUESTION SUPPRESION". */
if ((qj = find_scheduled_job(s, key))) {
-/* g_message("Query suppressed by distributed duplicate suppression"); */
+/* avahi_log_debug("Query suppressed by distributed duplicate suppression"); */
job_mark_done(s, qj);
return;
}
#include "response-sched.h"
#include "util.h"
+#include "log.h"
#define AVAHI_RESPONSE_HISTORY_MSEC 700
#define AVAHI_RESPONSE_DEFER_MSEC 20
if (!packet_add_response_job(s, p, rj)) {
avahi_dns_packet_free(p);
- g_warning("Record too large, cannot send");
+ avahi_log_warn("Record too large, cannot send");
job_mark_done(s, rj);
return;
}
avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) &&
rj->record->ttl >= record->ttl/2) {
-/* g_message("Response suppressed by known answer suppression."); */
+/* avahi_log_debug("Response suppressed by known answer suppression."); */
return FALSE;
}
if (avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) &&
rj->record->ttl >= record->ttl/2 &&
(rj->flush_cache || !flush_cache)) {
-/* g_message("Response suppressed by local duplicate suppression (history)"); */
+/* avahi_log_debug("Response suppressed by local duplicate suppression (history)"); */
return FALSE;
}
avahi_elapse_time(&tv, immediately ? 0 : AVAHI_RESPONSE_DEFER_MSEC, immediately ? 0 : AVAHI_RESPONSE_JITTER_MSEC);
if ((rj = find_scheduled_job(s, record))) {
-/* g_message("Response suppressed by local duplicate suppression (scheduled)"); */
+/* avahi_log_debug("Response suppressed by local duplicate suppression (scheduled)"); */
/* Update a little ... */
return TRUE;
} else {
-/* g_message("Accepted new response job."); */
+/* avahi_log_debug("Accepted new response job."); */
/* Create a new job and schedule it */
rj = job_new(s, record, AVAHI_SCHEDULED);
record->ttl >= rj->record->ttl/2) { /* sensible TTL */
/* A matching entry was found, so let's mark it done */
-/* g_message("Response suppressed by distributed duplicate suppression"); */
+/* avahi_log_debug("Response suppressed by distributed duplicate suppression"); */
job_mark_done(s, rj);
}
record->ttl >= rj->record->ttl/2) { /* sensible TTL */
/* A matching entry was found, so let's drop it */
-/* g_message("Known answer suppression active!"); */
+/* avahi_log_debug("Known answer suppression active!"); */
job_free(s, rj);
}
}
#include "iface.h"
#include "socket.h"
#include "browse.h"
+#include "log.h"
#define AVAHI_HOST_RR_HOLDOFF_MSEC 2000
g_assert(i);
g_assert(k);
-/* g_message("Posting responses matching [%s]", txt = avahi_key_to_string(k)); */
+/* avahi_log_debug("Posting responses matching [%s]", txt = avahi_key_to_string(k)); */
/* g_free(txt); */
if (avahi_key_is_pattern(k)) {
if (!ours) {
if (won)
- g_message("xxx Recieved conflicting probe [%s]. Local host won.", t);
+ avahi_log_debug("xxx Recieved conflicting probe [%s]. Local host won.", t);
else if (lost) {
- g_message("yyy Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t);
+ avahi_log_debug("yyy Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t);
withdraw_rrset(s, record->key);
}
}
g_assert(record);
-/* g_message("CHECKING FOR CONFLICT: [%s]", t); */
+/* avahi_log_debug("CHECKING FOR CONFLICT: [%s]", t); */
for (e = g_hash_table_lookup(s->entries_by_key, record->key); e; e = n) {
n = e->by_key_next;
/* Refresh */
t = avahi_record_to_string(record);
- g_message("Recieved record with bad TTL [%s]. Refreshing.", t);
+ avahi_log_debug("Recieved record with bad TTL [%s]. Refreshing.", t);
avahi_server_prepare_matching_responses(s, i, e->record->key, FALSE);
valid = FALSE;
}
}
-/* g_message("ours=%i conflict=%i", ours, conflict); */
+/* avahi_log_debug("ours=%i conflict=%i", ours, conflict); */
if (!ours && conflict) {
gchar *t;
t = avahi_record_to_string(record);
if (withdraw_immediately) {
- g_message("Recieved conflicting record [%s] with local record to be. Withdrawing.", t);
+ avahi_log_debug("Recieved conflicting record [%s] with local record to be. Withdrawing.", t);
withdraw_rrset(s, record->key);
} else {
g_assert(conflicting_entry);
- g_message("Recieved conflicting record [%s]. Resetting our record.", t);
+ avahi_log_debug("Recieved conflicting record [%s]. Resetting our record.", t);
avahi_entry_return_to_initial_state(s, conflicting_entry, i);
/* Local unique records are returned to probin
avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
else {
gchar *t = avahi_record_to_string(r);
- g_warning("Record [%s] not fitting in legacy unicast packet, dropping.", t);
+ avahi_log_warn("Record [%s] not fitting in legacy unicast packet, dropping.", t);
g_free(t);
}
avahi_dns_packet_free(reply);
gchar *t = avahi_record_to_string(r);
- g_warning("Record [%s] too large, doesn't fit in any packet!", t);
+ avahi_log_warn("Record [%s] too large, doesn't fit in any packet!", t);
g_free(t);
break;
} else
g_assert(i);
g_assert(a);
-/* g_message("query"); */
+/* avahi_log_debug("query"); */
g_assert(avahi_record_list_empty(s->record_list));
gboolean unicast_response = FALSE;
if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) {
- g_warning("Packet too short (1)");
+ avahi_log_warn("Packet too short (1)");
goto fail;
}
gboolean unique = FALSE;
if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
- g_warning("Packet too short (2)");
+ avahi_log_warn("Packet too short (2)");
goto fail;
}
gboolean unique = FALSE;
if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
- g_warning("Packet too short (3)");
+ avahi_log_warn("Packet too short (3)");
goto fail;
}
g_assert(i);
g_assert(a);
-/* g_message("response"); */
+/* avahi_log_debug("response"); */
for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) +
avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT); n > 0; n--) {
/* gchar *txt; */
if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) {
- g_warning("Packet too short (4)");
+ avahi_log_warn("Packet too short (4)");
break;
}
if (record->key->type != AVAHI_DNS_TYPE_ANY) {
-/* g_message("Handling response: %s", txt = avahi_record_to_string(record)); */
+/* avahi_log_debug("Handling response: %s", txt = avahi_record_to_string(record)); */
/* g_free(txt); */
if (handle_conflict(s, i, record, cache_flush, a)) {
if (!s->config.enable_reflector)
return;
-/* g_message("legacy unicast reflectr"); */
+/* avahi_log_debug("legacy unicast reflectr"); */
/* Reflecting legacy unicast queries is a little more complicated
than reflecting normal queries, since we must route the
if (!(slot = allocate_slot(s))) {
/* No slot available, we drop this legacy unicast query */
- g_warning("No slot available for legacy unicast reflection, dropping query packet.");
+ avahi_log_warn("No slot available for legacy unicast reflection, dropping query packet.");
return;
}
socklen_t l = sizeof(lsa);
if (getsockname(s->fd_legacy_unicast_ipv4, &lsa, &l) != 0)
- g_warning("getsockname(): %s", strerror(errno));
+ avahi_log_warn("getsockname(): %s", strerror(errno));
else
return lsa.sin_port == ((struct sockaddr_in*) sa)->sin_port;
socklen_t l = sizeof(lsa);
if (getsockname(s->fd_legacy_unicast_ipv6, &lsa, &l) != 0)
- g_warning("getsockname(): %s", strerror(errno));
+ avahi_log_warn("getsockname(): %s", strerror(errno));
else
return lsa.sin6_port == ((struct sockaddr_in6*) sa)->sin6_port;
}
if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) ||
!avahi_interface_relevant(i)) {
- g_warning("Recieved packet from invalid interface.");
+ avahi_log_warn("Recieved packet from invalid interface.");
return;
}
-/* g_message("new packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */
+/* avahi_log_debug("new packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */
port = avahi_port_from_sockaddr(sa);
avahi_address_from_sockaddr(sa, &a);
return;
if (avahi_dns_packet_check_valid(p) < 0) {
- g_warning("Recieved invalid packet.");
+ avahi_log_warn("Recieved invalid packet.");
return;
}
gboolean legacy_unicast = FALSE;
if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT) != 0) {
- g_warning("Invalid query packet.");
+ avahi_log_warn("Invalid query packet.");
return;
}
if ((avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) != 0 ||
avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0)) {
- g_warning("Invalid legacy unicast query packet.");
+ avahi_log_warn("Invalid legacy unicast query packet.");
return;
}
handle_query_packet(s, p, i, &a, port, legacy_unicast);
-/* g_message("Handled query"); */
+/* avahi_log_debug("Handled query"); */
} else {
if (port != AVAHI_MDNS_PORT) {
- g_warning("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol);
+ avahi_log_warn("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol);
return;
}
if (ttl != 255) {
- g_warning("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol);
+ avahi_log_warn("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol);
if (s->config.check_response_ttl)
return;
}
if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT) != 0 ||
avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 ||
avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0) {
- g_warning("Invalid response packet.");
+ avahi_log_warn("Invalid response packet.");
return;
}
handle_response_packet(s, p, i, &a);
-/* g_message("Handled response"); */
+/* avahi_log_debug("Handled response"); */
}
}
if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family)) ||
!avahi_interface_relevant(i)) {
- g_warning("Recieved packet from invalid interface.");
+ avahi_log_warn("Recieved packet from invalid interface.");
return;
}
-/* g_message("new legacy unicast packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */
+/* avahi_log_debug("new legacy unicast packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol); */
port = avahi_port_from_sockaddr(sa);
avahi_address_from_sockaddr(sa, &a);
return;
if (avahi_dns_packet_check_valid(p) < 0 || avahi_dns_packet_is_query(p)) {
- g_warning("Recieved invalid packet.");
+ avahi_log_warn("Recieved invalid packet.");
return;
}
if (!(slot = find_slot(s, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ID)))) {
- g_warning("Recieved legacy unicast response with unknown id");
+ avahi_log_warn("Recieved legacy unicast response with unknown id");
return;
}
}
if (s->fd_ipv4 < 0 && s->config.use_ipv4)
- g_message("Failed to create IPv4 socket, proceeding in IPv6 only mode");
+ avahi_log_debug("Failed to create IPv4 socket, proceeding in IPv6 only mode");
else if (s->fd_ipv6 < 0 && s->config.use_ipv6)
- g_message("Failed to create IPv6 socket, proceeding in IPv4 only mode");
+ avahi_log_debug("Failed to create IPv6 socket, proceeding in IPv4 only mode");
s->fd_legacy_unicast_ipv4 = s->fd_ipv4 >= 0 && s->config.enable_reflector ? avahi_open_legacy_unicast_socket_ipv4() : -1;
s->fd_legacy_unicast_ipv6 = s->fd_ipv6 >= 0 && s->config.enable_reflector ? avahi_open_legacy_unicast_socket_ipv6() : -1;
#include "dns.h"
#include "util.h"
#include "socket.h"
+#include "log.h"
static void mdns_mcast_group_ipv4(struct sockaddr_in *ret_sa) {
g_assert(ret_sa);
mreq.imr_ifindex = index;
if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
- g_warning("IP_ADD_MEMBERSHIP failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_ADD_MEMBERSHIP failed: %s\n", strerror(errno));
return -1;
}
mreq6.ipv6mr_interface = index;
if (setsockopt(fd, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
- g_warning("IPV6_ADD_MEMBERSHIP failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_ADD_MEMBERSHIP failed: %s\n", strerror(errno));
return -1;
}
mreq.imr_ifindex = index;
if (setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
- g_warning("IP_DROP_MEMBERSHIP failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_DROP_MEMBERSHIP failed: %s\n", strerror(errno));
return -1;
}
mreq6.ipv6mr_interface = index;
if (setsockopt(fd, SOL_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
- g_warning("IPV6_DROP_MEMBERSHIP failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_DROP_MEMBERSHIP failed: %s\n", strerror(errno));
return -1;
}
int fd = -1, ttl, yes;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- g_warning("socket() failed: %s\n", strerror(errno));
+ avahi_log_warn("socket() failed: %s\n", strerror(errno));
goto fail;
}
ttl = 255;
if (setsockopt(fd, SOL_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
- g_warning("IP_MULTICAST_TTL failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_MULTICAST_TTL failed: %s\n", strerror(errno));
goto fail;
}
ttl = 255;
if (setsockopt(fd, SOL_IP, IP_TTL, &ttl, sizeof(ttl)) < 0) {
- g_warning("IP_TTL failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_TTL failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
- g_warning("SO_REUSEADDR failed: %s\n", strerror(errno));
+ avahi_log_warn("SO_REUSEADDR failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
- g_warning("IP_MULTICAST_LOOP failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_MULTICAST_LOOP failed: %s\n", strerror(errno));
goto fail;
}
local.sin_port = htons(AVAHI_MDNS_PORT);
if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
- g_warning("bind() failed: %s\n", strerror(errno));
+ avahi_log_warn("bind() failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
- g_warning("IP_RECVTTL failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_RECVTTL failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) {
- g_warning("IP_PKTINFO failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_PKTINFO failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_cloexec(fd) < 0) {
- g_warning("FD_CLOEXEC failed: %s\n", strerror(errno));
+ avahi_log_warn("FD_CLOEXEC failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_nonblock(fd) < 0) {
- g_warning("O_NONBLOCK failed: %s\n", strerror(errno));
+ avahi_log_warn("O_NONBLOCK failed: %s\n", strerror(errno));
goto fail;
}
mdns_mcast_group_ipv6(&sa);
if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- g_warning("socket() failed: %s\n", strerror(errno));
+ avahi_log_warn("socket() failed: %s\n", strerror(errno));
goto fail;
}
ttl = 255;
if (setsockopt(fd, SOL_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
- g_warning("IPV6_MULTICAST_HOPS failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_MULTICAST_HOPS failed: %s\n", strerror(errno));
goto fail;
}
ttl = 255;
if (setsockopt(fd, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0) {
- g_warning("IPV6_UNICAST_HOPS failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_UNICAST_HOPS failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
- g_warning("SO_REUSEADDR failed: %s\n", strerror(errno));
+ avahi_log_warn("SO_REUSEADDR failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) < 0) {
- g_warning("IPV6_V6ONLY failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_V6ONLY failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IPV6, IPV6_MULTICAST_LOOP, &yes, sizeof(yes)) < 0) {
- g_warning("IPV6_MULTICAST_LOOP failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_MULTICAST_LOOP failed: %s\n", strerror(errno));
goto fail;
}
local.sin6_port = htons(AVAHI_MDNS_PORT);
if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
- g_warning("bind() failed: %s\n", strerror(errno));
+ avahi_log_warn("bind() failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) {
- g_warning("IPV6_HOPLIMIT failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_HOPLIMIT failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) {
- g_warning("IPV6_PKTINFO failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_PKTINFO failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_cloexec(fd) < 0) {
- g_warning("FD_CLOEXEC failed: %s\n", strerror(errno));
+ avahi_log_warn("FD_CLOEXEC failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_nonblock(fd) < 0) {
- g_warning("O_NONBLOCK failed: %s\n", strerror(errno));
+ avahi_log_warn("O_NONBLOCK failed: %s\n", strerror(errno));
goto fail;
}
break;
if (errno != EAGAIN) {
- g_message("sendmsg() failed: %s\n", strerror(errno));
+ avahi_log_debug("sendmsg() failed: %s\n", strerror(errno));
return -1;
}
g_assert(ret_ttl);
if (ioctl(fd, FIONREAD, &ms) < 0) {
- g_warning("ioctl(): %s", strerror(errno));
+ avahi_log_warn("ioctl(): %s", strerror(errno));
goto fail;
}
msg.msg_flags = 0;
if ((l = recvmsg(fd, &msg, 0)) < 0) {
- g_warning("recvmsg(): %s", strerror(errno));
+ avahi_log_warn("recvmsg(): %s", strerror(errno));
goto fail;
}
}
}
-/* g_message("ttl=%u iface=%i", *ret_ttl, *ret_iface); */
+/* avahi_log_debug("ttl=%u iface=%i", *ret_ttl, *ret_iface); */
g_assert(found_iface);
g_assert(found_ttl);
g_assert(ret_ttl);
if (ioctl(fd, FIONREAD, &ms) < 0) {
- g_warning("ioctl(): %s", strerror(errno));
+ avahi_log_warn("ioctl(): %s", strerror(errno));
goto fail;
}
msg.msg_flags = 0;
if ((l = recvmsg(fd, &msg, 0)) < 0) {
- g_warning("recvmsg(): %s", strerror(errno));
+ avahi_log_warn("recvmsg(): %s", strerror(errno));
goto fail;
}
int fd = -1, yes;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- g_warning("socket() failed: %s\n", strerror(errno));
+ avahi_log_warn("socket() failed: %s\n", strerror(errno));
goto fail;
}
local.sin_family = AF_INET;
if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
- g_warning("bind() failed: %s\n", strerror(errno));
+ avahi_log_warn("bind() failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) {
- g_warning("IP_RECVTTL failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_RECVTTL failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0) {
- g_warning("IP_PKTINFO failed: %s\n", strerror(errno));
+ avahi_log_warn("IP_PKTINFO failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_cloexec(fd) < 0) {
- g_warning("FD_CLOEXEC failed: %s\n", strerror(errno));
+ avahi_log_warn("FD_CLOEXEC failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_nonblock(fd) < 0) {
- g_warning("O_NONBLOCK failed: %s\n", strerror(errno));
+ avahi_log_warn("O_NONBLOCK failed: %s\n", strerror(errno));
goto fail;
}
int fd = -1, yes;
if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- g_warning("socket() failed: %s\n", strerror(errno));
+ avahi_log_warn("socket() failed: %s\n", strerror(errno));
goto fail;
}
local.sin_family = AF_INET;
if (bind(fd, (struct sockaddr*) &local, sizeof(local)) < 0) {
- g_warning("bind() failed: %s\n", strerror(errno));
+ avahi_log_warn("bind() failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IPV6, IPV6_HOPLIMIT, &yes, sizeof(yes)) < 0) {
- g_warning("IPV6_HOPLIMIT failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_HOPLIMIT failed: %s\n", strerror(errno));
goto fail;
}
yes = 1;
if (setsockopt(fd, SOL_IPV6, IPV6_PKTINFO, &yes, sizeof(yes)) < 0) {
- g_warning("IPV6_PKTINFO failed: %s\n", strerror(errno));
+ avahi_log_warn("IPV6_PKTINFO failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_cloexec(fd) < 0) {
- g_warning("FD_CLOEXEC failed: %s\n", strerror(errno));
+ avahi_log_warn("FD_CLOEXEC failed: %s\n", strerror(errno));
goto fail;
}
if (avahi_set_nonblock(fd) < 0) {
- g_warning("O_NONBLOCK failed: %s\n", strerror(errno));
+ avahi_log_warn("O_NONBLOCK failed: %s\n", strerror(errno));
goto fail;
}
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = ../avahi-core/core.h ../avahi-common/address.h ../avahi-common/rr.h ../avahi-common/strlst.h ../avahi-common/alternative.h
+INPUT = ../avahi-core/core.h ../avahi-common/address.h ../avahi-common/rr.h ../avahi-common/strlst.h ../avahi-common/alternative.h ../avahi-core/log.h
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
* enlarge packet in case a record/query is too large to fit in a normal packet
* reflector
* test against apple test suite
+* sensible logging