Clean up some other stuff while we're at it.
#define IP_MSS 576 /* default maximum segment size */
/* in print-ip.c */
-extern u_int32_t ip_finddst(const struct ip *);
+extern int nextproto4_cksum(const struct ip *, const u_int8_t *, u_int, u_int);
register const u_char *, u_int);
extern void igrp_print(netdissect_options *,const u_char *, u_int,
const u_char *);
+extern int nextproto4_cksum(const struct ip *, const u_int8_t *, u_int, u_int);
extern void ipN_print(netdissect_options *,const u_char *, u_int);
extern void ipx_print(netdissect_options *,const u_char *, u_int);
extern void isoclns_print(netdissect_options *,const u_char *,
"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;
static int dccp_cksum(const struct ip *ip,
const struct dccp_hdr *dh, u_int len)
{
- int cov = dccp_csum_coverage(dh, len);
- struct phdr {
- u_int32_t src;
- u_int32_t dst;
- u_char mbz;
- u_char proto;
- u_int16_t len;
- } ph;
- struct cksum_vec vec[2];
-
- /* pseudo-header.. */
- ph.mbz = 0;
- ph.len = htons(len);
- ph.proto = IPPROTO_DCCP;
- memcpy(&ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
- if (IP_HL(ip) == 5)
- memcpy(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
- else
- ph.dst = ip_finddst(ip);
-
- 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 nextproto4_cksum(ip, (const u_int8_t *)(void *)dh,
+ dccp_csum_coverage(dh, len), IPPROTO_DCCP);
}
#ifdef INET6
* This is used for UDP and TCP pseudo-header in the checksum
* calculation.
*/
-u_int32_t
+static u_int32_t
ip_finddst(const struct ip *ip)
{
int length;
return retval;
}
+/*
+ * Compute a V4-style checksum by building a pseudoheader.
+ */
+int
+nextproto4_cksum(const struct ip *ip, const u_int8_t *data,
+ u_int len, u_int next_proto)
+{
+ struct phdr {
+ u_int32_t src;
+ u_int32_t dst;
+ u_char mbz;
+ u_char proto;
+ u_int16_t len;
+ } ph;
+ struct cksum_vec vec[2];
+
+ /* pseudo-header.. */
+ ph.len = htons((u_int16_t)len);
+ ph.mbz = 0;
+ ph.proto = next_proto;
+ memcpy(&ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
+ if (IP_HL(ip) == 5)
+ memcpy(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
+ else
+ ph.dst = ip_finddst(ip);
+
+ vec[0].ptr = (const u_int8_t *)(void *)&ph;
+ vec[0].len = sizeof(ph);
+ vec[1].ptr = data;
+ vec[1].len = len;
+ return (in_cksum(vec, 2));
+}
+
static void
ip_printts(register const u_char *cp, u_int length)
{
register const struct tcphdr *tp,
register u_int len)
{
- struct phdr {
- u_int32_t src;
- u_int32_t dst;
- u_char mbz;
- u_char proto;
- u_int16_t len;
- } ph;
- struct cksum_vec vec[2];
-
- /* pseudo-header.. */
- ph.len = htons((u_int16_t)len);
- ph.mbz = 0;
- ph.proto = IPPROTO_TCP;
- memcpy(&ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
- if (IP_HL(ip) == 5)
- memcpy(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
- else
- ph.dst = ip_finddst(ip);
-
- vec[0].ptr = (const u_int8_t *)(void *)&ph;
- vec[0].len = sizeof(ph);
- vec[1].ptr = (const u_int8_t *)tp;
- vec[1].len = len;
- return in_cksum(vec, 2);
+ return (nextproto4_cksum(ip, (const u_int8_t *)tp, len,
+ IPPROTO_TCP));
}
void
register const struct udphdr *up,
register u_int len)
{
- struct phdr {
- u_int32_t src;
- u_int32_t dst;
- u_char mbz;
- u_char proto;
- u_int16_t len;
- } ph;
- struct cksum_vec vec[2];
-
- /* pseudo-header.. */
- ph.len = htons((u_int16_t)len);
- ph.mbz = 0;
- ph.proto = IPPROTO_UDP;
- memcpy(&ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
- if (IP_HL(ip) == 5)
- memcpy(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
- else
- ph.dst = ip_finddst(ip);
-
- 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 (nextproto4_cksum(ip, (const u_int8_t *)(void *)up, len,
+ IPPROTO_UDP));
}
#ifdef INET6