ret_addr->family = sa->sa_family;
if (sa->sa_family == AF_INET)
- memcpy(&ret_addr->data.ipv4, &((struct sockaddr_in*) sa)->sin_addr, sizeof(ret_addr->data.ipv4));
+ memcpy(&ret_addr->data.ipv4, &((const struct sockaddr_in*) sa)->sin_addr, sizeof(ret_addr->data.ipv4));
else
- memcpy(&ret_addr->data.ipv6, &((struct sockaddr_in6*) sa)->sin6_addr, sizeof(ret_addr->data.ipv6));
+ memcpy(&ret_addr->data.ipv6, &((const struct sockaddr_in6*) sa)->sin6_addr, sizeof(ret_addr->data.ipv6));
return ret_addr;
}
g_assert(sa->sa_family == AF_INET || sa->sa_family == AF_INET6);
if (sa->sa_family == AF_INET)
- return ntohs(((struct sockaddr_in*) sa)->sin_port);
+ return ntohs(((const struct sockaddr_in*) sa)->sin_port);
else
- return ntohs(((struct sockaddr_in6*) sa)->sin6_port);
+ return ntohs(((const struct sockaddr_in6*) sa)->sin6_port);
}
gboolean avahi_address_is_ipv4_in_ipv6(const AvahiAddress *a) {
a = avahi_string_list_add(a, "foo");
a = avahi_string_list_add(a, "bar");
a = avahi_string_list_add(a, "quux");
- a = avahi_string_list_add_arbitrary(a, (guint8*) "null\0null", 9);
+ a = avahi_string_list_add_arbitrary(a, (const guint8*) "null\0null", 9);
a = avahi_string_list_add(a, "end");
t = avahi_string_list_to_string(a);
AvahiStringList *avahi_string_list_new_from_array(const gchar *array[], gint length) {
AvahiStringList *r = NULL;
- gint index;
+ gint i;
g_assert(array);
- for (index = 0; length >= 0 ? index < length : !!array[index]; index++)
- r = avahi_string_list_add(r, array[index]);
+ for (i = 0; length >= 0 ? i < length : !!array[i]; i++)
+ r = avahi_string_list_add(r, array[i]);
return r;
}
gboolean avahi_entry_registered(AvahiServer *s, AvahiEntry *e, AvahiInterface *i);
gboolean avahi_entry_probing(AvahiServer *s, AvahiEntry *e, AvahiInterface *i);
-void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, gboolean send);
-void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, gboolean send);
+void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, gboolean send_goodbye);
+void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, gboolean send_goodbye);
-void avahi_goodbye_all(AvahiServer *s, gboolean send);
+void avahi_goodbye_all(AvahiServer *s, gboolean send_goodbye);
AvahiAnnouncement *avahi_get_announcement(AvahiServer *s, AvahiEntry *e, AvahiInterface *i);
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
+#include <stdio.h>
#include <avahi-core/core.h>
#include <avahi-core/log.h>
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) {
+static void sr_callback(AvahiServiceResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *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)
- avahi_log_debug("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, name, service_type, domain_name);
else {
gchar t[64], *s;
avahi_address_snprint(t, sizeof(t), a);
s = avahi_string_list_to_string(txt);
- 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);
+ avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s>: %s/%s:%i (%s) [found]", iface, protocol, name, service_type, domain_name, hostname, t, port, s);
g_free(s);
}
}
avahi_cache_walk(i->cache, s->key, scan_cache_callback, &cbdata);
}
-gboolean scan_idle_callback(gpointer data) {
+static gboolean scan_idle_callback(gpointer data) {
AvahiRecordBrowser *b = data;
g_assert(b);
usec = ((AvahiUsec) e->record->ttl) * 10000;
/* 2% jitter */
- usec = (AvahiUsec) g_random_double_range(usec*percent, usec*(percent+2));
+ usec = (AvahiUsec) g_random_double_range((gdouble) (usec*percent), (gdouble) (usec*(percent+2)));
/* g_message("next expiry: %lli (%s)", usec / 1000000, txt = avahi_record_to_string(e->record)); */
/* g_free(txt); */
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stdio.h>
#include "core.h"
#include "util.h"
static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata);
-static void create_service(gchar *t) {
+static void create_service(const gchar *t) {
gchar *n;
g_assert(t || name);
#include "log.h"
int main(int argc, char *argv[]) {
- gchar t[256], *a, *b, *c, *d;
+ gchar t[256];
+ const gchar *a, *b, *c, *d;
AvahiDnsPacket *p;
p = avahi_dns_packet_new(0);
g_free(p);
}
-void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint index, guint16 v) {
+void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint idx, guint16 v) {
g_assert(p);
- g_assert(index < AVAHI_DNS_PACKET_HEADER_SIZE);
+ g_assert(idx < AVAHI_DNS_PACKET_HEADER_SIZE);
- ((guint16*) AVAHI_DNS_PACKET_DATA(p))[index] = g_htons(v);
+ ((guint16*) AVAHI_DNS_PACKET_DATA(p))[idx] = g_htons(v);
}
-guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint index) {
+guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint idx) {
g_assert(p);
- g_assert(index < AVAHI_DNS_PACKET_HEADER_SIZE);
+ g_assert(idx < AVAHI_DNS_PACKET_HEADER_SIZE);
- return g_ntohs(((guint16*) AVAHI_DNS_PACKET_DATA(p))[index]);
+ return g_ntohs(((guint16*) AVAHI_DNS_PACKET_DATA(p))[idx]);
}
-void avahi_dns_packet_inc_field(AvahiDnsPacket *p, guint index) {
+void avahi_dns_packet_inc_field(AvahiDnsPacket *p, guint idx) {
g_assert(p);
+ g_assert(idx < AVAHI_DNS_PACKET_HEADER_SIZE);
- avahi_dns_packet_set_field(p, index, avahi_dns_packet_get_field(p, index) + 1);
+ avahi_dns_packet_set_field(p, idx, avahi_dns_packet_get_field(p, idx) + 1);
}
guint8* avahi_dns_packet_append_name(AvahiDnsPacket *p, const gchar *name) {
/* Check whether we can compress this name. */
if (p->name_table && (prev = g_hash_table_lookup(p->name_table, name))) {
- guint index;
+ guint idx;
g_assert(prev >= AVAHI_DNS_PACKET_DATA(p));
- index = (guint) (prev - AVAHI_DNS_PACKET_DATA(p));
+ idx = (guint) (prev - AVAHI_DNS_PACKET_DATA(p));
- g_assert(index < p->size);
+ g_assert(idx < p->size);
- if (index < 0x4000) {
+ if (idx < 0x4000) {
guint16 *t;
if (!(t = (guint16*) avahi_dns_packet_extend(p, sizeof(guint16))))
return NULL;
- *t = g_htons((0xC000 | index));
+ *t = g_htons((0xC000 | idx));
return saved_ptr;
}
}
return !(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_QR);
}
-static gint consume_labels(AvahiDnsPacket *p, guint index, gchar *ret_name, guint l) {
+static gint consume_labels(AvahiDnsPacket *p, guint idx, gchar *ret_name, guint l) {
gint ret = 0;
int compressed = 0;
int first_label = 1;
for (;;) {
guint8 n;
- if (index+1 > p->size)
+ if (idx+1 > p->size)
return -1;
- n = AVAHI_DNS_PACKET_DATA(p)[index];
+ n = AVAHI_DNS_PACKET_DATA(p)[idx];
if (!n) {
- index++;
+ idx++;
if (!compressed)
ret++;
} else if (n <= 63) {
/* Uncompressed label */
- index++;
+ idx++;
if (!compressed)
ret++;
- if (index + n > p->size)
+ if (idx + n > p->size)
return -1;
if ((guint) n + 1 > l)
} else
first_label = 0;
- if (!(avahi_escape_label(AVAHI_DNS_PACKET_DATA(p) + index, n, &ret_name, &l)))
+ if (!(avahi_escape_label(AVAHI_DNS_PACKET_DATA(p) + idx, n, &ret_name, &l)))
return -1;
- index += n;
+ idx += n;
if (!compressed)
ret += n;
} else if ((n & 0xC0) == 0xC0) {
/* Compressed label */
- if (index+2 > p->size)
+ if (idx+2 > p->size)
return -1;
- index = ((guint) (AVAHI_DNS_PACKET_DATA(p)[index] & ~0xC0)) << 8 | AVAHI_DNS_PACKET_DATA(p)[index+1];
+ idx = ((guint) (AVAHI_DNS_PACKET_DATA(p)[idx] & ~0xC0)) << 8 | AVAHI_DNS_PACKET_DATA(p)[idx+1];
if (!compressed)
ret += 2;
/* 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)
+ if ((const guint8*) avahi_dns_packet_get_rptr(p) - (const guint8*) start != rdlength)
goto fail;
return r;
case AVAHI_DNS_TYPE_TXT: {
guint8 *data;
- guint size;
+ guint n;
- size = avahi_string_list_serialize(r->data.txt.string_list, NULL, 0);
+ n = avahi_string_list_serialize(r->data.txt.string_list, NULL, 0);
-/* avahi_log_debug("appending string: %u %p", size, r->data.txt.string_list); */
+/* avahi_log_debug("appending string: %u %p", n, r->data.txt.string_list); */
- if (!(data = avahi_dns_packet_extend(p, size)))
+ if (!(data = avahi_dns_packet_extend(p, n)))
goto fail;
- avahi_string_list_serialize(r->data.txt.string_list, data, size);
+ avahi_string_list_serialize(r->data.txt.string_list, data, n);
break;
}
AvahiDnsPacket* avahi_dns_packet_new_reply(AvahiDnsPacket* p, guint mtu, gboolean copy_queries, gboolean aa);
void avahi_dns_packet_free(AvahiDnsPacket *p);
-void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint index, guint16 v);
-guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint index);
-void avahi_dns_packet_inc_field(AvahiDnsPacket *p, guint index);
+void avahi_dns_packet_set_field(AvahiDnsPacket *p, guint idx, guint16 v);
+guint16 avahi_dns_packet_get_field(AvahiDnsPacket *p, guint idx);
+void avahi_dns_packet_inc_field(AvahiDnsPacket *p, guint idx);
guint8 *avahi_dns_packet_extend(AvahiDnsPacket *p, guint l);
#include <linux/rtnetlink.h>
#include <errno.h>
#include <net/if.h>
+#include <stdio.h>
#include "iface.h"
#include "netlink.h"
#include "util.h"
#include "log.h"
-static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a, gboolean remove) {
+static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a, gboolean remove_rrs) {
g_assert(m);
g_assert(a);
if (avahi_interface_address_relevant(a) &&
- !remove &&
+ !remove_rrs &&
m->server->config.publish_addresses &&
(m->server->state == AVAHI_SERVER_RUNNING ||
m->server->state == AVAHI_SERVER_REGISTERING)) {
}
}
-static void update_interface_rr(AvahiInterfaceMonitor *m, AvahiInterface *i, gboolean remove) {
+static void update_interface_rr(AvahiInterfaceMonitor *m, AvahiInterface *i, gboolean remove_rrs) {
AvahiInterfaceAddress *a;
g_assert(m);
g_assert(i);
for (a = i->addresses; a; a = a->address_next)
- update_address_rr(m, a, remove);
+ update_address_rr(m, a, remove_rrs);
}
-static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, gboolean remove) {
+static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, gboolean remove_rrs) {
AvahiInterface *i;
g_assert(m);
g_assert(hw);
for (i = hw->interfaces; i; i = i->by_hardware_next)
- update_interface_rr(m, i, remove);
+ update_interface_rr(m, i, remove_rrs);
- if (!remove &&
+ if (!remove_rrs &&
m->server->config.publish_workstation &&
(m->server->state == AVAHI_SERVER_RUNNING ||
m->server->state == AVAHI_SERVER_REGISTERING)) {
avahi_log_debug("New relevant interface %s.%i (#%i)", i->hardware->name, i->protocol, i->hardware->index);
if (i->protocol == AVAHI_PROTO_INET)
- avahi_mdns_mcast_join_ipv4(i->hardware->index, m->server->fd_ipv4);
+ avahi_mdns_mcast_join_ipv4(m->server->fd_ipv4, i->hardware->index);
if (i->protocol == AVAHI_PROTO_INET6)
- avahi_mdns_mcast_join_ipv6(i->hardware->index, m->server->fd_ipv6);
+ avahi_mdns_mcast_join_ipv6(m->server->fd_ipv6, i->hardware->index);
i->announcing = TRUE;
avahi_announce_interface(m->server, i);
avahi_log_debug("Interface %s.%i no longer relevant", i->hardware->name, i->protocol);
if (i->protocol == AVAHI_PROTO_INET)
- avahi_mdns_mcast_leave_ipv4(i->hardware->index, m->server->fd_ipv4);
+ avahi_mdns_mcast_leave_ipv4(m->server->fd_ipv4, i->hardware->index);
if (i->protocol == AVAHI_PROTO_INET6)
- avahi_mdns_mcast_leave_ipv6(i->hardware->index, m->server->fd_ipv6);
+ avahi_mdns_mcast_leave_ipv6(m->server->fd_ipv6, i->hardware->index);
avahi_goodbye_interface(m->server, i, FALSE);
avahi_response_scheduler_clear(i->response_scheduler);
check_interface_relevant(m, i);
}
-static void callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata) {
+static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata) {
AvahiInterfaceMonitor *m = userdata;
g_assert(m);
m = g_new0(AvahiInterfaceMonitor, 1);
m->server = s;
- if (!(m->netlink = avahi_netlink_new(s->context, G_PRIORITY_DEFAULT-10, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, callback, m)))
+ if (!(m->netlink = avahi_netlink_new(s->context, G_PRIORITY_DEFAULT-10, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, netlink_callback, m)))
goto fail;
m->hash_table = g_hash_table_new(g_int_hash, g_int_equal);
}
-AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex index, AvahiProtocol protocol) {
+AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol) {
AvahiHwInterface *hw;
AvahiInterface *i;
g_assert(m);
- g_assert(index > 0);
+ g_assert(idx > 0);
g_assert(protocol != AVAHI_PROTO_UNSPEC);
- if (!(hw = avahi_interface_monitor_get_hw_interface(m, index)))
+ if (!(hw = avahi_interface_monitor_get_hw_interface(m, idx)))
return NULL;
for (i = hw->interfaces; i; i = i->by_hardware_next)
return NULL;
}
-AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, AvahiIfIndex index) {
+AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx) {
g_assert(m);
- g_assert(index > 0);
+ g_assert(idx > 0);
- return g_hash_table_lookup(m->hash_table, &index);
+ return g_hash_table_lookup(m->hash_table, &idx);
}
}
-gboolean avahi_interface_match(AvahiInterface *i, AvahiIfIndex index, AvahiProtocol protocol) {
+gboolean avahi_interface_match(AvahiInterface *i, AvahiIfIndex idx, AvahiProtocol protocol) {
g_assert(i);
- if (index > 0 && index != i->hardware->index)
+ if (idx > 0 && idx != i->hardware->index)
return FALSE;
if (protocol != AVAHI_PROTO_UNSPEC && protocol != i->protocol)
}
}
-void avahi_update_host_rrs(AvahiInterfaceMonitor *m, gboolean remove) {
+void avahi_update_host_rrs(AvahiInterfaceMonitor *m, gboolean remove_rrs) {
AvahiHwInterface *hw;
g_assert(m);
for (hw = m->hw_interfaces; hw; hw = hw->hardware_next)
- update_hw_interface_rr(m, hw, remove);
+ update_hw_interface_rr(m, hw, remove_rrs);
}
gboolean avahi_address_is_local(AvahiInterfaceMonitor *m, const AvahiAddress *a) {
if ((g_ntohl(a->data.ipv4.address) & m) == (g_ntohl(ia->address.data.ipv4.address) & m))
return TRUE;
} else {
- guint i;
+ guint j;
guchar pl;
g_assert(a->family == AVAHI_PROTO_INET6);
pl = ia->prefix_len;
- for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
guint8 m;
if (pl == 0)
pl = 0;
}
- if ((a->data.ipv6.address[i] & m) != (ia->address.data.ipv6.address[i] & m))
+ if ((a->data.ipv6.address[j] & m) != (ia->address.data.ipv6.address[j] & m))
break;
}
}
void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m);
-AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex index, AvahiProtocol protocol);
-AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, gint index);
+AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol);
+AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, gint idx);
void avahi_interface_send_packet(AvahiInterface *i, AvahiDnsPacket *p);
void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, guint16 port);
gboolean avahi_interface_relevant(AvahiInterface *i);
gboolean avahi_interface_address_relevant(AvahiInterfaceAddress *a);
-gboolean avahi_interface_match(AvahiInterface *i, AvahiIfIndex index, AvahiProtocol protocol);
+gboolean avahi_interface_match(AvahiInterface *i, AvahiIfIndex idx, AvahiProtocol protocol);
typedef void (*AvahiInterfaceMonitorWalkCallback)(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata);
-void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, AvahiIfIndex index, AvahiProtocol protocol, AvahiInterfaceMonitorWalkCallback callback, gpointer userdata);
+void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol, AvahiInterfaceMonitorWalkCallback callback, gpointer userdata);
-void avahi_update_host_rrs(AvahiInterfaceMonitor *m, gboolean remove);
+void avahi_update_host_rrs(AvahiInterfaceMonitor *m, gboolean remove_rrs);
gboolean avahi_address_is_local(AvahiInterfaceMonitor *m, const AvahiAddress *a);
GSource *source;
void (*callback) (AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata);
gpointer userdata;
+ guint8* buffer;
+ guint buffer_length;
};
gboolean avahi_netlink_work(AvahiNetlink *nl, gboolean block) {
for (;;) {
ssize_t bytes;
struct nlmsghdr *p;
- guint8 buffer[64*1024];
- p = (struct nlmsghdr *) buffer;
+ for (;;) {
+ if ((bytes = recv(nl->fd, nl->buffer, nl->buffer_length, block ? 0 : MSG_DONTWAIT)) < 0) {
- if ((bytes = recv(nl->fd, buffer, sizeof(buffer), block ? 0 : MSG_DONTWAIT)) < 0) {
-
- if (errno == EAGAIN || errno == EINTR)
- break;
+ if (errno == EAGAIN || errno == EINTR)
+ return TRUE;
+
+ avahi_log_warn("NETLINK: recv() failed: %s", strerror(errno));
+ return FALSE;
+ }
- avahi_log_warn("NETLINK: recv() failed: %s", strerror(errno));
- return FALSE;
+ break;
}
+ p = (struct nlmsghdr *) nl->buffer;
+
if (nl->callback) {
for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) {
if (!NLMSG_OK(p, (size_t) bytes)) {
}
if (block)
- break;
+ return TRUE;
}
-
- return TRUE;
}
static gboolean prepare_func(GSource *source, gint *timeout) {
nl->seq = 0;
nl->callback = cb;
nl->userdata = userdata;
+ nl->buffer = g_new(guint8, nl->buffer_length = 64*1024);
nl->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(AvahiNetlink*));
*((AvahiNetlink**) (((guint8*) nl->source) + sizeof(GSource))) = nl;
g_source_unref(nl->source);
g_main_context_unref(nl->context);
close(nl->fd);
+ g_free(nl->buffer);
g_free(nl);
}
g_assert(FALSE);
}
- snprintf(sn, sizeof(sn), r->service_name);
- snprintf(st, sizeof(st), r->service_type);
+ g_snprintf(sn, sizeof(sn), r->service_name);
+ g_snprintf(st, sizeof(st), r->service_type);
if ((i = strlen(sn)) > 0 && sn[i-1] == '.')
sn[i-1] = 0;
n = t;
l = sizeof(t);
- avahi_escape_label((guint8*) name, strlen(name), &n, &l);
- snprintf(n, l, ".%s.%s", r->service_type, r->domain_name);
+ avahi_escape_label((const guint8*) name, strlen(name), &n, &l);
+ g_snprintf(n, l, ".%s.%s", r->service_type, r->domain_name);
avahi_elapse_time(&tv, 1000, 0);
r->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, time_event_callback, r);
#include <sys/utsname.h>
#include <unistd.h>
#include <errno.h>
+#include <stdio.h>
#include "server.h"
#include "util.h"
}
static AvahiLegacyUnicastReflectSlot* allocate_slot(AvahiServer *s) {
- guint n, index = (guint) -1;
+ guint n, idx = (guint) -1;
AvahiLegacyUnicastReflectSlot *slot;
g_assert(s);
s->legacy_unicast_reflect_slots = g_new0(AvahiLegacyUnicastReflectSlot*, AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS);
for (n = 0; n < AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS; n++, s->legacy_unicast_reflect_id++) {
- index = s->legacy_unicast_reflect_id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
+ idx = s->legacy_unicast_reflect_id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
- if (!s->legacy_unicast_reflect_slots[index])
+ if (!s->legacy_unicast_reflect_slots[idx])
break;
}
- if (index == (guint) -1 || s->legacy_unicast_reflect_slots[index])
+ if (idx == (guint) -1 || s->legacy_unicast_reflect_slots[idx])
return NULL;
- slot = s->legacy_unicast_reflect_slots[index] = g_new(AvahiLegacyUnicastReflectSlot, 1);
+ slot = s->legacy_unicast_reflect_slots[idx] = g_new(AvahiLegacyUnicastReflectSlot, 1);
slot->id = s->legacy_unicast_reflect_id++;
slot->server = s;
return slot;
}
static void deallocate_slot(AvahiServer *s, AvahiLegacyUnicastReflectSlot *slot) {
- guint index;
+ guint idx;
g_assert(s);
g_assert(slot);
- index = slot->id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
+ idx = slot->id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
- g_assert(s->legacy_unicast_reflect_slots[index] == slot);
+ g_assert(s->legacy_unicast_reflect_slots[idx] == slot);
avahi_time_event_queue_remove(s->time_event_queue, slot->time_event);
g_free(slot);
- s->legacy_unicast_reflect_slots[index] = NULL;
+ s->legacy_unicast_reflect_slots[idx] = NULL;
}
static void free_slots(AvahiServer *s) {
- guint index;
+ guint idx;
g_assert(s);
if (!s->legacy_unicast_reflect_slots)
return;
- for (index = 0; index < AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS; index ++)
- if (s->legacy_unicast_reflect_slots[index])
- deallocate_slot(s, s->legacy_unicast_reflect_slots[index]);
+ for (idx = 0; idx < AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS; idx ++)
+ if (s->legacy_unicast_reflect_slots[idx])
+ deallocate_slot(s, s->legacy_unicast_reflect_slots[idx]);
g_free(s->legacy_unicast_reflect_slots);
s->legacy_unicast_reflect_slots = NULL;
}
static AvahiLegacyUnicastReflectSlot* find_slot(AvahiServer *s, guint16 id) {
- guint index;
+ guint idx;
g_assert(s);
if (!s->legacy_unicast_reflect_slots)
return NULL;
- index = id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
+ idx = id % AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS;
- if (!s->legacy_unicast_reflect_slots[index] || s->legacy_unicast_reflect_slots[index]->id != id)
+ if (!s->legacy_unicast_reflect_slots[idx] || s->legacy_unicast_reflect_slots[idx]->id != id)
return NULL;
- return s->legacy_unicast_reflect_slots[index];
+ return s->legacy_unicast_reflect_slots[idx];
}
static void legacy_unicast_reflect_slot_timeout(AvahiTimeEvent *e, void *userdata) {
if (getsockname(s->fd_legacy_unicast_ipv4, &lsa, &l) != 0)
avahi_log_warn("getsockname(): %s", strerror(errno));
else
- return lsa.sin_port == ((struct sockaddr_in*) sa)->sin_port;
+ return lsa.sin_port == ((const struct sockaddr_in*) sa)->sin_port;
}
if (getsockname(s->fd_legacy_unicast_ipv6, &lsa, &l) != 0)
avahi_log_warn("getsockname(): %s", strerror(errno));
else
- return lsa.sin6_port == ((struct sockaddr_in6*) sa)->sin6_port;
+ return lsa.sin6_port == ((const struct sockaddr_in6*) sa)->sin6_port;
}
return FALSE;
continue;
t = avahi_record_to_string(e->record);
- snprintf(ln, sizeof(ln), "%s ; iface=%i proto=%i", t, e->interface, e->protocol);
+ g_snprintf(ln, sizeof(ln), "%s ; iface=%i proto=%i", t, e->interface, e->protocol);
g_free(t);
callback(ln, userdata);
d = avahi_normalize_name(domain);
t = avahi_normalize_name(type);
- snprintf(ptr_name, sizeof(ptr_name), "%s.%s", t, d);
- snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, t, d);
+ g_snprintf(ptr_name, sizeof(ptr_name), "%s.%s", t, d);
+ g_snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, t, d);
ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, ptr_name, svc_name);
ret |= avahi_server_add_txt_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
- snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", d);
+ g_snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", d);
ret |=avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name);
g_free(d);
domain = s->domain_name;
d = avahi_normalize_name(domain);
- snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", d);
+ g_snprintf(t, sizeof(t), "%s.%s", type == AVAHI_DNS_SERVER_RESOLVE ? "_domain._udp" : "_dns-update._udp", d);
g_free(d);
r = avahi_record_new_full(t, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME);
memcpy(&ret_sa->sin6_addr, a, sizeof(AvahiIPv6Address));
}
-int avahi_mdns_mcast_join_ipv4 (int index, int fd) {
+int avahi_mdns_mcast_join_ipv4(gint fd, gint idx) {
struct ip_mreqn mreq;
struct sockaddr_in sa;
memset(&mreq, 0, sizeof(mreq));
mreq.imr_multiaddr = sa.sin_addr;
- mreq.imr_ifindex = index;
+ mreq.imr_ifindex = idx;
if (setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
avahi_log_warn("IP_ADD_MEMBERSHIP failed: %s\n", strerror(errno));
return 0;
}
-int avahi_mdns_mcast_join_ipv6 (int index, int fd) {
+int avahi_mdns_mcast_join_ipv6(gint fd, gint idx) {
struct ipv6_mreq mreq6;
struct sockaddr_in6 sa6;
memset(&mreq6, 0, sizeof(mreq6));
mreq6.ipv6mr_multiaddr = sa6.sin6_addr;
- mreq6.ipv6mr_interface = index;
+ mreq6.ipv6mr_interface = idx;
if (setsockopt(fd, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
avahi_log_warn("IPV6_ADD_MEMBERSHIP failed: %s\n", strerror(errno));
return 0;
}
-int avahi_mdns_mcast_leave_ipv4 (int index, int fd) {
+int avahi_mdns_mcast_leave_ipv4(gint fd, gint idx) {
struct ip_mreqn mreq;
struct sockaddr_in sa;
memset(&mreq, 0, sizeof(mreq));
mreq.imr_multiaddr = sa.sin_addr;
- mreq.imr_ifindex = index;
+ mreq.imr_ifindex = idx;
if (setsockopt(fd, SOL_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
avahi_log_warn("IP_DROP_MEMBERSHIP failed: %s\n", strerror(errno));
return 0;
}
-int avahi_mdns_mcast_leave_ipv6 (int index, int fd) {
+int avahi_mdns_mcast_leave_ipv6(gint fd, gint idx) {
struct ipv6_mreq mreq6;
struct sockaddr_in6 sa6;
memset(&mreq6, 0, sizeof(mreq6));
mreq6.ipv6mr_multiaddr = sa6.sin6_addr;
- mreq6.ipv6mr_interface = index;
+ mreq6.ipv6mr_interface = idx;
if (setsockopt(fd, SOL_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
avahi_log_warn("IPV6_DROP_MEMBERSHIP failed: %s\n", strerror(errno));
AvahiDnsPacket *avahi_recv_dns_packet_ipv4(gint fd, struct sockaddr_in*ret_sa, AvahiIPv4Address *ret_dest_address, gint *ret_iface, guint8 *ret_ttl);
AvahiDnsPacket *avahi_recv_dns_packet_ipv6(gint fd, struct sockaddr_in6*ret_sa, AvahiIPv6Address *ret_dest_address, gint *ret_iface, guint8 *ret_ttl);
-int avahi_mdns_mcast_join_ipv4(int index, int fd);
-int avahi_mdns_mcast_join_ipv6(int index, int fd);
+int avahi_mdns_mcast_join_ipv4(gint fd, gint idx);
+int avahi_mdns_mcast_join_ipv6(gint fd, gint idx);
-int avahi_mdns_mcast_leave_ipv4(int index, int fd);
-int avahi_mdns_mcast_leave_ipv6(int index, int fd);
+int avahi_mdns_mcast_leave_ipv4(gint fd, gint idx);
+int avahi_mdns_mcast_leave_ipv6(gint fd, gint idx);
#endif
static AvahiTimeEventQueue *q = NULL;
-void callback(AvahiTimeEvent*e, gpointer userdata) {
+static void callback(AvahiTimeEvent*e, gpointer userdata) {
GTimeVal tv = {0, 0};
g_assert(e);
g_message("callback(%i)", GPOINTER_TO_INT(userdata));
#define MAX_NAME_SERVERS 10
-static gint load_resolv_conf(const DaemonConfig *config) {
+static gint load_resolv_conf(const DaemonConfig *c) {
gint ret = -1;
FILE *f;
gint i = 0;
g_strfreev(resolv_conf);
resolv_conf = NULL;
- if (!config->publish_resolv_conf)
+ if (!c->publish_resolv_conf)
return 0;
if (!(f = fopen(RESOLV_CONF, "r"))) {
}
static void server_callback(AvahiServer *s, AvahiServerState state, gpointer userdata) {
- DaemonConfig *config = userdata;
+ DaemonConfig *c = userdata;
g_assert(s);
- g_assert(config);
+ g_assert(c);
#ifdef ENABLE_DBUS
- if (config->enable_dbus)
+ if (c->enable_dbus)
dbus_protocol_server_state_changed(state);
#endif
if (resolv_conf && resolv_conf[0])
resolv_conf_entry_group = add_dns_servers(s, resolv_conf);
- if (config->publish_dns_servers && config->publish_dns_servers[0])
- dns_servers_entry_group = add_dns_servers(s, config->publish_dns_servers);
+ if (c->publish_dns_servers && c->publish_dns_servers[0])
+ dns_servers_entry_group = add_dns_servers(s, c->publish_dns_servers);
simple_protocol_restart_queries();
argv0);
}
-static gint parse_command_line(DaemonConfig *config, int argc, char *argv[]) {
- gint c;
+static gint parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
+ gint o;
static const struct option const long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "check", no_argument, NULL, 'c' },
};
- g_assert(config);
+ g_assert(c);
opterr = 0;
- while ((c = getopt_long(argc, argv, "hDkVf:rc", long_options, NULL)) >= 0) {
+ while ((o = getopt_long(argc, argv, "hDkVf:rc", long_options, NULL)) >= 0) {
- switch(c) {
+ switch(o) {
case 'h':
- config->command = DAEMON_HELP;
+ c->command = DAEMON_HELP;
break;
case 'D':
- config->daemonize = TRUE;
+ c->daemonize = TRUE;
break;
case 'k':
- config->command = DAEMON_KILL;
+ c->command = DAEMON_KILL;
break;
case 'V':
- config->command = DAEMON_VERSION;
+ c->command = DAEMON_VERSION;
break;
case 'f':
- g_free(config->config_file);
- config->config_file = g_strdup(optarg);
+ g_free(c->config_file);
+ c->config_file = g_strdup(optarg);
break;
case 'r':
- config->command = DAEMON_RELOAD;
+ c->command = DAEMON_RELOAD;
break;
case 'c':
- config->command = DAEMON_CHECK;
+ c->command = DAEMON_CHECK;
break;
default:
- fprintf(stderr, "Invalid command line argument: %c\n", c);
+ fprintf(stderr, "Invalid command line argument: %c\n", o);
return -1;
}
}
return *s == 'y' || *s == 'Y';
}
-static gint load_config_file(DaemonConfig *config) {
+static gint load_config_file(DaemonConfig *c) {
int r = -1;
GKeyFile *f = NULL;
GError *err = NULL;
gchar **groups = NULL, **g, **keys = NULL, *v = NULL;
- g_assert(config);
+ g_assert(c);
f = g_key_file_new();
g_key_file_set_list_separator(f, ',');
- if (!g_key_file_load_from_file(f, config->config_file ? config->config_file : AVAHI_CONFIG_FILE, G_KEY_FILE_NONE, &err)) {
+ if (!g_key_file_load_from_file(f, c->config_file ? c->config_file : AVAHI_CONFIG_FILE, G_KEY_FILE_NONE, &err)) {
fprintf(stderr, "Unable to read config file: %s\n", err->message);
goto finish;
}
v = g_key_file_get_value(f, *g, *k, NULL);
if (g_strcasecmp(*k, "host-name") == 0) {
- g_free(config->server_config.host_name);
- config->server_config.host_name = v;
+ g_free(c->server_config.host_name);
+ c->server_config.host_name = v;
v = NULL;
} else if (g_strcasecmp(*k, "domain-name") == 0) {
- g_free(config->server_config.domain_name);
- config->server_config.domain_name = v;
+ g_free(c->server_config.domain_name);
+ c->server_config.domain_name = v;
v = NULL;
} else if (g_strcasecmp(*k, "use-ipv4") == 0)
- config->server_config.use_ipv4 = is_yes(v);
+ c->server_config.use_ipv4 = is_yes(v);
else if (g_strcasecmp(*k, "use-ipv6") == 0)
- config->server_config.use_ipv6 = is_yes(v);
+ c->server_config.use_ipv6 = is_yes(v);
else if (g_strcasecmp(*k, "check-response-ttl") == 0)
- config->server_config.check_response_ttl = is_yes(v);
+ c->server_config.check_response_ttl = is_yes(v);
else if (g_strcasecmp(*k, "use-iff-running") == 0)
- config->server_config.use_iff_running = is_yes(v);
+ c->server_config.use_iff_running = is_yes(v);
else if (g_strcasecmp(*k, "enable-dbus") == 0)
- config->enable_dbus = is_yes(v);
+ c->enable_dbus = is_yes(v);
else if (g_strcasecmp(*k, "drop-root") == 0)
- config->drop_root = is_yes(v);
+ c->drop_root = is_yes(v);
else {
fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
goto finish;
v = g_key_file_get_string(f, *g, *k, NULL);
if (g_strcasecmp(*k, "publish-addresses") == 0)
- config->server_config.publish_addresses = is_yes(v);
+ c->server_config.publish_addresses = is_yes(v);
else if (g_strcasecmp(*k, "publish-hinfo") == 0)
- config->server_config.publish_hinfo = is_yes(v);
+ c->server_config.publish_hinfo = is_yes(v);
else if (g_strcasecmp(*k, "publish-workstation") == 0)
- config->server_config.publish_workstation = is_yes(v);
+ c->server_config.publish_workstation = is_yes(v);
else if (g_strcasecmp(*k, "publish-domain") == 0)
- config->server_config.publish_domain = is_yes(v);
+ c->server_config.publish_domain = is_yes(v);
else if (g_strcasecmp(*k, "publish-resolv-conf-dns-servers") == 0)
- config->publish_resolv_conf = is_yes(v);
+ c->publish_resolv_conf = is_yes(v);
else if (g_strcasecmp(*k, "publish-dns-servers") == 0) {
- g_strfreev(config->publish_dns_servers);
- config->publish_dns_servers = g_key_file_get_string_list(f, *g, *k, NULL, NULL);
+ g_strfreev(c->publish_dns_servers);
+ c->publish_dns_servers = g_key_file_get_string_list(f, *g, *k, NULL, NULL);
} else {
fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
goto finish;
v = g_key_file_get_string(f, *g, *k, NULL);
if (g_strcasecmp(*k, "enable-reflector") == 0)
- config->server_config.enable_reflector = is_yes(v);
+ c->server_config.enable_reflector = is_yes(v);
else if (g_strcasecmp(*k, "reflect-ipv") == 0)
- config->server_config.reflect_ipv = is_yes(v);
+ c->server_config.reflect_ipv = is_yes(v);
else {
fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
goto finish;
return TRUE;
}
-static gint run_server(DaemonConfig *config) {
+static gint run_server(DaemonConfig *c) {
GMainLoop *loop = NULL;
gint r = -1;
GIOChannel *io = NULL;
guint watch_id = (guint) -1;
- g_assert(config);
+ g_assert(c);
loop = g_main_loop_new(NULL, FALSE);
goto finish;
#ifdef ENABLE_DBUS
- if (config->enable_dbus)
+ if (c->enable_dbus)
if (dbus_protocol_setup(loop) < 0)
goto finish;
#endif
- if (!(avahi_server = avahi_server_new(NULL, &config->server_config, server_callback, config)))
+ if (!(avahi_server = avahi_server_new(NULL, &c->server_config, server_callback, c)))
goto finish;
- load_resolv_conf(config);
+ load_resolv_conf(c);
static_service_load();
- if (config->daemonize) {
+ if (c->daemonize) {
daemon_retval_send(0);
r = 0;
}
simple_protocol_shutdown();
#ifdef ENABLE_DBUS
- if (config->enable_dbus)
+ if (c->enable_dbus)
dbus_protocol_shutdown();
#endif
if (loop)
g_main_loop_unref(loop);
- if (r != 0 && config->daemonize)
+ if (r != 0 && c->daemonize)
daemon_retval_send(1);
return r;
else
argv0 = argv[0];
- daemon_pid_file_ident = daemon_log_ident = (char *) argv0;
+ daemon_pid_file_ident = (const char *) argv0;
+ daemon_log_ident = argv0;
daemon_pid_file_proc = pid_file_proc;
if (parse_command_line(&config, argc, argv) < 0)
c->poll_fd.events |= G_IO_OUT;
}
-static void client_output_printf(Client *c, gchar *format, ...) {
+static void client_output_printf(Client *c, const gchar *format, ...) {
gchar *t;
va_list ap;
#include <avahi-core/log.h>
#include "main.h"
+#include "static-services.h"
typedef struct StaticService StaticService;
typedef struct StaticServiceGroup StaticServiceGroup;
break;
ret += r;
- data = (guint8*) data + r;
+ data = (const guint8*) data + r;
size -= r;
}
run_versioned automake 1.7 -a -c --foreign
autoconf -Wall
- CFLAGS="-g -O0" ./configure --sysconfdir=/etc --localstatedir=/var "$@"
+ CFLAGS="$CFLAGS -g -O0" ./configure --sysconfdir=/etc --localstatedir=/var "$@"
make clean
fi