-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmrp_server.c
81 lines (64 loc) · 1.36 KB
/
mrp_server.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
// SPDX-License-Identifier: (GPL-2.0)
#include <stdio.h>
#include <stdbool.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
#include <ev.h>
#include <unistd.h>
#include "server_socket.h"
#include "utils.h"
#include "packet.h"
#include "print.h"
volatile bool quit = false;
static void usage(void)
{
printf("Usage::\n"
" -m print messages to stdout\n"
" -h print this message and exit\n"
" -l [num] set the logging level\n");
}
static void handle_signal(int sig)
{
ev_break(EV_DEFAULT, EVBREAK_ALL);;
}
int signal_init(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = handle_signal;
sa.sa_flags = 0;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
return 0;
}
int main(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "mhl:")) != -1) {
switch (c) {
case 'm':
print_set_verbose(1);
break;
case 'l':
print_set_level(atoi(optarg));
break;
case 'h':
usage();
return 0;
default:
usage();
return 0;
}
}
ctl_socket_init();
packet_socket_init();
ev_run(EV_DEFAULT, 0);
packet_socket_cleanup();
ctl_socket_cleanup();
return 0;
}