When generating invitations, handle any order of Port and Adress statements.
This commit is contained in:
parent
f0e11cd2c5
commit
5da0ebd421
1 changed files with 44 additions and 33 deletions
|
@ -35,18 +35,14 @@
|
|||
|
||||
int addressfamily = AF_UNSPEC;
|
||||
|
||||
char *get_my_hostname() {
|
||||
char *hostname = NULL;
|
||||
char *port = NULL;
|
||||
char *hostport = NULL;
|
||||
char *name = get_my_name(false);
|
||||
char *filename = NULL;
|
||||
static void scan_for_hostname(const char *filename, char **hostname, char **port) {
|
||||
if(!filename || (*hostname && *port))
|
||||
return;
|
||||
|
||||
// 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");
|
||||
if(f) {
|
||||
if(!f)
|
||||
return;
|
||||
|
||||
while(fgets(line, sizeof line, f)) {
|
||||
if(!rstrip(line))
|
||||
continue;
|
||||
|
@ -63,21 +59,36 @@ char *get_my_hostname() {
|
|||
*p++ = 0;
|
||||
p += strspn(p, "\t ");
|
||||
p[strcspn(p, "\t ")] = 0;
|
||||
if(!port && !strcasecmp(line, "Port")) {
|
||||
port = xstrdup(q);
|
||||
continue;
|
||||
}
|
||||
if(strcasecmp(line, "Address"))
|
||||
continue;
|
||||
hostname = xstrdup(q);
|
||||
|
||||
if(!*port && !strcasecmp(line, "Port")) {
|
||||
*port = xstrdup(q);
|
||||
} else if(!*hostname && !strcasecmp(line, "Address")) {
|
||||
*hostname = xstrdup(q);
|
||||
if(*p) {
|
||||
free(port);
|
||||
port = xstrdup(p);
|
||||
free(*port);
|
||||
*port = xstrdup(p);
|
||||
}
|
||||
}
|
||||
|
||||
if(*hostname && *port)
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue