char *avahi_get_host_name(char *ret_s, size_t size) { assert(ret_s); assert(size > 0); if (gethostname(ret_s, size) >= 0) { ret_s[size-1] = 0; strip_bad_chars(ret_s); } else *ret_s = 0; if (strcmp(ret_s, "localhost") == 0 || strncmp(ret_s, "localhost.", 10) == 0) { *ret_s = 0; avahi_log_warn("System host name is set to 'localhost'. This is not a suitable mDNS host name, looking for alternatives."); } if (*ret_s == 0) { /* No hostname was set, so let's take the OS name */ #ifdef __linux__ /* Try LSB distribution name first */ if (load_lsb_distrib_id(ret_s, size) >= 0) { strip_bad_chars(ret_s); avahi_strdown(ret_s); } if (*ret_s == 0) #endif { /* Try uname() second */ struct utsname utsname; if (uname(&utsname) >= 0) { snprintf(ret_s, size, "%s", utsname.sysname); strip_bad_chars(ret_s); avahi_strdown(ret_s); } /* Give up */ if (*ret_s == 0) snprintf(ret_s, size, "unnamed"); } } if (size >= AVAHI_LABEL_MAX) ret_s[AVAHI_LABEL_MAX-1] = 0; return ret_s; }
char* dcc_make_dnssd_subtype(char *stype, size_t nbytes, const char *v, const char *m) { char version[64], machine[64]; strncpy(version, v, sizeof(version)-1); version[sizeof(version)-1] = 0; strncpy(machine, m, sizeof(machine)-1); machine[sizeof(machine)-1] = 0; strip_bad_chars(version); strip_bad_chars(machine); snprintf(stype, nbytes, "_%s--%s._sub." DCC_DNS_SERVICE_TYPE, machine, version); stype[nbytes-1] = 0; return stype; }