summaryrefslogtreecommitdiffstats
path: root/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-09-15 19:15:52 +0000
committerRoy Marples <roy@marples.name>2008-09-15 19:15:52 +0000
commitafc7387846a6e8f01deafe2f2ae797392d496413 (patch)
treeddbaa902c469571b995217d549254f8cb399542a /if-bsd.c
parent1da85ce3902e0fa159b35f24f5addffeb9493eac (diff)
downloaddhcpcd-afc7387846a6e8f01deafe2f2ae797392d496413.tar.xz
We need to flush the ARP table after configuring new routes.
Diffstat (limited to 'if-bsd.c')
-rw-r--r--if-bsd.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/if-bsd.c b/if-bsd.c
index 6da4dd2b..576e6f42 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -25,11 +25,12 @@
* SUCH DAMAGE.
*/
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
#include <arpa/inet.h>
#include <net/if_dl.h>
@@ -188,6 +189,44 @@ if_route(const struct interface *iface, const struct in_addr *dest,
}
int
+arp_flush(void)
+{
+ int s, mib[6], retval = 0;
+ size_t buffer_len = 0;
+ char *buffer, *e, *p;
+ struct rt_msghdr *rtm;
+
+ if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) == -1)
+ return -1;
+ mib[0] = CTL_NET;
+ mib[1] = PF_ROUTE;
+ mib[2] = 0;
+ mib[3] = AF_INET;
+ mib[4] = NET_RT_FLAGS;
+ mib[5] = RTF_LLINFO;
+ printf ("sizeof %d\n", sizeof(mib));
+ if (sysctl(mib, 6, NULL, &buffer_len, NULL, 0) == -1)
+ return -1;
+ if (buffer_len == 0)
+ return 0;
+ buffer = xmalloc(buffer_len);
+ if (sysctl(mib, 6, buffer, &buffer_len, NULL, 0) == -1)
+ return -1;
+ e = buffer + buffer_len;
+ for (p = buffer; p < e; p += rtm->rtm_msglen) {
+ rtm = (struct rt_msghdr *)(void *)p;
+ rtm->rtm_type = RTM_DELETE;
+ if (write(s, rtm, rtm->rtm_msglen) == -1) {
+ retval = -1;
+ break;
+ }
+ }
+ free(buffer);
+ close(s);
+ return retval;
+}
+
+int
open_link_socket(void)
{
int fd;