- printf("[|ip]");
-}
-
-/*
- * compute an IP header checksum.
- * don't modifiy the packet.
- */
-u_short
-in_cksum(const u_short *addr, register u_int len, int csum)
-{
- int nleft = len;
- const u_short *w = addr;
- u_short answer;
- int sum = csum;
-
- /*
- * Our algorithm is simple, using a 32 bit accumulator (sum),
- * we add sequential 16 bit words to it, and at the end, fold
- * back all the carry bits from the top 16 bits into the lower
- * 16 bits.
- */
- while (nleft > 1) {
- sum += *w++;
- nleft -= 2;
- }
- if (nleft == 1)
- sum += htons(*(u_char *)w<<8);
-
- /*
- * add back carry outs from top 16 bits to low 16 bits
- */
- sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
-}
-
-/*
- * Given the host-byte-order value of the checksum field in a packet
- * header, and the network-byte-order computed checksum of the data
- * that the checksum covers (including the checksum itself), compute
- * what the checksum field *should* have been.
- */
-u_int16_t
-in_cksum_shouldbe(u_int16_t sum, u_int16_t computed_sum)
-{
- u_int32_t shouldbe;
-
- /*
- * The value that should have gone into the checksum field
- * is the negative of the value gotten by summing up everything
- * *but* the checksum field.
- *
- * We can compute that by subtracting the value of the checksum
- * field from the sum of all the data in the packet, and then
- * computing the negative of that value.
- *
- * "sum" is the value of the checksum field, and "computed_sum"
- * is the negative of the sum of all the data in the packets,
- * so that's -(-computed_sum - sum), or (sum + computed_sum).
- *
- * All the arithmetic in question is one's complement, so the
- * addition must include an end-around carry; we do this by
- * doing the arithmetic in 32 bits (with no sign-extension),
- * and then adding the upper 16 bits of the sum, which contain
- * the carry, to the lower 16 bits of the sum, and then do it
- * again in case *that* sum produced a carry.
- *
- * As RFC 1071 notes, the checksum can be computed without
- * byte-swapping the 16-bit words; summing 16-bit words
- * on a big-endian machine gives a big-endian checksum, which
- * can be directly stuffed into the big-endian checksum fields
- * in protocol headers, and summing words on a little-endian
- * machine gives a little-endian checksum, which must be
- * byte-swapped before being stuffed into a big-endian checksum
- * field.
- *
- * "computed_sum" is a network-byte-order value, so we must put
- * it in host byte order before subtracting it from the
- * host-byte-order value from the header; the adjusted checksum
- * will be in host byte order, which is what we'll return.
- */
- shouldbe = sum;
- shouldbe += ntohs(computed_sum);
- shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16);
- shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16);
- return shouldbe;