diff options
-rw-r--r-- | ip6.h | 2 | ||||
-rw-r--r-- | netdissect.h | 2 | ||||
-rw-r--r-- | print-dccp.c | 24 | ||||
-rw-r--r-- | print-icmp6.c | 40 | ||||
-rw-r--r-- | print-ip6.c | 6 | ||||
-rw-r--r-- | print-tcp.c | 2 | ||||
-rw-r--r-- | print-udp.c | 23 |
7 files changed, 12 insertions, 87 deletions
@@ -187,6 +187,6 @@ struct ip6_frag { #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */ /* in print-ip6.c */ -extern int nextproto6_cksum(const struct ip6_hdr *, const u_short *, u_int, u_int); +extern int nextproto6_cksum(const struct ip6_hdr *, const u_int8_t *, u_int, u_int); #endif /* not _NETINET_IP6_H_ */ diff --git a/netdissect.h b/netdissect.h index 0c829e62..5363988f 100644 --- a/netdissect.h +++ b/netdissect.h @@ -461,7 +461,7 @@ extern u_int ieee802_15_4_if_print(netdissect_options *,const struct pcap_pkthdr extern void ip6_print(netdissect_options *,const u_char *, u_int); #if 0 extern void ip6_opt_print(netdissect_options *,const u_char *, int); -extern int nextproto6_cksum(const struct ip6_hdr *, const u_short *, u_int, u_int); +extern int nextproto6_cksum(const struct ip6_hdr *, const u_int8_t *, u_int, u_int); extern int hbhopt_print(netdissect_options *,const u_char *); extern int dstopt_print(netdissect_options *,const u_char *); extern int frag6_print(netdissect_options *,const u_char *, diff --git a/print-dccp.c b/print-dccp.c index 460c43a0..96aa7ab2 100644 --- a/print-dccp.c +++ b/print-dccp.c @@ -103,28 +103,8 @@ static int dccp_cksum(const struct ip *ip, #ifdef INET6 static int dccp6_cksum(const struct ip6_hdr *ip6, const struct dccp_hdr *dh, u_int len) { - int cov = dccp_csum_coverage(dh, len); - struct { - struct in6_addr ph_src; - struct in6_addr ph_dst; - u_int32_t ph_len; - u_int8_t ph_zero[3]; - u_int8_t ph_nxt; - } ph; - struct cksum_vec vec[2]; - - /* pseudo-header */ - memset(&ph, 0, sizeof(ph)); - ph.ph_src = ip6->ip6_src; - ph.ph_dst = ip6->ip6_dst; - ph.ph_len = htonl(len); - ph.ph_nxt = IPPROTO_DCCP; - - vec[0].ptr = (const u_int8_t *)(void *)&ph; - vec[0].len = sizeof(ph); - vec[1].ptr = (const u_int8_t *)(void *)dh; - vec[1].len = cov; - return in_cksum(vec, 2); + return nextproto6_cksum(ip6, (const u_int8_t *)(void *)dh, + dccp_csum_coverage(dh, len), IPPROTO_DCCP); } #endif diff --git a/print-icmp6.c b/print-icmp6.c index c8c06386..be362bbf 100644 --- a/print-icmp6.c +++ b/print-icmp6.c @@ -197,44 +197,8 @@ print_lladdr(const u_int8_t *p, size_t l) static int icmp6_cksum(const struct ip6_hdr *ip6, const struct icmp6_hdr *icp, u_int len) { - size_t i; - register const u_int16_t *sp; - u_int32_t sum; - union { - struct { - struct in6_addr ph_src; - struct in6_addr ph_dst; - u_int32_t ph_len; - u_int8_t ph_zero[3]; - u_int8_t ph_nxt; - } ph; - u_int16_t pa[20]; - } phu; - - /* pseudo-header */ - memset(&phu, 0, sizeof(phu)); - phu.ph.ph_src = ip6->ip6_src; - phu.ph.ph_dst = ip6->ip6_dst; - phu.ph.ph_len = htonl(len); - phu.ph.ph_nxt = IPPROTO_ICMPV6; - - sum = 0; - for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++) - sum += phu.pa[i]; - - sp = (const u_int16_t *)icp; - - for (i = 0; i < (len & ~1); i += 2) - sum += *sp++; - - if (len & 1) - sum += htons((*(const u_int8_t *)sp) << 8); - - while (sum > 0xffff) - sum = (sum & 0xffff) + (sum >> 16); - sum = ~sum & 0xffff; - - return (sum); + return (nextproto6_cksum(ip6, (const u_int8_t *)(void *)icp, len, + IPPROTO_ICMPV6)); } enum ND_RPL_CODE { diff --git a/print-ip6.c b/print-ip6.c index fad1a9a2..f5e62441 100644 --- a/print-ip6.c +++ b/print-ip6.c @@ -48,7 +48,7 @@ static const char rcsid[] _U_ = * Compute a V6-style checksum by building a pseudoheader. */ int -nextproto6_cksum(const struct ip6_hdr *ip6, const u_short *data, +nextproto6_cksum(const struct ip6_hdr *ip6, const u_int8_t *data, u_int len, u_int next_proto) { struct { @@ -69,7 +69,7 @@ nextproto6_cksum(const struct ip6_hdr *ip6, const u_short *data, vec[0].ptr = (const u_int8_t *)(void *)&ph; vec[0].len = sizeof(ph); - vec[1].ptr = (const u_int8_t *)(void *)data; + vec[1].ptr = data; vec[1].len = len; return in_cksum(vec, 2); @@ -225,7 +225,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length) } case IPPROTO_PIM: - pim_print(cp, len, nextproto6_cksum(ip6, (u_short *)cp, len, + pim_print(cp, len, nextproto6_cksum(ip6, cp, len, IPPROTO_PIM)); return; diff --git a/print-tcp.c b/print-tcp.c index 24025e59..82840419 100644 --- a/print-tcp.c +++ b/print-tcp.c @@ -432,7 +432,7 @@ tcp_print(register const u_char *bp, register u_int length, #ifdef INET6 else if (IP_V(ip) == 6 && ip6->ip6_plen) { if (TTEST2(tp->th_sport, length)) { - sum = nextproto6_cksum(ip6, (u_short *)tp, length, IPPROTO_TCP); + sum = nextproto6_cksum(ip6, (const u_int8_t *)tp, length, IPPROTO_TCP); tcp_sum = EXTRACT_16BITS(&tp->th_sum); (void)printf(", cksum 0x%04x", tcp_sum); diff --git a/print-udp.c b/print-udp.c index 32a7e8af..02a1e6ec 100644 --- a/print-udp.c +++ b/print-udp.c @@ -316,27 +316,8 @@ static int udp_cksum(register const struct ip *ip, static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up, u_int len) { - struct { - struct in6_addr ph_src; - struct in6_addr ph_dst; - u_int32_t ph_len; - u_int8_t ph_zero[3]; - u_int8_t ph_nxt; - } ph; - struct cksum_vec vec[2]; - - /* pseudo-header */ - memset(&ph, 0, sizeof(ph)); - ph.ph_src = ip6->ip6_src; - ph.ph_dst = ip6->ip6_dst; - ph.ph_len = htonl(len); - ph.ph_nxt = IPPROTO_UDP; - - vec[0].ptr = (const u_int8_t *)(void *)&ph; - vec[0].len = sizeof(ph); - vec[1].ptr = (const u_int8_t *)(void *)up; - vec[1].len = len; - return (in_cksum(vec, 2)); + return (nextproto6_cksum(ip6, (const u_int8_t *)(void *)up, len, + IPPROTO_UDP)); } #endif |