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; } }
/** * Parse the "value" of a T_INTEREST * * 'offset' should point to the first byte of the "value" of the T_INTEREST container * * @param [in] packet The packet buffer * @param [in] offset The first byte to begin parsing at * @param [in] endSection The ceiling of bytes to parse * @param [in] skeleton The structure to fill in * * Example: * @code * { * <#example#> * } * @endcode */ static void _parseInterestV1(const uint8_t *packet, size_t offset, size_t endSection, struct tlv_skeleton *skeleton) { int foundCount = 0; // parse to the end or until we find all 3 things (name, keyid, objecthash) while (offset < endSection && foundCount < 3) { const MetisTlvType *tlv = (MetisTlvType *) (packet + offset); const uint16_t type = htons(tlv->type); const uint16_t v_length = htons(tlv->length); // skip past the TLV header offset += sizeof(MetisTlvType); size_t endSubSection = offset + v_length; if (endSubSection <= endSection) { switch (type) { case T_NAME: metisTlvSkeleton_SetName(skeleton, offset, v_length); foundCount++; break; case T_KEYIDRES: metisTlvSkeleton_SetKeyId(skeleton, offset, v_length); foundCount++; break; case T_OBJHASHRES: metisTlvSkeleton_SetObjectHash(skeleton, offset, v_length); foundCount++; break; default: break; } } offset = endSubSection; } }