You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
freshtomato-arm/release/src-rt-6.x.4708/router/rc/arpbind.c

60 lines
1.0 KiB
C

/*
Tomato Firmware
Copyright (C) 2006-2009 Jonathan Zarate
*/
#include "rc.h"
void start_arpbind(void)
{
char *nvp, *nv, *b;
const char *ipaddr, *macaddr;
const char *name, *bind;
nvp = nv = strdup(nvram_safe_get("dhcpd_static"));
if (!nv)
return;
/* clear arp table first */
stop_arpbind();
while ((b = strsep(&nvp, ">")) != NULL) {
/*
* macaddr<ip.ad.dr.ess<hostname<arpbind>anotherhwaddr<other.ip.addr.ess<othername<arpbind
*/
if ((vstrsep(b, "<", &macaddr, &ipaddr, &name, &bind)) < 4)
continue;
if (strchr(macaddr, ',') != NULL)
continue;
if (strcmp(bind, "1") == 0)
eval ("arp", "-s", (char *)ipaddr, (char *)macaddr);
}
free(nv);
}
void stop_arpbind(void)
{
FILE *f;
char buf[512];
char ipaddr[48] = "";
if ((f = fopen("/proc/net/arp", "r")) != NULL) {
while (fgets(buf, sizeof(buf), f)) {
if (sscanf(buf, "%s %*s %*s %*s %*s %*s", ipaddr) != 1)
continue;
if (strcmp(ipaddr, "IP") == 0)
continue;
eval ("arp", "-d", (char *)ipaddr);
}
fclose(f);
}
}