MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pbuf_copy_partial

Function pbuf_copy_partial

components/net/lwip/lwip-2.1.2/src/core/pbuf.c:1026–1057  ·  view source on GitHub ↗

* @ingroup pbuf * Copy (part of) the contents of a packet buffer * to an application supplied buffer. * * @param buf the pbuf from which to copy data * @param dataptr the application supplied buffer * @param len length of data to copy (dataptr must be big enough). No more * than buf->tot_len will be copied, irrespective of len * @param offset offset into the packet buffer from where to beg

Source from the content-addressed store, hash-verified

1024 * @return the number of bytes copied, or 0 on failure
1025 */
1026u16_t
1027pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
1028{
1029 const struct pbuf *p;
1030 u16_t left = 0;
1031 u16_t buf_copy_len;
1032 u16_t copied_total = 0;
1033
1034 LWIP_ERROR("pbuf_copy_partial: invalid buf", (buf != NULL), return 0;);
1035 LWIP_ERROR("pbuf_copy_partial: invalid dataptr", (dataptr != NULL), return 0;);
1036
1037 /* Note some systems use byte copy if dataptr or one of the pbuf payload pointers are unaligned. */
1038 for (p = buf; len != 0 && p != NULL; p = p->next) {
1039 if ((offset != 0) && (offset >= p->len)) {
1040 /* don't copy from this buffer -> on to the next */
1041 offset = (u16_t)(offset - p->len);
1042 } else {
1043 /* copy from this buffer. maybe only partially. */
1044 buf_copy_len = (u16_t)(p->len - offset);
1045 if (buf_copy_len > len) {
1046 buf_copy_len = len;
1047 }
1048 /* copy the necessary parts of the buffer */
1049 MEMCPY(&((char *)dataptr)[left], &((char *)p->payload)[offset], buf_copy_len);
1050 copied_total = (u16_t)(copied_total + buf_copy_len);
1051 left = (u16_t)(left + buf_copy_len);
1052 len = (u16_t)(len - buf_copy_len);
1053 offset = 0;
1054 }
1055 }
1056 return copied_total;
1057}
1058
1059/**
1060 * @ingroup pbuf

Callers 15

pbuf_get_contiguousFunction · 0.70
dns_recvFunction · 0.70
tcp_split_unsent_segFunction · 0.70
tcp_zero_window_probeFunction · 0.70
virtio_net_txFunction · 0.50
rw009_wifi_txFunction · 0.50
START_TESTFunction · 0.50
START_TESTFunction · 0.50
nd6_inputFunction · 0.50

Calls

no outgoing calls

Tested by 3

START_TESTFunction · 0.40
START_TESTFunction · 0.40