X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Falternative.c;h=77470baa405009105be92b0cb9a0db89b17f575f;hb=ceee295adb1e22818bcaf201f0135760836c5aae;hp=53a1e6c1259265d23d7b7f4a6d6cac4de557a405;hpb=e63a65b3955b173a3e8d6b78c6377a518a9922d6;p=catta diff --git a/avahi-common/alternative.c b/avahi-common/alternative.c index 53a1e6c..77470ba 100644 --- a/avahi-common/alternative.c +++ b/avahi-common/alternative.c @@ -30,23 +30,33 @@ #include "alternative.h" #include "malloc.h" -#include "util.h" char * avahi_alternative_host_name(const char *s) { - const char *p, *e; + const char *e; char *r; assert(s); - e = s; - - for (p = s; *p; p++) - if (!isdigit(*p)) - e = p+1; + e = strrchr(s, '-'); + + if (e) { + const char *p; + + for (p = e+1; *p; p++) + if (!isdigit(*p)) { + e = NULL; + break; + } + + if (e && (*(e+1) == '0' || (*(e+1) == 0))) + e = NULL; + } - if (*e) { + if (e) { char *c; + e++; + if (!(c = avahi_strndup(s, e-s))) return NULL; @@ -54,7 +64,7 @@ char * avahi_alternative_host_name(const char *s) { avahi_free(c); } else - r = avahi_strdup_printf("%s2", s); + r = avahi_strdup_printf("%s-2", s); return r; } @@ -77,6 +87,9 @@ char *avahi_alternative_service_name(const char *s) { e = NULL; break; } + + if (e && (*e == '0' || *e == 0)) + e = NULL; } if (e) {