allow coexistance of N build and AC build.
[tomato.git] / release / src / router / rc / arpbind.c
blob4400de8444b07492bc66278676b16fc3f17852aa
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 nvp = nv = strdup(nvram_safe_get("dhcpd_static"));
10 if (!nv) return;
12 // clear arp table first
13 stop_arpbind();
15 while ((b = strsep(&nvp, ">")) != NULL) {
17 macaddr<ip.ad.dr.ess<hostname<arpbind>anotherhwaddr<other.ip.addr.ess<othername<arpbind
20 if ((vstrsep(b, "<", &macaddr, &ipaddr, &name, &bind)) != 4)
21 continue;
22 if (strchr(macaddr,',') != NULL)
23 continue;
24 if (strcmp(bind,"1") == 0)
25 eval ("arp", "-s", (char *)ipaddr, (char *)macaddr);
27 free(nv);
30 void stop_arpbind(void) {
32 FILE *f;
33 char buf[512];
34 char ipaddr[48] = "";
36 if ((f = fopen("/proc/net/arp", "r")) != NULL) {
37 // fgets(buf, sizeof(buf), f); // header
38 while (fgets(buf, sizeof(buf), f)) {
39 if (sscanf(buf, "%s %*s %*s %*s %*s %*s", ipaddr) != 1) continue;
40 eval ("arp", "-d", (char *)ipaddr);
42 fclose(f);