/* Compare pbuf contents at specified offset with memory s2, both of length n */
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
/* Compare pbuf contents at specified offset with memory s2, both of length n */
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
{
  u16_t start = offset;
  const struct pbuf* q = p;
  u16_t i;
  if(p->tot_len < (offset + n)) {
    return 0xffff;
  }
  while ((q != NULL) && (q->len <= start)) {
    start -= q->len;
    q = q->next;
  }
  for (i = 0; i < n; i++) {
    u8_t a = pbuf_get_at(q, start + i);
    u8_t b = ((const u8_t*)s2)[i];
    if (a != b) {
      return i+1;
    }
  }
  return 0;
}