/* Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used). */
u16_t inet_chksum_pbuf(struct pbuf *p)
/* Calculate a checksum over a chain of pbufs (without pseudo-header, much like inet_chksum only pbufs are used). */
u16_t inet_chksum_pbuf(struct pbuf *p)
{
  u32_t acc;
  struct pbuf *q;
  int swapped = 0;
  acc = 0;
  for (q = p; q != NULL; q = q->next) {
    acc += LWIP_CHKSUM(q->payload, q->len);
    acc = FOLD_U32T(acc);
    if (q->len % 2 != 0) {
      swapped = !swapped;
      acc = SWAP_BYTES_IN_WORD(acc);
    }
  }
  if (swapped) {
    acc = SWAP_BYTES_IN_WORD(acc);
  }
  return (u16_t)~(acc & 0xffffUL);
}