Merge branch 'Toastman-RT' into Toastman-RT-N
[tomato.git] / release / src / router / rc / arpbind.c
blobdd4c25087a1820da256e473bdadcc5b97d81f951
1 #include "rc.h"
3 void start_arpbind(void) {
5 char *nvp, *nv, *b;
6 const char *ipaddr, *macaddr;
7 const char *name, *bind;
9 int anyways = nvram_get_int("arpbind_listed");
11 nvp = nv = strdup(nvram_safe_get("dhcpd_static"));
13 if (!nv) return;
15 // clear arp table first
16 stop_arpbind();
18 while ((b = strsep(&nvp, ">")) != NULL) {
20 macaddr<ip.ad.dr.ess<hostname<arpbind>anotherhwaddr<other.ip.addr.ess<othername<arpbind
23 if ((vstrsep(b, "<", &macaddr, &ipaddr, &name, &bind)) != 4)
24 continue;
25 if (strchr(macaddr,',') != NULL)
26 continue;
27 if ((strcmp(bind,"1") == 0) || (anyways == 1))
28 eval ("arp", "-s", (char *)ipaddr, (char *)macaddr);
30 free(nv);
33 void stop_arpbind(void) {
35 FILE *f;
36 char buf[512];
37 char ipaddr[48] = "";
39 if ((f = fopen("/proc/net/arp", "r")) != NULL) {
40 fgets(buf, sizeof(buf), f); // header - 1st line should be indeed ignored
41 while (fgets(buf, sizeof(buf), f)) {
42 if (sscanf(buf, "%s %*s %*s %*s %*s %*s", ipaddr) != 1) continue;
43 eval ("arp", "-d", (char *)ipaddr);
45 fclose(f);