aboutsummaryrefslogtreecommitdiffstats
path: root/wg_dynamic_server.c
blob: fb4fc444cb9e1dbbfb4b46596a5898a907306fa0 (plain) (blame)
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
/* SPDX-License-Identifier: MIT */
/*
 * Copyright (C) 2018 Wireguard LLC
 */

#include "server.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

const char *PROG_NAME;

static void show_usage()
{
	fprintf(stderr, "Usage: %s <interface>\n\n", PROG_NAME);
}

int main(int argc, char *argv[])
{
	const char *iface;
	int sock;
	int ret;

	PROG_NAME = argv[0];

	if (argc == 1) {
		show_usage();
		return EXIT_FAILURE;
	}

	iface = argv[1];

	if (!is_wg_up_on_iface(iface)) {
		fprintf(stderr, "no such wireguard interface: %s\n", iface);
		return EXIT_FAILURE;
	}

	if ((sock = setup_server(argv[1])) < 0) {
		fprintf(stderr, "error setting up server: %s\n",
			strerror(-sock));
		return EXIT_FAILURE;
	}

	if ((ret = handle_connections(sock)) < 0) {
		fprintf(stderr, "error while handling connections: %s\n",
			strerror(-ret));
		return EXIT_FAILURE;
	}

	/* unreachable */
	return EXIT_FAILURE;
}