alfred: Start up alfred without valid interfaces
[feed/routing.git] / alfred / patches / 0003-alfred-Save-global-mode-flags-in-bitfield.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Mon, 15 Feb 2021 20:34:54 +0100
3 Subject: alfred: Save global mode flags in bitfield
4
5 The verbose and ipv4mode entries in the globals structure is only used to
6 save a boolean information. So just use a bit in a bitfield to store this
7 information instead of a full int.
8
9 Signed-off-by: Sven Eckelmann <sven@narfation.org>
10 Forwarded: https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/20210215200126.140253-3-sven@narfation.org/
11
12 diff --git a/alfred.h b/alfred.h
13 index 7d6b0b35b5c8b8c3b087589880c390eb035584be..c64ff17ab9be8a16b3e1c86070b93235c226a004 100644
14 --- a/alfred.h
15 +++ b/alfred.h
16 @@ -115,8 +115,8 @@ struct globals {
17 enum clientmode clientmode;
18 int clientmode_arg;
19 int clientmode_version;
20 - int verbose;
21 - int ipv4mode;
22 + uint8_t verbose:1;
23 + uint8_t ipv4mode:1;
24
25 int unix_sock;
26 const char *unix_path;
27 diff --git a/main.c b/main.c
28 index 7b866cc4275797beb7f614dd1a19ea0099e1281b..f25b6cc11975b8523abf6c59b77a86e94684b03b 100644
29 --- a/main.c
30 +++ b/main.c
31 @@ -9,6 +9,7 @@
32 #include <arpa/inet.h>
33 #include <getopt.h>
34 #include <signal.h>
35 +#include <stdbool.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 @@ -181,8 +182,8 @@ static struct globals *alfred_init(int argc, char *argv[])
40 globals->clientmode_version = 0;
41 globals->mesh_iface = "bat0";
42 globals->unix_path = ALFRED_SOCK_PATH_DEFAULT;
43 - globals->verbose = 0;
44 - globals->ipv4mode = 0;
45 + globals->verbose = false;
46 + globals->ipv4mode = false;
47 globals->update_command = NULL;
48 globals->sync_period.tv_sec = ALFRED_INTERVAL;
49 globals->sync_period.tv_nsec = 0;
50 @@ -252,7 +253,7 @@ static struct globals *alfred_init(int argc, char *argv[])
51 globals->unix_path = optarg;
52 break;
53 case 'd':
54 - globals->verbose++;
55 + globals->verbose = true;
56 break;
57 case 'c':
58 globals->update_command = optarg;
59 @@ -268,7 +269,7 @@ static struct globals *alfred_init(int argc, char *argv[])
60 printf(" ** Setting sync interval to: %.9f seconds (%ld.%09ld)\n", sync_period, globals->sync_period.tv_sec, globals->sync_period.tv_nsec);
61 break;
62 case '4':
63 - globals->ipv4mode = 1;
64 + globals->ipv4mode = true;
65 inet_pton(AF_INET, optarg, &alfred_mcast.ipv4);
66 printf(" ** IPv4 Multicast Mode: %x\n", alfred_mcast.ipv4.s_addr);
67 break;