From e8edcf439d2ce1593af11c357893681b6b3c0bb4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Sep 2005 00:22:30 +0000 Subject: * add magic identification cookies to service TXT records automatically * add an API to query the local service cookie * add a DBUS interface to query the local service cookie * wrap that in avahi-client git-svn-id: file:///home/lennart/svn/public/avahi/trunk@555 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/core.h | 4 ++++ avahi-core/server.c | 29 +++++++++++++++++++++++++++++ avahi-core/server.h | 2 ++ 3 files changed, 35 insertions(+) (limited to 'avahi-core') diff --git a/avahi-core/core.h b/avahi-core/core.h index 1cf35fc..427a09a 100644 --- a/avahi-core/core.h +++ b/avahi-core/core.h @@ -85,6 +85,7 @@ typedef struct AvahiServerConfig { int 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. */ int enable_reflector; /**< Reflect incoming mDNS traffic to all local networks. This allows mDNS based network browsing beyond ethernet borders */ int reflect_ipv; /**< if enable_reflector is 1, enable/disable reflecting between IPv4 and IPv6 */ + int add_service_cookie; /**< Add magic service cookie to all locally generated records implicitly */ } AvahiServerConfig; /** Allocate a new mDNS responder object. */ @@ -564,6 +565,9 @@ void avahi_s_dns_server_browser_free(AvahiSDNSServerBrowser *b); /** Return the last error code */ int avahi_server_errno(AvahiServer *s); +/** Return the local service cookie */ +uint32_t avahi_server_get_local_service_cookie(AvahiServer *s); + #ifndef DOXYGEN_SHOULD_SKIP_THIS AVAHI_C_DECL_END #endif diff --git a/avahi-core/server.c b/avahi-core/server.c index 66cc705..625af50 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -1411,6 +1412,10 @@ AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig s->legacy_unicast_reflect_slots = NULL; s->legacy_unicast_reflect_id = 0; + + do { + s->local_service_cookie = (uint32_t) rand() * (uint32_t) rand(); + } while (s->local_service_cookie == AVAHI_SERVICE_COOKIE_INVALID); /* Get host name */ s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name(); @@ -1849,6 +1854,22 @@ static void escape_service_name(char *d, size_t size, const char *s) { *(d++) = 0; } +static AvahiStringList *add_magic_cookie( + AvahiServer *s, + AvahiStringList *strlst) { + + assert(s); + + if (!s->config.add_service_cookie) + return strlst; + + if (avahi_string_list_find(strlst, AVAHI_SERVICE_COOKIE)) + /* This string list already contains a magic cookie */ + return strlst; + + return avahi_string_list_add_printf(strlst, AVAHI_SERVICE_COOKIE"=%u", s->local_service_cookie); +} + static int server_add_service_strlst_nocopy( AvahiServer *s, AvahiSEntryGroup *g, @@ -1919,6 +1940,8 @@ static int server_add_service_strlst_nocopy( if (ret < 0) goto fail; + strlst = add_magic_cookie(s, strlst); + ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst); strlst = NULL; @@ -2389,6 +2412,7 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) { c->use_iff_running = 0; c->enable_reflector = 0; c->reflect_ipv = 0; + c->add_service_cookie = 1; return c; } @@ -2435,3 +2459,8 @@ int avahi_server_set_errno(AvahiServer *s, int error) { return s->error = error; } +uint32_t avahi_server_get_local_service_cookie(AvahiServer *s) { + assert(s); + + return s->local_service_cookie; +} diff --git a/avahi-core/server.h b/avahi-core/server.h index 6ceab42..7384e98 100644 --- a/avahi-core/server.h +++ b/avahi-core/server.h @@ -139,6 +139,8 @@ struct AvahiServer { uint16_t legacy_unicast_reflect_id; int error; + + uint32_t local_service_cookie; }; int avahi_server_entry_match_interface(AvahiEntry *e, AvahiInterface *i); -- cgit