Add a command to list all tunnels
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
@@ -68,6 +68,7 @@ void gt_set_port (struct sockaddr *, uint16_t);
|
|||||||
uint16_t gt_get_port (struct sockaddr *);
|
uint16_t gt_get_port (struct sockaddr *);
|
||||||
int gt_toaddr (char *, size_t, struct sockaddr *);
|
int gt_toaddr (char *, size_t, struct sockaddr *);
|
||||||
|
|
||||||
|
int gt_list (int, char **);
|
||||||
int gt_show (int, char **);
|
int gt_show (int, char **);
|
||||||
int gt_bind (int, char **);
|
int gt_bind (int, char **);
|
||||||
int gt_path (int, char **);
|
int gt_path (int, char **);
|
||||||
|
|||||||
49
src/list.c
Normal file
49
src/list.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "ctl.h"
|
||||||
|
|
||||||
|
#include "../argz/argz.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
gt_list(int argc, char **argv)
|
||||||
|
{
|
||||||
|
struct argz showz[] = {
|
||||||
|
{"list", NULL, NULL, argz_option},
|
||||||
|
{NULL}};
|
||||||
|
|
||||||
|
if (argz(showz, argc, argv))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char dir[64];
|
||||||
|
|
||||||
|
if (!ctl_rundir(dir, sizeof(dir)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
DIR *dp = opendir(dir);
|
||||||
|
|
||||||
|
if (!dp)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
struct dirent *d = NULL;
|
||||||
|
|
||||||
|
while (d = readdir(dp), d) {
|
||||||
|
if (d->d_name[0] == '.')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int fd = ctl_connect(d->d_name);
|
||||||
|
|
||||||
|
if (fd < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
printf("%s\n", d->d_name);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -78,7 +78,8 @@ main(int argc, char **argv)
|
|||||||
char *help;
|
char *help;
|
||||||
int (*call)(int, char **);
|
int (*call)(int, char **);
|
||||||
} cmd[] = {
|
} cmd[] = {
|
||||||
{"show", "show tunnel info", gt_show},
|
{"list", "list all tunnels", gt_list},
|
||||||
|
{"show", "show tunnel information", gt_show},
|
||||||
{"bench", "start a crypto bench", gt_bench},
|
{"bench", "start a crypto bench", gt_bench},
|
||||||
{"bind", "start a new tunnel", gt_bind},
|
{"bind", "start a new tunnel", gt_bind},
|
||||||
{"set", "change tunnel properties", gt_set},
|
{"set", "change tunnel properties", gt_set},
|
||||||
|
|||||||
Reference in New Issue
Block a user