summaryrefslogtreecommitdiff
path: root/mdns_tinysvcmdns.c
diff options
context:
space:
mode:
authorMke Brady <mikebrady@eircom.net>2014-11-26 23:11:49 +0000
committerMke Brady <mikebrady@eircom.net>2014-11-26 23:11:49 +0000
commita730ad97ec80d6f20c902d5f0f1b19cc7c0f617b (patch)
tree35e43907b2c20f3fb82a14ce21bd771a2a957c01 /mdns_tinysvcmdns.c
parentdf88dbd8a61deea6394aa733ec0d80eed2b640e4 (diff)
Add .local to name if not already there.
Diffstat (limited to 'mdns_tinysvcmdns.c')
-rw-r--r--mdns_tinysvcmdns.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/mdns_tinysvcmdns.c b/mdns_tinysvcmdns.c
index 1dfeb90..f92d8c1 100644
--- a/mdns_tinysvcmdns.c
+++ b/mdns_tinysvcmdns.c
@@ -48,9 +48,20 @@ static int mdns_tinysvcmdns_register(char *apname, int port) {
return -1;
}
- char hostname[100];
- gethostname(hostname, 100-10); // leave a bit of space for the .local
- strcat(hostname,".local");
+ // Thanks to Paul Lietar for this
+ // room for name + .local + NULL
+ char hostname[100 + 6];
+ gethostname(hostname, 99);
+ // according to POSIX, this may be truncated without a final NULL !
+ hostname[99] = 0;
+
+ // will not work if the hostname doesn't end in .local
+ char *hostend = hostname + strlen(hostname);
+ if ((strlen(hostname) > 6) &&
+ strcmp(hostend - 6, ".local"))
+ {
+ strcat(hostname, ".local");
+ }
if (getifaddrs(&ifalist) < 0)