| * This file was originally taken from the FreeBSD project. |
| * Copyright (c) 2001 Charles Mott <cm@linktel.net> |
| * Copyright (c) 2008 coresystems GmbH |
| * SPDX-License-Identifier: BSD-2-Clause |
| unsigned compute_ip_checksum(const void *vptr, unsigned nbytes) |
| const unsigned short *ptr = vptr; |
| ((u8 *)&oddbyte)[0] = *(u8 *)ptr; |
| sum = (sum >> 16) + (sum & 0xffff); |
| unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new) |
| * byte-swap the sum if it came from an odd offset; since the |
| * computation is endian independant this works. |
| new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00); |
| return (~checksum) & 0xffff; |
| int ip_checksum_ok(const void *addr, unsigned nbytes) |
| return !(compute_ip_checksum(addr, nbytes) & 0xfffe); |