This patch doesn't require extra fiddling on either Linux (Gentoo) or
FreeBSD 6.1. Since both have the 8 bit array for V6 addresses,
neither requires any additional OS-specific hacks. I think this might
be more generally portable.
This is a diff against the CVS archive as of today.
Index: addr_hash.c
===================================================================
RCS file: /home/pdw/vcvs/repos/iftop/addr_hash.c,v
retrieving revision 1.6
diff -u -r1.6 addr_hash.c
--- addr_hash.c 27 Nov 2010 11:06:12 -0000 1.6
+++ addr_hash.c 5 Jun 2011 16:57:30 -0000
@@ -43,7 +43,7 @@
addr_pair* ap = (addr_pair*)key;
if (ap->af == AF_INET6) {
- uint32_t* addr6 = ap->src6.s6_addr32;
+ uint32_t* addr6 = (uint32_t*)ap->src6.s6_addr;
hash = ( hash_uint32(addr6[0])
+ hash_uint32(addr6[1])
@@ -51,7 +51,7 @@
+ hash_uint32(addr6[3])
+ ap->src_port) % 0xFF;
- addr6 = ap->dst6.s6_addr32;
+ addr6 = (uint32_t*)ap->dst6.s6_addr;
hash = ( hash + hash_uint32(addr6[0])
+ hash_uint32(addr6[1])
+ hash_uint32(addr6[2])
Index: iftop.c
===================================================================
RCS file: /home/pdw/vcvs/repos/iftop/iftop.c,v
retrieving revision 1.56
diff -u -r1.56 iftop.c
--- iftop.c 27 Nov 2010 11:06:12 -0000 1.56
+++ iftop.c 5 Jun 2011 16:57:30 -0000
@@ -328,11 +328,11 @@
/* First reduce the participating addresses using the netfilter prefix.
* We need scratch pads to do this.
*/
- for (j=0; j < 4; ++j) {
- scribdst.s6_addr32[j] = ip6tr->ip6_dst.s6_addr32[j]
- & options.netfilter6mask.s6_addr32[j];
- scribsrc.s6_addr32[j] = ip6tr->ip6_src.s6_addr32[j]
- & options.netfilter6mask.s6_addr32[j];
+ for (j=0; j < 16; ++j) {
+ scribdst.s6_addr[j] = ip6tr->ip6_dst.s6_addr[j]
+ & options.netfilter6mask.s6_addr[j];
+ scribsrc.s6_addr[j] = ip6tr->ip6_src.s6_addr[j]
+ & options.netfilter6mask.s6_addr[j];
}
/* Now look for any hits. */
Index: ns_hash.c
===================================================================
RCS file: /home/pdw/vcvs/repos/iftop/ns_hash.c,v
retrieving revision 1.4
diff -u -r1.4 ns_hash.c
--- ns_hash.c 27 Nov 2010 11:06:12 -0000 1.4
+++ ns_hash.c 5 Jun 2011 16:57:30 -0000
@@ -29,7 +29,7 @@
int ns_hash_hash(void* key) {
int hash;
- uint32_t* addr6 = ((struct in6_addr *) key)->s6_addr32;
+ uint32_t* addr6 = (uint32_t*)((struct in6_addr *) key)->s6_addr;
hash = ( hash_uint32(addr6[0])
+ hash_uint32(addr6[1])
Index: options.c
===================================================================
RCS file: /home/pdw/vcvs/repos/iftop/options.c,v
retrieving revision 1.46
diff -u -r1.46 options.c
--- options.c 27 Nov 2010 11:06:12 -0000 1.46
+++ options.c 5 Jun 2011 16:57:30 -0000
@@ -538,16 +538,16 @@
}
else {
int bl, rem;
- const uint32_t mm = 0xffffffff;
- uint32_t part = mm;
+ const uint8_t mm = 0xff;
+ uint8_t part = mm;
- bl = n / 32;
- rem = n % 32;
- part <<= 32 - rem;
+ bl = n / 8;
+ rem = n % 8;
+ part <<= 8 - rem;
for (j=0; j < bl; ++j)
- options.netfilter6mask.s6_addr32[j] = htonl(mm);
+ options.netfilter6mask.s6_addr[j] = mm;
if (rem > 0)
- options.netfilter6mask.s6_addr32[bl] = htonl(part);
+ options.netfilter6mask.s6_addr[bl] = part;
options.netfilter6 = 1;
}
}
@@ -560,8 +560,8 @@
}
}
/* Prepare any comparison by masking the provided filtered net. */
- for (j=0; j < 4; ++j)
- options.netfilter6net.s6_addr32[j] &=
options.netfilter6mask.s6_addr32[j];
+ for (j=0; j < 16; ++j)
+ options.netfilter6net.s6_addr[j] &=
options.netfilter6mask.s6_addr[j];
return 1;
}