* Note: the checksum routines assume that the actual checksum word has * been zeroed out. If the checksum word is filled with the proper value, * then these routines will give a result of zero (useful for testing * purposes); */
| 72 | * purposes); |
| 73 | */ |
| 74 | u_short |
| 75 | LibAliasInternetChecksum(struct libalias *la __unused, u_short * ptr, |
| 76 | int nbytes) |
| 77 | { |
| 78 | int sum, oddbyte; |
| 79 | |
| 80 | LIBALIAS_LOCK(la); |
| 81 | sum = 0; |
| 82 | while (nbytes > 1) { |
| 83 | sum += *ptr++; |
| 84 | nbytes -= 2; |
| 85 | } |
| 86 | if (nbytes == 1) { |
| 87 | oddbyte = 0; |
| 88 | ((u_char *) & oddbyte)[0] = *(u_char *) ptr; |
| 89 | ((u_char *) & oddbyte)[1] = 0; |
| 90 | sum += oddbyte; |
| 91 | } |
| 92 | sum = (sum >> 16) + (sum & 0xffff); |
| 93 | sum += (sum >> 16); |
| 94 | LIBALIAS_UNLOCK(la); |
| 95 | return (~sum); |
| 96 | } |
| 97 | |
| 98 | #ifndef _KERNEL |
| 99 | u_short |