Exemplo n.º 1
0
bool probe_extract_ext(const probe_t * probe, const char * name, size_t depth, void * value) {
    size_t                   i, num_layers = probe_get_num_layers(probe);
    const layer_t          * layer;
    const protocol_field_t * protocol_field;

    // We go through the layers until we get the required field
    for(i = depth; i < num_layers; i++) {
        layer = probe_get_layer(probe, i);
        if (!(protocol_field = layer_get_protocol_field(layer, name))) continue;

        // Hack to convert ipv*_t extracted into address_t value.
        switch (protocol_field->type) {
            case TYPE_IPV4:
                memset(value, 0, sizeof(address_t));
                ((address_t *) value)->family = AF_INET;
                value = &((address_t *) value)->ip.ipv4;
                break;
            case TYPE_IPV6:
                memset(value, 0, sizeof(address_t));
                ((address_t *) value)->family = AF_INET6;
                value = &((address_t *) value)->ip.ipv6;
                break;
            default: break;
        }

        if ((layer = probe_get_layer(probe, i))
        &&   layer_extract(layer, name, value)) {
            return true;
        }
    }

    return false;
}
Exemplo n.º 2
0
const protocol_t * icmpv4_get_next_protocol(const layer_t * icmpv4_layer) {
    const protocol_t * next_protocol = NULL;
    uint8_t            icmpv4_type;

    if (layer_extract(icmpv4_layer, "type", &icmpv4_type)) {
        switch (icmpv4_type) {
            case ICMP_DEST_UNREACH:
            case ICMP_TIME_EXCEEDED:
                next_protocol = protocol_search("ipv4");
                break;
            default:
                break;
        }
    }
    return next_protocol;
}