X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e8b523758959c1854689d71c7a4686c631e5501c..309ca62193772fd8ba532fd413b51a61be0c741e:/print-dccp.c?ds=sidebyside diff --git a/print-dccp.c b/print-dccp.c index fee4a6e5..79ea5f72 100644 --- a/print-dccp.c +++ b/print-dccp.c @@ -60,7 +60,7 @@ static const char *dccp_feature_nums[] = { "check data checksum", }; -static inline int dccp_csum_coverage(const struct dccp_hdr* dh, u_int len) +static inline u_int dccp_csum_coverage(const struct dccp_hdr* dh, u_int len) { u_int cov; @@ -73,61 +73,15 @@ static inline int dccp_csum_coverage(const struct dccp_hdr* dh, u_int len) static int dccp_cksum(const struct ip *ip, const struct dccp_hdr *dh, u_int len) { - int cov = dccp_csum_coverage(dh, len); - union phu { - struct phdr { - u_int32_t src; - u_int32_t dst; - u_char mbz; - u_char proto; - u_int16_t len; - } ph; - u_int16_t pa[6]; - } phu; - const u_int16_t *sp; - - /* pseudo-header.. */ - phu.ph.mbz = 0; - phu.ph.len = htons(len); - phu.ph.proto = IPPROTO_DCCP; - memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t)); - if (IP_HL(ip) == 5) - memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t)); - else - phu.ph.dst = ip_finddst(ip); - - sp = &phu.pa[0]; - return in_cksum((u_short *)dh, cov, sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]); + return nextproto4_cksum(ip, (const u_int8_t *)(void *)dh, + dccp_csum_coverage(dh, len), IPPROTO_DCCP); } #ifdef INET6 static int dccp6_cksum(const struct ip6_hdr *ip6, const struct dccp_hdr *dh, u_int len) { - size_t i; - u_int32_t sum = 0; - int cov = dccp_csum_coverage(dh, len); - 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_DCCP; - - for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++) - sum += phu.pa[i]; - - return in_cksum((u_short *)dh, cov, sum); + return nextproto6_cksum(ip6, (const u_int8_t *)(void *)dh, + dccp_csum_coverage(dh, len), IPPROTO_DCCP); } #endif