// write Interest packet *before* buf[offs], adjust offs and return bytes used
int
ccnl_ccntlv_prependChunkInterestWithHdr(struct ccnl_prefix_s *name,
                                        int *offset, unsigned char *buf)
{
    int len, oldoffset;
    unsigned char hoplimit = 64; // setting hoplimit to max valid value?

    oldoffset = *offset;
    len = ccnl_ccntlv_prependInterest(name, offset, buf);
    if ( (unsigned int)len >= ((1 << 16) - sizeof(struct ccnx_tlvhdr_ccnx2015_s)))
        return -1;

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

    return oldoffset - *offset;
}
Esempio n. 2
0
// write Interest packet *before* buf[offs], adjust offs and return bytes used
int8_t
ccnl_ccntlv_prependChunkInterestWithHdr(struct ccnl_prefix_s *name,
                                        size_t *offset, uint8_t *buf, size_t *reslen)
{
    size_t len, oldoffset;
    uint8_t hoplimit = 64; // setting hoplimit to max valid value?

    oldoffset = *offset;
    if (ccnl_ccntlv_prependInterest(name, 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_Interest,
                                    len, hoplimit, offset, buf)) {
        return -1;
    }

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