assert(mesh->avahi_server != NULL);
assert(mesh->avahi_poll != NULL);
assert(mesh->avahi_servicetype != NULL);
+ assert(mesh->self != NULL);
fprintf(stderr, "Adding service\n");
/* Create txt records */
size_t txt_name_len = sizeof(MESHLINK_MDNS_NAME_KEY) + 1 + strlen(mesh->name) + 1;
txt_name = malloc(txt_name_len);
+
+ if(txt_name == NULL)
+ {
+ fprintf(stderr, "Could not allocate memory for TXT record\n");
+ goto fail;
+ }
+
snprintf(txt_name, txt_name_len, "%s=%s", MESHLINK_MDNS_NAME_KEY, mesh->name);
char txt_fingerprint[sizeof(MESHLINK_MDNS_FINGERPRINT_KEY) + 1 + MESHLINK_FINGERPRINTLEN + 1];
snprintf(txt_fingerprint, sizeof(txt_fingerprint), "%s=%s", MESHLINK_MDNS_FINGERPRINT_KEY, meshlink_get_fingerprint(mesh, (meshlink_node_t *)mesh->self));
- // Generate a name for the service (actually we do not care)
- uuid_t srvname;
- uuid_generate(srvname);
-
- char srvnamestr[36+1];
- uuid_unparse_lower(srvname, srvnamestr);
-
/* Add the service */
int ret = 0;
- if((ret = avahi_server_add_service(mesh->avahi_server, mesh->avahi_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, srvnamestr, mesh->avahi_servicetype, NULL, NULL, atoi(mesh->myport), txt_name, txt_fingerprint, NULL)) < 0)
+ if((ret = avahi_server_add_service(mesh->avahi_server, mesh->avahi_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, meshlink_get_fingerprint(mesh, (meshlink_node_t *)mesh->self), mesh->avahi_servicetype, NULL, NULL, atoi(mesh->myport), txt_name, txt_fingerprint, NULL)) < 0)
{
fprintf(stderr, "Failed to add service: %s\n", avahi_strerror(ret));
goto fail;
done:
if(txt_name)
- free(txt_name);
+ { free(txt_name); }
}
static void discovery_server_callback(AvahiServer *server, AvahiServerState state, void * userdata)