projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add upnp.h to tincd SOURCES.
[tinc]
/
src
/
tincctl.c
diff --git
a/src/tincctl.c
b/src/tincctl.c
index
c9d8c67
..
6c54eff
100644
(file)
--- a/
src/tincctl.c
+++ b/
src/tincctl.c
@@
-233,6
+233,12
@@
FILE *fopenmask(const char *filename, const char *mode, mode_t perms) {
perms &= ~mask;
umask(~perms);
FILE *f = fopen(filename, mode);
perms &= ~mask;
umask(~perms);
FILE *f = fopen(filename, mode);
+
+ if(!f) {
+ fprintf(stderr, "Could not open %s: %s\n", filename, strerror(errno));
+ return NULL;
+ }
+
#ifdef HAVE_FCHMOD
if((perms & 0444) && f)
fchmod(fileno(f), perms);
#ifdef HAVE_FCHMOD
if((perms & 0444) && f)
fchmod(fileno(f), perms);
@@
-411,6
+417,7
@@
static bool ed25519_keygen(bool ask) {
char *pubkey = ecdsa_get_base64_public_key(key);
fprintf(f, "Ed25519PublicKey = %s\n", pubkey);
char *pubkey = ecdsa_get_base64_public_key(key);
fprintf(f, "Ed25519PublicKey = %s\n", pubkey);
+ free(pubkey);
fclose(f);
ecdsa_free(key);
fclose(f);
ecdsa_free(key);
@@
-1474,6
+1481,9
@@
const var_t variables[] = {
{"UDPInfoInterval", VAR_SERVER},
{"UDPRcvBuf", VAR_SERVER},
{"UDPSndBuf", VAR_SERVER},
{"UDPInfoInterval", VAR_SERVER},
{"UDPRcvBuf", VAR_SERVER},
{"UDPSndBuf", VAR_SERVER},
+ {"UPnP", VAR_SERVER},
+ {"UPnPDiscoverWait", VAR_SERVER},
+ {"UPnPRefreshPeriod", VAR_SERVER},
{"VDEGroup", VAR_SERVER},
{"VDEPort", VAR_SERVER},
/* Host configuration */
{"VDEGroup", VAR_SERVER},
{"VDEPort", VAR_SERVER},
/* Host configuration */
@@
-1798,7
+1808,7
@@
static int cmd_config(int argc, char *argv[]) {
}
static bool try_bind(int port) {
}
static bool try_bind(int port) {
- struct addrinfo *ai = NULL;
+ struct addrinfo *ai = NULL
, *aip
;
struct addrinfo hint = {
.ai_flags = AI_PASSIVE,
.ai_family = AF_UNSPEC,
struct addrinfo hint = {
.ai_flags = AI_PASSIVE,
.ai_family = AF_UNSPEC,
@@
-1806,24
+1816,30
@@
static bool try_bind(int port) {
.ai_protocol = IPPROTO_TCP,
};
.ai_protocol = IPPROTO_TCP,
};
+ bool success = true;
char portstr[16];
snprintf(portstr, sizeof portstr, "%d", port);
if(getaddrinfo(NULL, portstr, &hint, &ai) || !ai)
return false;
char portstr[16];
snprintf(portstr, sizeof portstr, "%d", port);
if(getaddrinfo(NULL, portstr, &hint, &ai) || !ai)
return false;
-
while(ai
) {
+
for(aip = ai; aip; aip = aip->ai_next
) {
int fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
int fd = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
- if(!fd)
- return false;
+ if(!fd) {
+ success = false;
+ break;
+ }
+
int result = bind(fd, ai->ai_addr, ai->ai_addrlen);
closesocket(fd);
int result = bind(fd, ai->ai_addr, ai->ai_addrlen);
closesocket(fd);
- if(result)
- return false;
- ai = ai->ai_next;
+ if(result) {
+ success = false;
+ break;
+ }
}
}
- return true;
+ freeaddrinfo(ai);
+ return success;
}
int check_port(char *name) {
}
int check_port(char *name) {