/*
* Returns the minimum snaplen needed to decode everything up to the TCP/UDP
- * packet headers. Argument lh is not allowed to be NULL.
+ * packet headers. The IPv6 header is normative. The argument lh is not
+ * allowed to be NULL.
*/
int
getsnaplen(const linkhdr_t *lh)
{
assert(lh != NULL);
- return (lh->hdrlen + IP_HDR_LEN + max(TCP_HDR_LEN, UDP_HDR_LEN));
+ return (lh->hdrlen + IPV6_HDR_LEN + max(TCP_HDR_LEN, UDP_HDR_LEN));
}
/*
return;
}
if (hdr->ip_v != 4) {
- verbosef("ip: version %d (expecting 4)", hdr->ip_v);
+ verbosef("ip: version %d (expecting 4 or 6)", hdr->ip_v);
return;
}
#include <pcap.h>
#include <netinet/in_systm.h> /* n_time */
+#define __USE_GNU 1
#include <netinet/in.h> /* in_addr_t */
#include <netinet/ip.h> /* struct ip */
};
time_t time;
uint16_t len;
- uint8_t af; /* AF_{UNSPEC, INET, INET6} */
+ sa_family_t af; /* AF_{UNSPEC, INET, INET6} */
uint8_t proto; /* IPPROTO_{TCP, UDP, ICMP} */
uint8_t tcp_flags; /* only for TCP */
uint16_t src_port, dest_port; /* only for TCP, UDP */
return ( (ip) ^ ((ip) >> 7) ^ ((ip) >> 17) );
}
+#ifndef s6_addr32
+/* Covers OpenBSD and FreeBSD. The macro __USE_GNU has
+ * taken care of GNU/Linux and GNU/kfreebsd. */
+# define s6_addr32 __u6_addr.__u6_addr32
+#endif
+
+/*
+ * This is the IPv6 hash function used by FreeBSD in the same file as above,
+ * svn rev 122922.
+ */
+inline static uint32_t
+ipv6_hash(const struct in6_addr *const ip6)
+{
+ return ( ip6->s6_addr32[0] ^ ip6->s6_addr32[1] ^ ip6->s6_addr32[2] ^ ip6->s6_addr32[3] );
+}
+
/* ---------------------------------------------------------------------------
* hash_func collection
*/
struct bucket *next; \
uint64_t in, out, total; \
union { struct type t; } u; } _custom_bucket; \
- struct bucket *name_bucket = xmalloc(sizeof(_custom_bucket)); \
+ struct bucket *name_bucket = xcalloc(1, sizeof(_custom_bucket)); \
struct type *name_content = &(name_bucket->u.type); \
name_bucket->next = NULL; \
name_bucket->in = name_bucket->out = name_bucket->total = 0;
assert(ht->count_keep < ht->count);
/* Fill table with pointers to buckets in hashtable. */
- table = xmalloc(sizeof(*table) * ht->count);
+ table = xcalloc(ht->count, sizeof(*table));
for (pos=0, i=0; i<ht->size; i++) {
struct bucket *b = ht->table[i];
while (b != NULL) {
}
/* Fill table with pointers to buckets in hashtable. */
- table = xmalloc(sizeof(*table) * ht->count);
+ table = xcalloc(ht->count, sizeof(*table));
for (pos=0, i=0; i<ht->size; i++) {
struct bucket *b = ht->table[i];
while (b != NULL) {