added pbuf_try_get_at() (much like pbuf_get_at() but can return out-of-pbuf error)

This commit is contained in:
sg 2016-08-30 21:31:00 +02:00
parent 8d45162a59
commit a08ed9148d
2 changed files with 21 additions and 2 deletions

View File

@ -1223,7 +1223,7 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
}
#endif /* LWIP_CHECKSUM_ON_COPY */
/**
/**
* @ingroup pbuf
* Get one byte from the specified position in a pbuf
* WARNING: returns zero for offset >= p->tot_len
@ -1234,6 +1234,24 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr,
*/
u8_t
pbuf_get_at(struct pbuf* p, u16_t offset)
{
int ret = pbuf_try_get_at(p, offset);
if (ret >= 0) {
return (u8_t)ret;
}
return 0;
}
/**
* @ingroup pbuf
* Get one byte from the specified position in a pbuf
*
* @param p pbuf to parse
* @param offset offset into p of the byte to return
* @return byte at an offset into p [0..0xFF] OR negative if 'offset' >= p->tot_len
*/
int
pbuf_try_get_at(struct pbuf* p, u16_t offset)
{
u16_t q_idx;
struct pbuf* q = pbuf_skip(p, offset, &q_idx);
@ -1242,7 +1260,7 @@ pbuf_get_at(struct pbuf* p, u16_t offset)
if ((q != NULL) && (q->len > q_idx)) {
return ((u8_t*)q->payload)[q_idx];
}
return 0;
return -1;
}
/**

View File

@ -250,6 +250,7 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest);
#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
u8_t pbuf_get_at(struct pbuf* p, u16_t offset);
int pbuf_try_get_at(struct pbuf* p, u16_t offset);
void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data);
u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n);
u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset);