os_mbuf_copyinto

int os_mbuf_copyinto(struct os_mbuf *om, int off, const void *src, int len);

Copies the contents of a flat buffer into an mbuf chain, starting at the specified destination offset. If the mbuf is too small for the source data, it is extended as necessary. If the destination mbuf contains a packet header, the header length is updated.

Arguments

ArgumentsDescription
omPointer to mbuf chain
offStart copy offset, in bytes, from beginning of mbuf chain
srcAddress from which bytes are copied
lenNumber of bytes to copy from src

Returned values

0: success.
All other values indicate an error.

Example

    int rc;
    uint16_t pktlen;
	struct os_mbuf *om;
    struct my_data_struct my_data;	
	
    /* Get initial packet length */
    pktlen = OS_MBUF_PKTLEN(om);

    /* Copy "my_data" into mbuf */
    rc = os_mbuf_copyinto(om, 0, &my_data, sizeof(struct my_data_struct));
    if (rc) {
        os_mbuf_free_chain(om);
        return;
    }

    /* Packet length should have increased by size of "my_data" */
    pktlen += sizeof(struct my_data_struct);
    assert(pktlen == OS_MBUF_PKTLEN(om));