Esempio n. 1
0
static void
_parsePerHopV0(const uint8_t *packet, size_t offset, size_t endHeaders, MetisTlvSkeleton *skeleton)
{
    int foundCount = 0;
    const size_t tl_length = 4;

    // we only parse to the end of the per-hop headers or until we've found
    // the 1 header we want is hoplimit.  Others ignored.
    while (offset < endHeaders && foundCount < 1) {
        MetisTlvType *tlv = (MetisTlvType *) (packet + offset);
        uint16_t type = htons(tlv->type);
        uint16_t v_length = htons(tlv->length);

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

        switch (type) {
            case T_HOPLIMIT:
                metisTlvSkeleton_SetHopLimit(skeleton, offset, v_length);
                foundCount++;
                break;

            default:
                break;
        }

        offset += v_length;
    }
}
Esempio n. 2
0
static bool
_parse(MetisTlvSkeleton *skeleton)
{
    bool success = false;

    _MetisTlvFixedHeaderV1 *hdr = (_MetisTlvFixedHeaderV1 *) metisTlvSkeleton_GetPacket(skeleton);

    // this function should only be called for version 1 packets
    trapUnexpectedStateIf(hdr->version != 1, "Version not 1");

    if (_goodPacketType(hdr->packetType) && hdr->headerLength >= sizeof(_MetisTlvFixedHeaderV1)) {
        size_t endHeaders = hdr->headerLength;
        size_t endPacket = htons(hdr->packetLength);

        if (endPacket >= endHeaders) {
            if (_isPacketTypeInterest((uint8_t *) hdr)) {
                metisTlvSkeleton_SetHopLimit(skeleton, 4, 1);
            }

            _parsePerHopV1(metisTlvSkeleton_GetPacket(skeleton), sizeof(_MetisTlvFixedHeaderV1), endHeaders, skeleton);
            size_t offset = _parseMessage(metisTlvSkeleton_GetPacket(skeleton), endHeaders, endPacket, skeleton);
            _parseValidationAlg(metisTlvSkeleton_GetPacket(skeleton), offset, endPacket, skeleton);
            success = true;
        }
    }

    return success;
}