diff options
Diffstat (limited to 'avahi-core/util.c')
-rw-r--r-- | avahi-core/util.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/avahi-core/util.c b/avahi-core/util.c index 086c041..9b84d12 100644 --- a/avahi-core/util.c +++ b/avahi-core/util.c @@ -29,6 +29,8 @@ #include <errno.h> #include <limits.h> #include <stdio.h> +#include <ctype.h> +#include <stdlib.h> #include "util.h" @@ -401,3 +403,55 @@ gint avahi_domain_hash(const gchar *s) { g_free(n); } } + + +gchar * avahi_alternative_host_name(const gchar *s) { + const gchar *p, *e = NULL; + gchar *c, *r; + gint n; + + g_assert(s); + + for (p = s; *p; p++) + if (!isdigit(*p)) + e = p+1; + + if (e && *e) + n = atoi(e)+1; + else + n = 2; + + c = e ? g_strndup(s, e-s) : g_strdup(s); + r = g_strdup_printf("%s%i", c, n); + g_free(c); + + return r; + +} + +gchar *avahi_alternative_service_name(const gchar *s) { + const gchar *e; + g_assert(s); + + if ((e = strstr(s, " #"))) { + const gchar *n, *p; + e += 2; + + while ((n = strstr(e, " #"))) + e = n + 2; + + for (p = e; *p; p++) + if (!isdigit(*p)) { + e = NULL; + break; + } + } + + if (e) { + gchar *r, *c = g_strndup(s, e-s); + r = g_strdup_printf("%s%i", c, atoi(e)+1); + g_free(c); + return r; + } else + return g_strdup_printf("%s #2", s); +} |