Normally the appname is used as the service name as well. However,
Catta's rules are that the service name must be at least two characters,
and only contain alphanumeric characters, dashses and underscores.
catta_set_log_function(discovery_log_cb);
// create service type string
catta_set_log_function(discovery_log_cb);
// create service type string
- size_t servicetype_strlen = sizeof(MESHLINK_MDNS_SERVICE_TYPE) + strlen(mesh->appname) + 1;
+ char appname[strlen(mesh->appname) + 2];
+ strcpy(appname, mesh->appname);
+
+ for(char *p = appname; *p; p++) {
+ if(!isalnum(*p) && *p != '_' && *p != '-') {
+ *p = '_';
+ }
+ }
+
+ if(!appname[1]) {
+ appname[1] = '_';
+ appname[2] = '\0';
+ }
+
+ size_t servicetype_strlen = sizeof(MESHLINK_MDNS_SERVICE_TYPE) + strlen(appname) + 1;
mesh->catta_servicetype = malloc(servicetype_strlen);
if(mesh->catta_servicetype == NULL) {
mesh->catta_servicetype = malloc(servicetype_strlen);
if(mesh->catta_servicetype == NULL) {
- snprintf(mesh->catta_servicetype, servicetype_strlen, MESHLINK_MDNS_SERVICE_TYPE, mesh->appname);
+ snprintf(mesh->catta_servicetype, servicetype_strlen, MESHLINK_MDNS_SERVICE_TYPE, appname);
// Allocate discovery loop object
if(!(mesh->catta_poll = catta_simple_poll_new())) {
// Allocate discovery loop object
if(!(mesh->catta_poll = catta_simple_poll_new())) {