+ if ((e = strrchr(s, '-'))) {
+ const char *p;
+
+ e++;
+
+ for (p = e; *p; p++)
+ if (!isdigit(*p)) {
+ e = NULL;
+ break;
+ }
+
+ if (e && (*e == '0' || *e == 0))
+ e = NULL;
+ }
+
+ if (e) {
+ char *c, *m;
+ size_t l;
+ int n;
+
+ n = atoi(e)+1;
+ if (!(m = avahi_strdup_printf("%i", n)))
+ return NULL;
+
+ l = e-s-1;
+
+ if (l >= AVAHI_LABEL_MAX-1-strlen(m)-1)
+ l = AVAHI_LABEL_MAX-1-strlen(m)-1;
+
+ if (!(c = avahi_strndup(s, l))) {
+ avahi_free(m);
+ return NULL;
+ }
+
+ drop_incomplete_utf8(c);
+
+ r = avahi_strdup_printf("%s-%s", c, m);
+ avahi_free(c);
+ avahi_free(m);
+
+ } else {
+ char *c;
+
+ if (!(c = avahi_strndup(s, AVAHI_LABEL_MAX-1-2)))
+ return NULL;
+
+ drop_incomplete_utf8(c);
+
+ r = avahi_strdup_printf("%s-2", c);
+ avahi_free(c);
+ }
+
+ assert(avahi_is_valid_host_name(r));
+