summaryrefslogtreecommitdiffstats
path: root/src/dect-cell-add.c
blob: f9448a0f245839e9d55359def7e12c35651b8ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "netlink/cli/utils.h"

int main(int argc, char *argv[])
{
	struct nl_sock *sock;
	struct nl_dect_cell *cell;
	struct nl_cache *cluster_cache;
	struct nl_dump_params params = {
		.dp_type = NL_DUMP_LINE,
		.dp_fd = stdout,
	};
	uint8_t cli;
	int err;

	sock = nl_cli_alloc_socket();
	nl_cli_connect(sock, NETLINK_DECT);

	if (nl_dect_cluster_alloc_cache(sock, &cluster_cache))
		exit(1);
	nl_cache_mngt_provide(cluster_cache);

	cell = nl_dect_cell_alloc();
	for (;;) {
		int c, optidx = 0;
		enum {
			ARG_NAME = 256,
			ARG_FLAGS,
			ARG_CLUSTER,
		};
		static struct option long_opts[] = {
			{ "name",		1, 0, ARG_NAME },
			{ "flags",		1, 0, ARG_FLAGS },
			{ "cluster",		1, 0, ARG_CLUSTER },
			{ 0, 0, 0, 0 }
		};

		c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case 'v': nl_cli_print_version(); break;
		case ARG_NAME:
			nl_dect_cell_set_name(cell, optarg);
			break;
		case ARG_FLAGS:
			nl_dect_cell_set_flags(cell, nl_dect_cell_str2flags(optarg));
			break;
		case ARG_CLUSTER:
			if (isdigit(*optarg))
				cli = strtoul(optarg, NULL, 0);
			else
				cli = nl_dect_cluster_name2i(cluster_cache, optarg);
			nl_dect_cell_set_link(cell, cli);
			break;
		}
	}

	err = nl_dect_cell_add(sock, cell, 0);
	if (err < 0)
		nl_cli_fatal(err, "Unable to add cell: %s", nl_geterror(err));

	printf("Added: ");
	nl_object_dump(OBJ_CAST(cell), &params);
	return 0;
}