/*
tincctl.c -- Controlling a running tincd
- Copyright (C) 2007-2009 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2007-2011 Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "control_common.h"
#include "rsagen.h"
#include "utils.h"
+#include "tincctl.h"
+#include "top.h"
/* The name this program was run with. */
char *program_name = NULL;
{"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}
};
" 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"
+#ifdef HAVE_CURSES
+ " top Show real-time statistics\n"
+#endif
"\n");
printf("Report bugs to tinc@tinc-vpn.org.\n");
}
#endif
if(!controlcookiename)
- xasprintf(&controlcookiename, "%s/run/%s.control/socket", LOCALSTATEDIR, identname);
+ xasprintf(&controlcookiename, "%s/run/%s.cookie", LOCALSTATEDIR, identname);
if(netname) {
if(!confbase)
}
}
-static bool recvline(int fd, char *line, size_t len) {
+bool recvline(int fd, char *line, size_t len) {
static char buffer[4096];
static size_t blen = 0;
char *newline = NULL;
return true;
}
-static bool sendline(int fd, char *format, ...) {
+bool sendline(int fd, char *format, ...) {
static char buffer[4096];
char *p = buffer;
size_t blen = 0;
return 1;
}
+#ifdef HAVE_MINGW
unsigned long arg = 0;
if(ioctlsocket(fd, FIONBIO, &arg) != 0) {
fprintf(stderr, "ioctlsocket failed: %s", sockstrerror(sockerrno));
}
+#endif
if(connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0) {
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;
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;
}
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;
+ }
+
+#ifdef HAVE_CURSES
+ if(!strcasecmp(argv[optind], "top")) {
+ top(fd);
+ return 0;
+ }
+#endif
+
fprintf(stderr, "Unknown command `%s'.\n", argv[optind]);
usage(true);