--- src/libnet_link_bpf.c.orig	Mon Jan  8 02:13:48 2001
+++ src/libnet_link_bpf.c	Thu Dec  5 19:24:59 2013
@@ -28,7 +28,6 @@
  */
 
 #include <sys/param.h>  /* optionally get BSD define */
-#include <sys/timeb.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
 
@@ -43,6 +42,7 @@
 #include <sys/sysctl.h>
 #include <net/route.h>
 #include <net/if_dl.h>
+#include <net/if_types.h>
 #include "../include/gnuc.h"
 #include "../include/bpf.h"
 
@@ -61,7 +61,7 @@ libnet_bpf_open(char *errbuf)
      */
     for (i = 0;;i++)
     {
-        sprintf(device, "/dev/bpf%d", i);
+        snprintf(device, sizeof(device), "/dev/bpf%d", i);
 
         fd = open(device, O_RDWR);
         if (fd == -1 && errno == EBUSY)
@@ -83,7 +83,7 @@ libnet_bpf_open(char *errbuf)
 
     if (fd == -1)
     {
-        sprintf(errbuf, "%s: %s", device, ll_strerror(errno));
+        snprintf(errbuf, LIBNET_ERRBUF_SIZE, "%s: %s", device, ll_strerror(errno));
     }
     return (fd);
 }
@@ -104,7 +104,7 @@ libnet_open_link_interface(char *device, char *ebuf)
     l = (struct libnet_link_int *)malloc(sizeof(*l));
     if (!l)
     {
-        sprintf(ebuf, "malloc: %s", ll_strerror(errno));
+        snprintf(ebuf, LIBNET_ERRBUF_SIZE, "malloc: %s", ll_strerror(errno));
 #if (__DEBUG)
         libnet_error(LN_ERR_CRITICAL, "bpf libnet_open_link_interface: malloc %s",
                 ll_strerror(errno));
@@ -125,13 +125,13 @@ libnet_open_link_interface(char *device, char *ebuf)
      */
     if (ioctl(l->fd, BIOCVERSION, (caddr_t)&bv) < 0)
     {
-        sprintf(ebuf, "BIOCVERSION: %s", ll_strerror(errno));
+        snprintf(ebuf, LIBNET_ERRBUF_SIZE, "BIOCVERSION: %s", ll_strerror(errno));
         goto bad;
     }
 
     if (bv.bv_major != BPF_MAJOR_VERSION || bv.bv_minor < BPF_MINOR_VERSION)
     {
-        sprintf(ebuf, "kernel bpf filter out of date");
+        snprintf(ebuf, LIBNET_ERRBUF_SIZE, "kernel bpf filter out of date");
         goto bad;
     }
 
@@ -141,7 +141,7 @@ libnet_open_link_interface(char *device, char *ebuf)
     strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
     if (ioctl(l->fd, BIOCSETIF, (caddr_t)&ifr) == -1)
     {
-        sprintf(ebuf, "%s: %s", device, ll_strerror(errno));
+        snprintf(ebuf, LIBNET_ERRBUF_SIZE, "%s: %s", device, ll_strerror(errno));
         goto bad;
     }
 
@@ -150,7 +150,7 @@ libnet_open_link_interface(char *device, char *ebuf)
      */
     if (ioctl(l->fd, BIOCGDLT, (caddr_t)&v) == -1)
     {
-        sprintf(ebuf, "BIOCGDLT: %s", ll_strerror(errno));
+        snprintf(ebuf, LIBNET_ERRBUF_SIZE, "BIOCGDLT: %s", ll_strerror(errno));
         goto bad;
     }
 
@@ -161,7 +161,7 @@ libnet_open_link_interface(char *device, char *ebuf)
 #if defined(BIOCGHDRCMPLT) && defined(BIOCSHDRCMPLT)
     if (ioctl(l->fd, BIOCSHDRCMPLT, &spoof_eth_src) == -1)
     {
-        sprintf(ebuf, "BIOCSHDRCMPLT: %s", ll_strerror(errno));
+        snprintf(ebuf, LIBNET_ERRBUF_SIZE, "BIOCSHDRCMPLT: %s", ll_strerror(errno));
         goto bad;
     }
 #endif
@@ -278,9 +278,13 @@ libnet_get_hwaddr(struct libnet_link_int *l, const cha
     for (next = buf ; next < end ; next += ifm->ifm_msglen)
     {
         ifm = (struct if_msghdr *)next;
+        if (ifm->ifm_version != RTM_VERSION)
+            continue;
         if (ifm->ifm_type == RTM_IFINFO)
         {
             sdl = (struct sockaddr_dl *)(ifm + 1);
+            if (sdl->sdl_type != IFT_ETHER)
+                continue;
             if (strncmp(&sdl->sdl_data[0], device, sdl->sdl_nlen) == 0)
             {
                 if (!(ea = malloc(sizeof(struct ether_addr))))
