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