X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=632e7ac6efa8720197e7623b69b429087c49f528;hb=708825e4b229a4a1e182e682e2d1021fa2765396;hp=2d2e2f25431d903bc53a2d1a7bd302312daf98ad;hpb=fec14791e869180bb7994ca38ca7006cc2e957fb;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index 2d2e2f25..632e7ac6 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -58,7 +58,7 @@ static struct option const long_options[] = { {"net", required_argument, NULL, 'n'}, {"help", no_argument, NULL, 1}, {"version", no_argument, NULL, 2}, - {"controlsocket", required_argument, NULL, 5}, + {"controlcookie", required_argument, NULL, 5}, {NULL, 0, NULL, 0} }; @@ -92,6 +92,7 @@ static void usage(bool status) { " debug N Set debug level\n" " retry Retry all outgoing connections\n" " reload Partial reload of configuration\n" + " disconnect NODE Close meta connection with NODE\n" "\n"); printf("Report bugs to tinc@tinc-vpn.org.\n"); } @@ -282,7 +283,7 @@ static void make_names(void) { #endif if(!controlcookiename) - xasprintf(&controlcookiename, "%s/run/%s.control/socket", LOCALSTATEDIR, identname); + xasprintf(&controlcookiename, "%s/run/%s.cookie", LOCALSTATEDIR, identname); if(netname) { if(!confbase) @@ -540,7 +541,7 @@ int main(int argc, char *argv[], char *envp[]) { while(recvline(fd, line, sizeof line)) { char node1[4096], node2[4096]; - int n = sscanf(line, "%d %d %s to %s", &code, &req, &node1, &node2); + int n = sscanf(line, "%d %d %s to %s", &code, &req, node1, node2); if(n == 2) { if(do_graph && req == REQ_DUMP_NODES) continue; @@ -586,7 +587,7 @@ int main(int argc, char *argv[], char *envp[]) { debuglevel = atoi(argv[optind+1]); sendline(fd, "%d %d %d", CONTROL, REQ_SET_DEBUG, debuglevel); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_SET_DEBUG) { + if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &origlevel) != 3 || code != CONTROL || req != REQ_SET_DEBUG) { fprintf(stderr, "Could not purge tinc daemon\n"); return 1; } @@ -595,6 +596,36 @@ int main(int argc, char *argv[], char *envp[]) { return 0; } + if(!strcasecmp(argv[optind], "connect")) { + if(argc != optind + 2) { + fprintf(stderr, "Invalid arguments.\n"); + return 1; + } + char *name = argv[optind + 1]; + + sendline(fd, "%d %d %s", CONTROL, REQ_CONNECT, name); + if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_CONNECT || result) { + fprintf(stderr, "Could not connect to %s\n", name); + return 1; + } + return 0; + } + + if(!strcasecmp(argv[optind], "disconnect")) { + if(argc != optind + 2) { + fprintf(stderr, "Invalid arguments.\n"); + return 1; + } + char *name = argv[optind + 1]; + + sendline(fd, "%d %d %s", CONTROL, REQ_DISCONNECT, name); + if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_DISCONNECT || result) { + fprintf(stderr, "Could not disconnect %s\n", name); + return 1; + } + return 0; + } + fprintf(stderr, "Unknown command `%s'.\n", argv[optind]); usage(true);