pseudo-header checksum, to allow for IPSEC or other encapsulations.
Use in_cksum() instead of private versions.
#ifndef lint
static const char rcsid[] =
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.6 2001-06-15 22:17:33 fenner Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.7 2001-08-20 17:53:54 fenner Exp $";
#endif
#include <sys/param.h>
#endif
#include <sys/param.h>
#define OSRC_PRES 0x0080 /* old source is present */
#define OSRC_PRES 0x0080 /* old source is present */
-static u_int16_t mob_in_cksum(u_short *p, int len);
-
/*
* Deencapsulate and print a mobile-tunneled IP datagram
*/
/*
* Deencapsulate and print a mobile-tunneled IP datagram
*/
(void)printf("> %s ",ipaddr_string(&mob->odst));
(void)printf("(oproto=%d)",proto>>8);
}
(void)printf("> %s ",ipaddr_string(&mob->odst));
(void)printf("(oproto=%d)",proto>>8);
}
- if (mob_in_cksum((u_short *)mob, osp ? 12 : 8)!=0) {
+ if (in_cksum((u_short *)mob, osp ? 12 : 8, 0)!=0) {
(void)printf(" (bad checksum %d)",crc);
}
return;
}
(void)printf(" (bad checksum %d)",crc);
}
return;
}
-
-static u_int16_t mob_in_cksum(u_short *p, int len)
-{
- u_int32_t sum = 0;
- int nwords = len >> 1;
-
- while (nwords-- != 0)
- sum += *p++;
-
- if (len & 1) {
- union {
- u_int16_t w;
- u_int8_t c[2];
- } u;
- u.c[0] = *(u_char *)p;
- u.c[1] = 0;
- sum += u.w;
- }
-
- /* end-around-carry */
- sum = (sum >> 16) + (sum & 0xffff);
- sum += (sum >> 16);
- return (~sum);
-}
-
#ifndef lint
static const char rcsid[] =
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.87 2001-06-25 21:38:50 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.88 2001-08-20 17:53:53 fenner Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#endif
#ifdef HAVE_CONFIG_H
register const struct tcphdr *tp,
register int len)
{
register const struct tcphdr *tp,
register int len)
{
union phu {
struct phdr {
u_int32_t src;
union phu {
struct phdr {
u_int32_t src;
} ph;
u_int16_t pa[6];
} phu;
} ph;
u_int16_t pa[6];
} phu;
- register const u_int16_t *sp;
- u_int32_t sum;
- tlen = ntohs(ip->ip_len) - ((const char *)tp-(const char*)ip);
- phu.ph.len = htons(tlen);
+ phu.ph.len = htons(len); /* XXX */
phu.ph.mbz = 0;
phu.ph.proto = IPPROTO_TCP;
memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
sp = &phu.pa[0];
phu.ph.mbz = 0;
phu.ph.proto = IPPROTO_TCP;
memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
sp = &phu.pa[0];
- sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5];
-
- sp = (const u_int16_t *)tp;
-
- for (i=0; i<(tlen&~1); i+= 2)
- sum += *sp++;
-
- if (tlen & 1) {
- sum += htons( (*(const u_int8_t *)sp) << 8);
- }
-
- while (sum > 0xffff)
- sum = (sum & 0xffff) + (sum >> 16);
- sum = ~sum & 0xffff;
-
- return (sum);
+ return in_cksum((u_short *)tp, len,
+ sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
#ifndef lint
static const char rcsid[] =
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.96 2001-06-26 06:19:06 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.97 2001-08-20 17:53:54 fenner Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#endif
#ifdef HAVE_CONFIG_H
register const struct udphdr *up,
register int len)
{
register const struct udphdr *up,
register int len)
{
union phu {
struct phdr {
u_int32_t src;
union phu {
struct phdr {
u_int32_t src;
u_int16_t pa[6];
} phu;
register const u_int16_t *sp;
u_int16_t pa[6];
} phu;
register const u_int16_t *sp;
- u_int32_t sum;
- tlen = ntohs(ip->ip_len) - ((const char *)up-(const char*)ip);
- phu.ph.len = htons(tlen);
+ phu.ph.len = htons(len);
phu.ph.mbz = 0;
phu.ph.proto = IPPROTO_UDP;
memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
sp = &phu.pa[0];
phu.ph.mbz = 0;
phu.ph.proto = IPPROTO_UDP;
memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
sp = &phu.pa[0];
- sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5];
-
- sp = (const u_int16_t *)up;
-
- for (i=0; i<(tlen&~1); i+= 2)
- sum += *sp++;
-
- if (tlen & 1) {
- sum += htons( (*(const u_int8_t *)sp) << 8);
- }
-
- while (sum > 0xffff)
- sum = (sum & 0xffff) + (sum >> 16);
- sum = ~sum & 0xffff;
-
- return (sum);
+ return in_cksum((u_short *)up, len,
+ sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
if (sum == 0) {
(void)printf("[no cksum] ");
} else if (TTEST2(cp[0], length)) {
if (sum == 0) {
(void)printf("[no cksum] ");
} else if (TTEST2(cp[0], length)) {
- sum = udp_cksum(ip, up, length);
+ sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
if (sum != 0)
(void)printf("[bad udp cksum %x!] ", sum);
else
if (sum != 0)
(void)printf("[bad udp cksum %x!] ", sum);
else