When generating invitations, handle any order of Port and Adress statements.

This commit is contained in:
Guus Sliepen 2013-08-28 14:24:07 +02:00
parent f0e11cd2c5
commit 5da0ebd421

View file

@ -35,18 +35,14 @@
int addressfamily = AF_UNSPEC; int addressfamily = AF_UNSPEC;
char *get_my_hostname() { static void scan_for_hostname(const char *filename, char **hostname, char **port) {
char *hostname = NULL; if(!filename || (*hostname && *port))
char *port = NULL; return;
char *hostport = NULL;
char *name = get_my_name(false);
char *filename = NULL;
// Use first Address statement in own host config file
if(check_id(name)) {
xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "r");
if(f) { if(!f)
return;
while(fgets(line, sizeof line, f)) { while(fgets(line, sizeof line, f)) {
if(!rstrip(line)) if(!rstrip(line))
continue; continue;
@ -63,21 +59,36 @@ char *get_my_hostname() {
*p++ = 0; *p++ = 0;
p += strspn(p, "\t "); p += strspn(p, "\t ");
p[strcspn(p, "\t ")] = 0; p[strcspn(p, "\t ")] = 0;
if(!port && !strcasecmp(line, "Port")) {
port = xstrdup(q); if(!*port && !strcasecmp(line, "Port")) {
continue; *port = xstrdup(q);
} } else if(!*hostname && !strcasecmp(line, "Address")) {
if(strcasecmp(line, "Address")) *hostname = xstrdup(q);
continue;
hostname = xstrdup(q);
if(*p) { if(*p) {
free(port); free(*port);
port = xstrdup(p); *port = xstrdup(p);
} }
}
if(*hostname && *port)
break; break;
} }
fclose(f); fclose(f);
} }
char *get_my_hostname() {
char *hostname = NULL;
char *port = NULL;
char *hostport = NULL;
char *name = get_my_name(false);
char *filename = NULL;
// Use first Address statement in own host config file
if(check_id(name)) {
xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
scan_for_hostname(filename, &hostname, &port);
scan_for_hostname(tinc_conf, &hostname, &port);
} }
if(hostname) if(hostname)