72cb1a8bcc
code, as this used the NetBSD<5-style variable effective ifreq length. The patched code works in old and new compilation environments. Patch optimized by gimpy@.
39 lines
1.3 KiB
Text
39 lines
1.3 KiB
Text
$NetBSD: patch-ai,v 1.2 2012/08/23 13:10:52 is Exp $
|
|
|
|
--- src/if.c.orig 2006-04-02 14:29:42.000000000 +0000
|
|
+++ src/if.c
|
|
@@ -99,7 +99,7 @@ static int dl_addrlen;
|
|
|
|
static unsigned char *bpfBuffer; /* Packet filter buffer */
|
|
static int bpfLength = 0; /* Packet filter buffer length */
|
|
-static int bpfSize = 0; /* Number of unread bytes in buffer */
|
|
+int bpfSize = 0; /* Number of unread bytes in buffer */
|
|
static int bpfOffset = 0; /* Current offset in bpfBuffer */
|
|
#endif
|
|
|
|
@@ -152,7 +152,7 @@ getHWaddr(int sock, char const *ifname,
|
|
const struct sockaddr_dl *sdl;
|
|
struct ifconf ifc;
|
|
struct ifreq ifreq, *ifr;
|
|
- int i;
|
|
+ int i,l;
|
|
int found = 0;
|
|
|
|
ifc.ifc_len = sizeof(inbuf);
|
|
@@ -164,10 +164,12 @@ getHWaddr(int sock, char const *ifname,
|
|
ifreq.ifr_name[0] = '\0';
|
|
for (i = 0; i < ifc.ifc_len; ) {
|
|
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
|
|
- i += sizeof(ifr->ifr_name) +
|
|
- (ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
|
|
- ? ifr->ifr_addr.sa_len
|
|
- : sizeof(struct sockaddr));
|
|
+
|
|
+ l = sizeof(*ifr);
|
|
+ if (sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len > l)
|
|
+ l = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
|
|
+ i += l;
|
|
+
|
|
if (ifr->ifr_addr.sa_family == AF_LINK) {
|
|
sdl = (const struct sockaddr_dl *) &ifr->ifr_addr;
|
|
if ((sdl->sdl_type == IFT_ETHER) &&
|