Skip to content

Commit 0e777c9

Browse files
committed
Make path for ARP table configurable
Adds -a switch to wifidog executable.
1 parent b80bc0b commit 0e777c9

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

src/commandline.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ parse_commandline(int argc, char **argv)
9696
i = 0;
9797
restartargv[i++] = safe_strdup(argv[0]);
9898

99-
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:"))) {
99+
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:a:"))) {
100100

101101
skiponrestart = 0;
102102

@@ -158,6 +158,15 @@ parse_commandline(int argc, char **argv)
158158
}
159159
break;
160160

161+
case 'a':
162+
if (optarg) {
163+
free(config->arp_table_path);
164+
config->arp_table_path = safe_strdup(optarg);
165+
} else {
166+
fprintf(stdout, "You must supply the path to the ARP table with -a!");
167+
exit(1);
168+
}
169+
break;
161170
default:
162171
usage();
163172
exit(1);

src/conf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ config_init(void)
197197
config.ssl_certs = safe_strdup(DEFAULT_AUTHSERVSSLCERTPATH);
198198
config.ssl_verify = DEFAULT_AUTHSERVSSLPEERVER;
199199
config.ssl_cipher_list = NULL;
200+
config.arp_table_path = safe_strdup(DEFAULT_ARPTABLE);
200201
}
201202

202203
/**

src/conf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#define DEFAULT_AUTHSERVSSLCERTPATH "/etc/ssl/certs/"
7272
/** Note that DEFAULT_AUTHSERVSSLNOPEERVER must be 0 or 1, even if the config file syntax is yes or no */
7373
#define DEFAULT_AUTHSERVSSLPEERVER 1 /* 0 means: Enable peer verification */
74+
#define DEFAULT_ARPTABLE "/proc/net/arp"
7475
/*@}*/
7576

7677
/*@{*/
@@ -185,6 +186,8 @@ typedef struct {
185186
char *ssl_cipher_list; /**< @brief List of SSL ciphers allowed. Optional. */
186187
t_firewall_ruleset *rulesets; /**< @brief firewall rules */
187188
t_trusted_mac *trustedmaclist; /**< @brief list of trusted macs */
189+
char *arp_table_path; /**< @brief Path to custom ARP table, formatted
190+
like /proc/net/arp */
188191
} s_config;
189192

190193
/** @brief Get the current gateway configuration */

src/firewall.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ fw_set_authup(void)
139139
/* XXX DCY */
140140
/**
141141
* Get an IP's MAC address from the ARP cache.
142-
* Go through all the entries in /proc/net/arp until we find the requested
143-
* IP address and return the MAC address bound to it.
142+
* Go through all the entries in config->arp_table_path until we find the
143+
* requested IP address and return the MAC address bound to it.
144144
* @todo Make this function portable (using shell scripts?)
145145
*/
146146
char *
@@ -150,8 +150,9 @@ arp_get(const char *req_ip)
150150
char ip[16];
151151
char mac[18];
152152
char * reply;
153+
s_config *config = config_get_config();
153154

154-
if (!(proc = fopen("/proc/net/arp", "r"))) {
155+
if (!(proc = fopen(config->arp_table_path, "r"))) {
155156
return NULL;
156157
}
157158

0 commit comments

Comments
 (0)