summaryrefslogtreecommitdiff
path: root/mdns_avahi.c
diff options
context:
space:
mode:
authorMike McKnight <mike@soundwall.com>2016-03-30 20:49:24 -0600
committerMike McKnight <mike@soundwall.com>2016-03-30 20:49:24 -0600
commit490933984e6e19d6fb8028bc3b3dbd6d37fb0f29 (patch)
tree2a82afdd065b48f382d104ea4a6dbca729d1ae6f /mdns_avahi.c
parent89f47af295722a0f7957ae709094c13aad34e073 (diff)
Fix for name collisions in avahi
Diffstat (limited to 'mdns_avahi.c')
-rw-r--r--mdns_avahi.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/mdns_avahi.c b/mdns_avahi.c
index 31800b8..c7b51c5 100644
--- a/mdns_avahi.c
+++ b/mdns_avahi.c
@@ -38,16 +38,52 @@
static AvahiClient *client = NULL;
static AvahiEntryGroup *group = NULL;
static AvahiThreadedPoll *tpoll = NULL;
+static pthread_t tpoll_id;
static char *name = NULL;
static int port = 0;
+static void register_service( AvahiClient *c );
+
static void egroup_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
AVAHI_GCC_UNUSED void *userdata) {
- if (state == AVAHI_ENTRY_GROUP_COLLISION)
- die("service name already exists on network!");
- if (state == AVAHI_ENTRY_GROUP_FAILURE)
- die("avahi entry group failure!");
+ switch ( state )
+ {
+ case AVAHI_ENTRY_GROUP_ESTABLISHED:
+ /* The entry group has been established successfully */
+ inform("Service '%s' successfully established.\n", name );
+ tpoll_id = pthread_self();
+ break;
+
+ case AVAHI_ENTRY_GROUP_COLLISION:
+ {
+ char *n;
+
+ /* A service name collision with a remote service
+ * happened. Let's pick a new name */
+ n = avahi_alternative_service_name( name );
+ avahi_free( name );
+ name = n;
+
+ warn( "Service name collision, renaming service to '%s'\n", name );
+
+ /* And recreate the services */
+ register_service( avahi_entry_group_get_client( g ) );
+ break;
+ }
+
+ case AVAHI_ENTRY_GROUP_FAILURE:
+ die( "Entry group failure: %s\n", avahi_strerror( avahi_client_errno( avahi_entry_group_get_client( g ) ) ) );
+ break;
+
+ case AVAHI_ENTRY_GROUP_UNCOMMITED:
+ debug(1, "Service '%s' group is not yet commited.\n", name );
+ break;
+
+ case AVAHI_ENTRY_GROUP_REGISTERING:
+ inform( "Service '%s' group is registering.\n", name );
+ break;
+ }
}
static void register_service(AvahiClient *c) {
@@ -98,10 +134,19 @@ static void client_callback(AvahiClient *c, AvahiClientState state,
break;
case AVAHI_CLIENT_FAILURE:
- case AVAHI_CLIENT_S_COLLISION:
die("avahi client failure");
+ break;
+
+ case AVAHI_CLIENT_S_COLLISION:
+ warn( "Avahi state is AVAHI_CLIENT_S_COLLISION...would have killed the service: %s\n", name );
+ break;
case AVAHI_CLIENT_CONNECTING:
+ inform( "Received AVAHI_CLIENT_CONNECTING\n" );
+ break;
+
+ default:
+ warn( "Unhandled avahi state: %d\n", state );
break;
}
}