static void _parseControlPlaneInterface(const uint8_t *packet, size_t offset, size_t endMessage, MetisTlvSkeleton *skeleton) { int foundCount = 0; const size_t tl_length = 4; // parse to the end or until we find all 5 things (name, keyid, objecthash, scope, interest lifetime) while (offset < endMessage && foundCount < 1) { 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_CPI: metisTlvSkeleton_SetCPI(skeleton, offset, v_length); foundCount++; break; default: break; } offset += v_length; } }
/** * Parses the message body * * 'offset' should point to the first byte of the T_INTEREST, T_CONTENTOBJECT, etc. * * @param [<#in#> | <#out#> | <#in,out#>] <#name#> <#description#> * * @return number The absolute byte offset of the next location to parse * * Example: * @code * { * <#example#> * } * @endcode */ static size_t _parseMessage(const uint8_t *packet, size_t offset, size_t endMessage, struct tlv_skeleton *skeleton) { size_t endSection = endMessage; if (offset + sizeof(MetisTlvType) < endMessage) { const MetisTlvType *tlv = (MetisTlvType *) (packet + offset); const uint16_t type = htons(tlv->type); const uint16_t v_length = htons(tlv->length); offset += sizeof(MetisTlvType); size_t endSubSection = offset + v_length; // make sure we don't have container overrun if (endSubSection <= endMessage) { switch (type) { case T_INTEREST: _parseInterestV1(packet, offset, endSubSection, skeleton); break; case T_MANIFEST: case T_OBJECT: _parseObjectV1(packet, offset, endSubSection, skeleton); break; case T_CPI: // There is nothing nested here, its just the value metisTlvSkeleton_SetCPI(skeleton, offset, v_length); break; case T_HOPFRAG_PAYLOAD: // There is nothing nested here, its just the value metisTlvSkeleton_SetFragmentPayload(skeleton, offset, v_length); break; default: break; } endSection = endSubSection; } } return endSection; }