repair libnet_get_hwaddr which was broken since the last

RTM_VERSION change. some analysis by me, fix from Mikko Tolmunen
<oskari at sefirosu.org> on ports@, thanks! tested on many arch.
This commit is contained in:
sthen 2008-11-08 22:15:10 +00:00
parent c798e25019
commit ca839e9209
4 changed files with 60 additions and 12 deletions

View File

@ -1,8 +1,8 @@
# $OpenBSD: Makefile,v 1.6 2008/01/04 17:48:37 espie Exp $
# $OpenBSD: Makefile,v 1.7 2008/11/08 22:15:10 sthen Exp $
REVISION= 1.0
VERSION= ${REVISION}.2a
PKGNAME= ${DISTNAME}p1
PKGNAME= ${DISTNAME}p2
SHARED_LIBS= net 0.0
MASTER_SITES= http://www.packetfactory.net/libnet/dist/deprecated/

View File

@ -1,7 +1,15 @@
$OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
$OpenBSD: patch-src_libnet_link_bpf_c,v 1.3 2008/11/08 22:15:10 sthen Exp $
--- src/libnet_link_bpf.c.orig Mon Jan 8 01:13:48 2001
+++ src/libnet_link_bpf.c Sat Nov 8 22:07:54 2008
@@ -61,7 +61,7 @@ libnet_bpf_open(char *errbuf)
+++ src/libnet_link_bpf.c Sat Nov 8 21:53:55 2008
@@ -43,6 +43,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 +62,7 @@ libnet_bpf_open(char *errbuf)
*/
for (i = 0;;i++)
{
@ -10,7 +18,7 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
fd = open(device, O_RDWR);
if (fd == -1 && errno == EBUSY)
@@ -83,7 +83,7 @@ libnet_bpf_open(char *errbuf)
@@ -83,7 +84,7 @@ libnet_bpf_open(char *errbuf)
if (fd == -1)
{
@ -19,7 +27,7 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
}
return (fd);
}
@@ -104,7 +104,7 @@ libnet_open_link_interface(char *device, char *ebuf)
@@ -104,7 +105,7 @@ libnet_open_link_interface(char *device, char *ebuf)
l = (struct libnet_link_int *)malloc(sizeof(*l));
if (!l)
{
@ -28,7 +36,7 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
#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)
@@ -125,13 +126,13 @@ libnet_open_link_interface(char *device, char *ebuf)
*/
if (ioctl(l->fd, BIOCVERSION, (caddr_t)&bv) < 0)
{
@ -44,7 +52,7 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
goto bad;
}
@@ -141,7 +141,7 @@ libnet_open_link_interface(char *device, char *ebuf)
@@ -141,7 +142,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)
{
@ -53,7 +61,7 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
goto bad;
}
@@ -150,7 +150,7 @@ libnet_open_link_interface(char *device, char *ebuf)
@@ -150,7 +151,7 @@ libnet_open_link_interface(char *device, char *ebuf)
*/
if (ioctl(l->fd, BIOCGDLT, (caddr_t)&v) == -1)
{
@ -62,7 +70,7 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
goto bad;
}
@@ -161,7 +161,7 @@ libnet_open_link_interface(char *device, char *ebuf)
@@ -161,7 +162,7 @@ libnet_open_link_interface(char *device, char *ebuf)
#if defined(BIOCGHDRCMPLT) && defined(BIOCSHDRCMPLT)
if (ioctl(l->fd, BIOCSHDRCMPLT, &spoof_eth_src) == -1)
{
@ -71,3 +79,17 @@ $OpenBSD: patch-src_libnet_link_bpf_c,v 1.2 2008/11/08 22:09:40 sthen Exp $
goto bad;
}
#endif
@@ -278,9 +279,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))))

View File

@ -1,7 +1,8 @@
# $OpenBSD: Makefile,v 1.4 2008/01/04 17:48:37 espie Exp $
# $OpenBSD: Makefile,v 1.5 2008/11/08 22:17:41 sthen Exp $
REVISION= 1.1
VERSION= ${REVISION}.2.1
PKGNAME= ${DISTNAME}p0
SHARED_LIBS= net 11.0
WRKDIST= ${WRKDIR}/libnet

View File

@ -0,0 +1,25 @@
$OpenBSD: patch-src_libnet_link_bpf_c,v 1.1 2008/11/08 22:17:41 sthen Exp $
--- src/libnet_link_bpf.c.orig Sat Nov 8 21:55:03 2008
+++ src/libnet_link_bpf.c Sat Nov 8 21:56:56 2008
@@ -43,6 +43,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"
@@ -308,9 +309,13 @@ libnet_get_hwaddr(libnet_t *l)
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], l->device, sdl->sdl_nlen) == 0)
{
if (!(ea = malloc(sizeof(struct libnet_ether_addr))))