* @ingroup netbuf * Let a netbuf reference existing (non-volatile) data. * * @param buf netbuf which should reference the data * @param dataptr pointer to the data to reference * @param size size of the data * @return ERR_OK if data is referenced * ERR_MEM if data couldn't be referenced due to lack of memory */
| 148 | * ERR_MEM if data couldn't be referenced due to lack of memory |
| 149 | */ |
| 150 | err_t |
| 151 | netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size) |
| 152 | { |
| 153 | LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;); |
| 154 | if (buf->p != NULL) { |
| 155 | pbuf_free(buf->p); |
| 156 | } |
| 157 | buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF); |
| 158 | if (buf->p == NULL) { |
| 159 | buf->ptr = NULL; |
| 160 | return ERR_MEM; |
| 161 | } |
| 162 | ((struct pbuf_rom *)buf->p)->payload = dataptr; |
| 163 | buf->p->len = buf->p->tot_len = size; |
| 164 | buf->ptr = buf->p; |
| 165 | return ERR_OK; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @ingroup netbuf |
no test coverage detected