Exemplo n.º 1
0
// write Content packet *before* buf[offs], adjust offs and return bytes used
int
ccnl_ccntlv_prependContentWithHdr(struct ccnl_prefix_s *name,
                                  unsigned char *payload, int paylen,
                                  unsigned int *lastchunknum, int *contentpos,
                                  int *offset, unsigned char *buf)
{
    int len, oldoffset;
    unsigned char hoplimit = 255; // setting to max (content has no hoplimit)

    oldoffset = *offset;

    len = ccnl_ccntlv_prependContent(name, payload, paylen, lastchunknum,
                                     contentpos, offset, buf);
    if (len < 0)
        return -1;

    if ((unsigned int)len >= ((uint32_t)1 << 16) - sizeof(struct ccnx_tlvhdr_ccnx2015_s))
        return -1;

    if (ccnl_ccntlv_prependFixedHdr(CCNX_TLV_V1, CCNX_PT_Data,
                                    len, hoplimit, offset, buf) < 0)
        return -1;

    return oldoffset - *offset;
}
Exemplo n.º 2
0
// write Content packet *before* buf[offs], adjust offs and return bytes used
int8_t
ccnl_ccntlv_prependContentWithHdr(struct ccnl_prefix_s *name,
                                  uint8_t *payload, size_t paylen,
                                  uint32_t *lastchunknum, size_t *contentpos,
                                  size_t *offset, uint8_t *buf, size_t *reslen)
{
    size_t len, oldoffset;
    uint8_t hoplimit = 255; // setting to max (content has no hoplimit)

    oldoffset = *offset;

    if (ccnl_ccntlv_prependContent(name, payload, paylen, lastchunknum,
                                   contentpos, offset, buf, &len)) {
        return -1;
    }

    if (len > (UINT16_MAX - sizeof(struct ccnx_tlvhdr_ccnx2015_s))) {
        return -1;
    }

    if (ccnl_ccntlv_prependFixedHdr(CCNX_TLV_V1, CCNX_PT_Data,
                                    len, hoplimit, offset, buf)) {
        return -1;
    }

    *reslen = oldoffset - *offset;
    return 0;
}