FreeBSD/tools/tools/netmap/pkt-gen.c
/* Compute the checksum of the given ip header. */
Compute the checksum of the given ip header.
Compute the checksum of the given ip header .
static uint16_t
checksum(const void *data, uint16_t len, uint32_t sum)
{
        const uint8_t *addr = data;
	uint32_t i;
        for (i = 0; i < (len & ~1U); i += 2) {
                sum += (u_int16_t)ntohs(*((u_int16_t *)(addr + i)));
                if (sum > 0xFFFF)
                        sum -= 0xFFFF;
        }
	if (i < len) {
		sum += addr[i] << 8;
		if (sum > 0xFFFF)
			sum -= 0xFFFF;
	}
	return sum;
}
static uint16_t checksum ( const void * data , uint16_t len , uint32_t sum ) { const uint8_t * addr = data ; uint32_t i ; for ( i = 0 ; i < ( len & ~ 1U ) ; i += 2 ) { sum += ( u_int16_t ) ntohs ( * ( ( u_int16_t * ) ( addr + i ) ) ) ; if ( sum > 0xFFFF ) sum -= 0xFFFF ; } if ( i < len ) { sum += addr [ i ] << 8 ; if ( sum > 0xFFFF ) sum -= 0xFFFF ; } return sum ; }
Compute the checksum of the given ip header.
Compute the checksum of the given ip header .
/* Checksum all the pairs of bytes first... */ /*
	 * If there's a single byte left over, checksum it, too.
	 * Network byte order is big-endian, so the remaining byte is
	 * the high byte.
	 */