X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fcontrol.c;h=71258b58da2361c3ee072f8ed5b6b47a6bcdf482;hb=f5223937e62e1cc5e9b3d322490dd3af8d666750;hp=76f262e2c390ae2a49266238805e9ce9886062bc;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/control.c b/src/control.c index 76f262e2..71258b58 100644 --- a/src/control.c +++ b/src/control.c @@ -159,12 +159,12 @@ bool init_control(void) { // Get the address and port of the first listening socket char *localhost = NULL; - sockaddr_t sa; + sockaddr_t sa = {0}; socklen_t len = sizeof(sa); // Make sure we have a valid address, and map 0.0.0.0 and :: to 127.0.0.1 and ::1. - if(getsockname(listen_socket[0].tcp.fd, (struct sockaddr *)&sa, &len)) { + if(getsockname(listen_socket[0].tcp.fd, &sa.sa, &len)) { xasprintf(&localhost, "127.0.0.1 port %s", myport); } else { if(sa.sa.sa_family == AF_INET) { @@ -201,6 +201,8 @@ bool init_control(void) { strncpy(sa_un.sun_path, unixsocketname, sizeof(sa_un.sun_path)); + sa_un.sun_path[sizeof(sa_un.sun_path) - 1] = 0; + if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) >= 0) { logger(DEBUG_ALWAYS, LOG_ERR, "UNIX socket %s is still in use!", unixsocketname); return false;