summaryrefslogtreecommitdiffstats
path: root/avahi-core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-06-03 16:11:07 +0000
committerLennart Poettering <lennart@poettering.net>2005-06-03 16:11:07 +0000
commit8d361c07a55685f6eee5209b30f46c392549ba42 (patch)
treeb200dc9c877f77e90edb9580d6c55d898eebfcbb /avahi-core
parent4ff0807c04fcc239de52a793bceb88e7f3408f3f (diff)
* add support for _workstation._tcp
* really fix #3455 git-svn-id: file:///home/lennart/svn/public/avahi/trunk@93 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core')
-rw-r--r--avahi-core/avahi-reflector.c2
-rw-r--r--avahi-core/avahi-test.c2
-rw-r--r--avahi-core/core.h1
-rw-r--r--avahi-core/iface.c56
-rw-r--r--avahi-core/iface.h7
-rw-r--r--avahi-core/rr.c10
-rw-r--r--avahi-core/server.c1
-rw-r--r--avahi-core/util.c23
-rw-r--r--avahi-core/util.h2
9 files changed, 95 insertions, 9 deletions
diff --git a/avahi-core/avahi-reflector.c b/avahi-core/avahi-reflector.c
index 0079afc..e10c43c 100644
--- a/avahi-core/avahi-reflector.c
+++ b/avahi-core/avahi-reflector.c
@@ -36,10 +36,10 @@ int main(int argc, char*argv[]) {
AvahiServerConfig config;
GMainLoop *loop;
-
avahi_server_config_init(&config);
config.register_hinfo = FALSE;
config.register_addresses = FALSE;
+ config.register_workstation = FALSE;
config.announce_domain = FALSE;
config.use_ipv6 = FALSE;
config.enable_reflector = TRUE;
diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c
index 48db6d7..269b64c 100644
--- a/avahi-core/avahi-test.c
+++ b/avahi-core/avahi-test.c
@@ -205,7 +205,7 @@ int main(int argc, char *argv[]) {
loop = g_main_loop_new(NULL, FALSE);
-/* g_timeout_add(1000*5, dump_timeout, server); */
+ g_timeout_add(1000*5, dump_timeout, server);
g_timeout_add(1000*30, quit_timeout, loop);
g_main_loop_run(loop);
diff --git a/avahi-core/core.h b/avahi-core/core.h
index 9e2f66b..0a744f3 100644
--- a/avahi-core/core.h
+++ b/avahi-core/core.h
@@ -76,6 +76,7 @@ typedef struct AvahiServerConfig {
gboolean use_ipv6; /**< Enable IPv6 support */
gboolean register_hinfo; /**< Register a HINFO record for the host containing the local OS and CPU type */
gboolean register_addresses; /**< Register A, AAAA and PTR records for all local IP addresses */
+ gboolean register_workstation; /**< Register a _workstation._tcp service */
gboolean check_response_ttl; /**< If enabled the server ignores all incoming responses with IP TTL != 255 */
gboolean announce_domain; /**< Announce the local domain for browsing */
gboolean use_iff_running; /**< Require IFF_RUNNING on local network interfaces. This is the official way to check for link beat. Unfortunately this doesn't work with all drivers. So bettere leave this off. */
diff --git a/avahi-core/iface.c b/avahi-core/iface.c
index d74a96d..8686fb5 100644
--- a/avahi-core/iface.c
+++ b/avahi-core/iface.c
@@ -36,6 +36,7 @@
#include "dns.h"
#include "socket.h"
#include "announce.h"
+#include "util.h"
static void update_address_rr(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a, gboolean remove) {
g_assert(m);
@@ -83,6 +84,36 @@ static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *h
for (i = hw->interfaces; i; i = i->by_hardware_next)
update_interface_rr(m, i, remove);
+
+ if (!remove &&
+ m->server->config.register_workstation &&
+ (m->server->state == AVAHI_SERVER_RUNNING ||
+ m->server->state == AVAHI_SERVER_REGISTERING)) {
+
+ if (!hw->entry_group) {
+ gchar *name;
+ gchar *t = avahi_format_mac_address(hw->mac_address, hw->mac_address_size);
+ name = g_strdup_printf("%s [%s]", m->server->host_name, t);
+ g_free(t);
+
+ hw->entry_group = avahi_entry_group_new(m->server, avahi_host_rr_entry_group_callback, NULL);
+ avahi_server_add_service(m->server, hw->entry_group, hw->index, AF_UNSPEC, "_workstation._tcp", name, NULL, NULL, 9, NULL);
+ avahi_entry_group_commit(hw->entry_group);
+
+ g_free(name);
+ }
+
+ } else {
+
+ if (hw->entry_group) {
+
+ if (avahi_entry_group_get_state(hw->entry_group) == AVAHI_ENTRY_GROUP_REGISTERING)
+ avahi_server_decrease_host_rr_pending(m->server);
+
+ avahi_entry_group_free(hw->entry_group);
+ hw->entry_group = NULL;
+ }
+ }
}
static void free_address(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a) {
@@ -90,10 +121,8 @@ static void free_address(AvahiInterfaceMonitor *m, AvahiInterfaceAddress *a) {
g_assert(a);
g_assert(a->interface);
+ update_address_rr(m, a, TRUE);
AVAHI_LLIST_REMOVE(AvahiInterfaceAddress, address, a->interface->addresses, a);
-
- if (a->entry_group)
- avahi_entry_group_free(a->entry_group);
g_free(a);
}
@@ -107,6 +136,8 @@ static void free_interface(AvahiInterfaceMonitor *m, AvahiInterface *i, gboolean
g_assert(!i->announcements);
+ update_interface_rr(m, i, TRUE);
+
while (i->addresses)
free_address(m, i->addresses);
@@ -125,6 +156,8 @@ static void free_hw_interface(AvahiInterfaceMonitor *m, AvahiHwInterface *hw, gb
g_assert(m);
g_assert(hw);
+ update_hw_interface_rr(m, hw, TRUE);
+
while (hw->interfaces)
free_interface(m, hw->interfaces, send_goodbye);
@@ -262,6 +295,8 @@ static void callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata) {
hw->flags = 0;
hw->mtu = 1500;
hw->index = ifinfomsg->ifi_index;
+ hw->mac_address_size = 0;
+ hw->entry_group = NULL;
AVAHI_LLIST_HEAD_INIT(AvahiInterface, hw->interfaces);
AVAHI_LLIST_PREPEND(AvahiHwInterface, hardware, m->hw_interfaces, hw);
@@ -290,6 +325,15 @@ static void callback(AvahiNetlink *nl, struct nlmsghdr *n, gpointer userdata) {
g_assert(RTA_PAYLOAD(a) == sizeof(unsigned int));
hw->mtu = *((unsigned int*) RTA_DATA(a));
break;
+
+ case IFLA_ADDRESS: {
+ hw->mac_address_size = RTA_PAYLOAD(a);
+ if (hw->mac_address_size > AVAHI_MAX_MAC_ADDRESS)
+ hw->mac_address_size = AVAHI_MAX_MAC_ADDRESS;
+
+ memcpy(hw->mac_address, RTA_DATA(a), hw->mac_address_size);
+ break;
+ }
default:
;
@@ -639,12 +683,12 @@ void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, gint interface, guch
}
void avahi_update_host_rrs(AvahiInterfaceMonitor *m, gboolean remove) {
- AvahiInterface *i;
+ AvahiHwInterface *hw;
g_assert(m);
- for (i = m->interfaces; i; i = i->interface_next)
- update_interface_rr(m, i, remove);
+ for (hw = m->hw_interfaces; hw; hw = hw->hardware_next)
+ update_hw_interface_rr(m, hw, remove);
}
gboolean avahi_address_is_local(AvahiInterfaceMonitor *m, const AvahiAddress *a) {
diff --git a/avahi-core/iface.h b/avahi-core/iface.h
index 50c130e..1372e6f 100644
--- a/avahi-core/iface.h
+++ b/avahi-core/iface.h
@@ -40,6 +40,8 @@ typedef struct AvahiHwInterface AvahiHwInterface;
#include "dns.h"
#include "announce.h"
+#define AVAHI_MAX_MAC_ADDRESS 32
+
struct AvahiInterfaceMonitor {
AvahiServer *server;
AvahiNetlink *netlink;
@@ -66,6 +68,11 @@ struct AvahiHwInterface {
guint flags;
guint mtu;
+ guint8 mac_address[AVAHI_MAX_MAC_ADDRESS];
+ guint mac_address_size;
+
+ AvahiEntryGroup *entry_group;
+
AVAHI_LLIST_HEAD(AvahiInterface, interfaces);
};
diff --git a/avahi-core/rr.c b/avahi-core/rr.c
index f3db584..cb2b8af 100644
--- a/avahi-core/rr.c
+++ b/avahi-core/rr.c
@@ -516,7 +516,15 @@ gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) {
avahi_string_list_serialize(a->data.txt.string_list, ma, asize);
avahi_string_list_serialize(b->data.txt.string_list, mb, bsize);
- r = lexicographical_memcmp(ma, asize, mb, bsize);
+ if (asize && bsize)
+ r = lexicographical_memcmp(ma, asize, mb, bsize);
+ else if (asize && !bsize)
+ r = 1;
+ else if (!asize && bsize)
+ r = -1;
+ else
+ r = 0;
+
g_free(ma);
g_free(mb);
diff --git a/avahi-core/server.c b/avahi-core/server.c
index 3ccaddc..7ba2a74 100644
--- a/avahi-core/server.c
+++ b/avahi-core/server.c
@@ -1856,6 +1856,7 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) {
c->use_iff_running = FALSE;
c->enable_reflector = FALSE;
c->ipv_reflect = FALSE;
+ c->register_workstation = TRUE;
return c;
}
diff --git a/avahi-core/util.c b/avahi-core/util.c
index b186817..a41475a 100644
--- a/avahi-core/util.c
+++ b/avahi-core/util.c
@@ -403,3 +403,26 @@ guint avahi_domain_hash(const gchar *s) {
}
}
+gchar *avahi_format_mac_address(const guint8* mac, guint size) {
+ gchar *r, *t;
+ guint i;
+ static const gchar hex[] = "0123456789abcdef";
+
+ t = r = g_new(gchar, size > 0 ? size*3 : 1);
+
+ if (size <= 0) {
+ *r = 0;
+ return r;
+ }
+
+ for (i = 0; i < size; i++) {
+ *(t++) = hex[*mac >> 4];
+ *(t++) = hex[*mac & 0xF];
+ *(t++) = ':';
+
+ mac++;
+ }
+
+ *(--t) = 0;
+ return r;
+}
diff --git a/avahi-core/util.h b/avahi-core/util.h
index ef87f5f..68d367c 100644
--- a/avahi-core/util.h
+++ b/avahi-core/util.h
@@ -52,4 +52,6 @@ gchar *avahi_escape_label(const guint8* src, guint src_length, gchar **ret_name,
guint avahi_domain_hash(const gchar *s);
+gchar *avahi_format_mac_address(const guint8* mac, guint size);
+
#endif