]> git.meshlink.io Git - catta/commitdiff
* add support for _workstation._tcp
authorLennart Poettering <lennart@poettering.net>
Fri, 3 Jun 2005 16:11:07 +0000 (16:11 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Jun 2005 16:11:07 +0000 (16:11 +0000)
* really fix #3455

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@93 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/avahi-reflector.c
avahi-core/avahi-test.c
avahi-core/core.h
avahi-core/iface.c
avahi-core/iface.h
avahi-core/rr.c
avahi-core/server.c
avahi-core/util.c
avahi-core/util.h
avahi-discover/main.c

index 0079afc04e25f372fc4bbdc7b165e859496bceb2..e10c43c6419707d502c674604fbd9928d2df8abe 100644 (file)
@@ -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;
index 48db6d7ca9fcea496f0ffc4e2274da62a5008554..269b64c60df64df5ea3348a8010759ce42e3b4b7 100644 (file)
@@ -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);
index 9e2f66b89cb980df7d0e5f03f5d8723a49b3dda2..0a744f349c7950b953587b8fda59ad2cbcb8a08d 100644 (file)
@@ -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. */
index d74a96d7b2eb030658aa1ec496b53141f9590156..8686fb551054f62328f18c94e3e9007304eef500 100644 (file)
@@ -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) {
index 50c130e74c22c8bf3b009c4dea32651ac59af69e..1372e6fd137ffcf7d13e3b42bd217813325590ae 100644 (file)
@@ -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);
 };
 
index f3db5845d539e8fc6067e5c4e1036d02525b71d8..cb2b8af0529eb570bafcf434c85f048e5bf0aeb5 100644 (file)
@@ -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);
 
index 3ccaddc15c9208fec38dd6c7e64ee7ba8b5eac53..7ba2a7420cb8b8503659add32667344d155cced1 100644 (file)
@@ -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;
 }
index b18681761112bb6fe5b20ad8f71065b35495bb75..a41475a3b7242d11ef9eb7fa67423fd01cad8bad 100644 (file)
@@ -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;
+}
index ef87f5f5a45f8e1b9531739f9728039c868bf6c8..68d367cebbb5b04b9cb5775066ec2786f09964cb 100644 (file)
@@ -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
index 2f702a726ab7874dc8209ca16a5814512ff75fcd..557806e26da6464cb9bae007bca2e6d4eaf7dc8f 100644 (file)
@@ -105,8 +105,6 @@ static void service_browser_callback(AvahiServiceBrowser *b, gint interface, guc
         s->protocol = protocol;
         s->service_type = g_hash_table_lookup(service_type_hash_table, service_type);
         g_assert(s->service_type);
-
-
         
         s->service_type->services = g_list_prepend(s->service_type->services, s);
 
@@ -267,7 +265,7 @@ int main(int argc, char *argv[]) {
     service_type_hash_table = g_hash_table_new((GHashFunc) avahi_domain_hash, (GEqualFunc) avahi_domain_equal);
     
     avahi_server_config_init(&config);
-    config.register_hinfo = config.register_addresses = config.announce_domain = FALSE;
+    config.register_hinfo = config.register_addresses = config.announce_domain = config.register_workstation = FALSE;
     server = avahi_server_new(NULL, &config, NULL, NULL);
     avahi_server_config_free(&config);