Example #1
0
/**
 * Parse the per-hop headers.
 *
 * Will return the absolute offset of the next byte to parse (i.e. 'endHeaders')
 *
 * @param [in] packet The packet buffer
 * @param [in] offset The first byte to begin parsing at
 * @param [in] endMessage The ceiling of bytes to parse
 * @param [in] skeleton The structure to fill in
 */
static void
_parsePerHopV1(const uint8_t *packet, size_t offset, size_t endHeaders, MetisTlvSkeleton *skeleton)
{
    const size_t tl_length = sizeof(MetisTlvType);

    // we only parse to the end of the per-hop headers or until we've found
    // the 2 headers we want (hoplimit, fragmentation header)
    while (offset + sizeof(MetisTlvType) < endHeaders) {
        const MetisTlvType *tlv = (MetisTlvType *) (packet + offset);
        const uint16_t type = htons(tlv->type);
        const uint16_t v_length = htons(tlv->length);

        // move past the TL header
        offset += tl_length;

        size_t endSubSection = offset + v_length;
        if (endSubSection <= endHeaders) {
            switch (type) {
                case T_INTLIFE:
                    metisTlvSkeleton_SetInterestLifetime(skeleton, offset, v_length);
                    break;

                // should verify that we dont have both INTFRAG and OBJFRAG
                case T_CACHETIME:
                    metisTlvSkeleton_SetCacheTimeHeader(skeleton, offset, v_length);
                    break;

                default:
                    break;
            }
        }

        offset = endSubSection;
    }
}
Example #2
0
static void
_parseInterestV0(const uint8_t *packet, size_t offset, size_t endMessage, MetisTlvSkeleton *skeleton)
{
    int foundCount = 0;
    const size_t tl_length = sizeof(MetisTlvType);

    // skip the Interest wrapper
    offset += 4;

    // parse to the end or until we find all 5 things (name, keyid, objecthash, scope, interest lifetime)
    while (offset < endMessage && foundCount < 5) {
        MetisTlvType *tlv = (MetisTlvType *) (packet + offset);
        uint16_t type = htons(tlv->type);
        uint16_t v_length = htons(tlv->length);

        // skip past the TLV header
        offset += tl_length;

        switch (type) {
            case T_NAME:
                metisTlvSkeleton_SetName(skeleton, offset, v_length);
                foundCount++;
                break;

            case T_KEYID:
                metisTlvSkeleton_SetKeyId(skeleton, offset, v_length);
                foundCount++;
                break;

            case T_OBJHASH:
                metisTlvSkeleton_SetObjectHash(skeleton, offset, v_length);
                foundCount++;
                break;

            case T_INTLIFE:
                metisTlvSkeleton_SetInterestLifetime(skeleton, offset, v_length);
                foundCount++;
                break;

            default:
                break;
        }

        offset += v_length;
    }
}