From ca839e9209b3dacac5f032a06df5d63272e76193 Mon Sep 17 00:00:00 2001 From: sthen Date: Sat, 8 Nov 2008 22:15:10 +0000 Subject: [PATCH] repair libnet_get_hwaddr which was broken since the last RTM_VERSION change. some analysis by me, fix from Mikko Tolmunen on ports@, thanks! tested on many arch. --- net/libnet/1.0/Makefile | 4 +- .../1.0/patches/patch-src_libnet_link_bpf_c | 40 ++++++++++++++----- net/libnet/1.1/Makefile | 3 +- .../1.1/patches/patch-src_libnet_link_bpf_c | 25 ++++++++++++ 4 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 net/libnet/1.1/patches/patch-src_libnet_link_bpf_c diff --git a/net/libnet/1.0/Makefile b/net/libnet/1.0/Makefile index ff133b2b6d1..1ecca734b54 100644 --- a/net/libnet/1.0/Makefile +++ b/net/libnet/1.0/Makefile @@ -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/ diff --git a/net/libnet/1.0/patches/patch-src_libnet_link_bpf_c b/net/libnet/1.0/patches/patch-src_libnet_link_bpf_c index 015991ddae8..a0a08aa64f1 100644 --- a/net/libnet/1.0/patches/patch-src_libnet_link_bpf_c +++ b/net/libnet/1.0/patches/patch-src_libnet_link_bpf_c @@ -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 + #include + #include ++#include + #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)))) diff --git a/net/libnet/1.1/Makefile b/net/libnet/1.1/Makefile index fa2387f536e..4a3a0ed4382 100644 --- a/net/libnet/1.1/Makefile +++ b/net/libnet/1.1/Makefile @@ -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 diff --git a/net/libnet/1.1/patches/patch-src_libnet_link_bpf_c b/net/libnet/1.1/patches/patch-src_libnet_link_bpf_c new file mode 100644 index 00000000000..1163dec504d --- /dev/null +++ b/net/libnet/1.1/patches/patch-src_libnet_link_bpf_c @@ -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 + #include + #include ++#include + #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))))