Ejemplo n.º 1
0
static void dissect_user(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
    user_encap_t* encap = NULL;
    tvbuff_t* payload_tvb;
    proto_item* item;
    gint len, reported_len;
    guint i;

    for (i = 0; i < num_encaps; i++) {
        if (encaps[i].encap == pinfo->match_uint) {
            encap = &(encaps[i]);
            break;
        }
    }

    item = proto_tree_add_item(tree,proto_user_encap,tvb,0,-1,ENC_NA);
    if (!encap) {
        char* msg = ep_strdup_printf("User encapsulation not handled: DLT=%d, "
                                     "check your Preferences->Protocols->DLT_USER",
                         pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
        proto_item_set_text(item,"%s",msg);
        expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN, "%s", msg);

        call_dissector(data_handle, tvb, pinfo, tree);
        return;
    }
    if (encap->payload_proto == NULL) {
        char* msg = ep_strdup_printf("User encapsulation's protocol %s not found: "
                                     "DLT=%d, check your Preferences->Protocols->DLT_USER",
                                     encap->payload_proto_name,
                                     pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
        proto_item_set_text(item,"%s",msg);
        expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN, "%s", msg);

        call_dissector(data_handle, tvb, pinfo, tree);
        return;
    }

    proto_item_set_text(item,"DLT: %d",pinfo->match_uint + 147 - WTAP_ENCAP_USER0);

    if (encap->header_size) {
        tvbuff_t* hdr_tvb = tvb_new_subset(tvb, 0, encap->header_size, encap->header_size);
        call_dissector(encap->header_proto, hdr_tvb, pinfo, tree);
        if (encap->header_proto_name) {
            const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->header_proto_name));
            if (proto_name) {
                proto_item_append_text(item, ", Header: %s (%s)", encap->header_proto_name, proto_name);
            }
        }
    }

    len = tvb_length(tvb) - (encap->header_size + encap->trailer_size);
    reported_len = tvb_reported_length(tvb) - (encap->header_size + encap->trailer_size);

    payload_tvb = tvb_new_subset(tvb, encap->header_size, len, reported_len);
    call_dissector(encap->payload_proto, payload_tvb, pinfo, tree);
    if (encap->payload_proto_name) {
        const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->payload_proto_name));
        if (proto_name) {
            proto_item_append_text(item, ", Payload: %s (%s)", encap->payload_proto_name, proto_name);
        }
    }

    if (encap->trailer_size) {
        tvbuff_t* trailer_tvb = tvb_new_subset(tvb, encap->header_size + len, encap->trailer_size, encap->trailer_size);
        call_dissector(encap->trailer_proto, trailer_tvb, pinfo, tree);
        if (encap->trailer_proto_name) {
            const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->trailer_proto_name));
            if (proto_name) {
                proto_item_append_text(item, ", Trailer: %s (%s)", encap->trailer_proto_name, proto_name);
            }
        }
    }
}
Ejemplo n.º 2
0
static void dissect_user(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree) {
    user_encap_t* encap = NULL;
    tvbuff_t* payload_tvb;
    proto_item* item;
    gint len, reported_len;
    guint i;

    for (i = 0; i < num_encaps; i++) {
        if (encaps[i].encap == pinfo->match_uint) {
            encap = &(encaps[i]);
            break;
        }
    }

    item = proto_tree_add_item(tree,proto_user_encap,tvb,0,-1,ENC_NA);
    if (!encap && pinfo->match_uint == WTAP_ENCAP_USER2) {
        /*
         * Special-case DLT_USER2 - Apple hijacked it for use as DLT_PKTAP.
         * The user hasn't assigned anything to it, so default it to
         * the PKTAP dissector.
         */
        encap = &user2_encap;
    }
    if (!encap) {
        char* msg = wmem_strdup_printf(wmem_packet_scope(),
                                     "User encapsulation not handled: DLT=%d, "
                                     "check your Preferences->Protocols->DLT_USER",
                         pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
        proto_item_set_text(item,"%s",msg);
        expert_add_info_format(pinfo, item, &ei_user_encap_not_handled, "%s", msg);

        call_dissector(data_handle, tvb, pinfo, tree);
        return;
    }
    if (encap->payload_proto == NULL) {
        char* msg = wmem_strdup_printf(wmem_packet_scope(),
                                     "User encapsulation's protocol %s not found: "
                                     "DLT=%d, check your Preferences->Protocols->DLT_USER",
                                     encap->payload_proto_name,
                                     pinfo->match_uint + 147 - WTAP_ENCAP_USER0);
        proto_item_set_text(item,"%s",msg);
        expert_add_info_format(pinfo, item, &ei_user_encap_not_handled, "%s", msg);

        call_dissector(data_handle, tvb, pinfo, tree);
        return;
    }

    proto_item_set_text(item,"DLT: %d",pinfo->match_uint + 147 - WTAP_ENCAP_USER0);

    if (encap->header_size) {
        tvbuff_t* hdr_tvb = tvb_new_subset_length(tvb, 0, encap->header_size);
        call_dissector(encap->header_proto, hdr_tvb, pinfo, tree);
        if (encap->header_proto_name) {
            const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->header_proto_name));
            if (proto_name) {
                proto_item_append_text(item, ", Header: %s (%s)", encap->header_proto_name, proto_name);
            }
        }
    }

    len = tvb_captured_length(tvb) - (encap->header_size + encap->trailer_size);
    reported_len = tvb_reported_length(tvb) - (encap->header_size + encap->trailer_size);

    payload_tvb = tvb_new_subset(tvb, encap->header_size, len, reported_len);
    call_dissector(encap->payload_proto, payload_tvb, pinfo, tree);
    if (encap->payload_proto_name) {
        const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->payload_proto_name));
        if (proto_name) {
            proto_item_append_text(item, ", Payload: %s (%s)", encap->payload_proto_name, proto_name);
        }
    }

    if (encap->trailer_size) {
        tvbuff_t* trailer_tvb = tvb_new_subset_length(tvb, encap->header_size + len, encap->trailer_size);
        call_dissector(encap->trailer_proto, trailer_tvb, pinfo, tree);
        if (encap->trailer_proto_name) {
            const char *proto_name = dissector_handle_get_long_name(find_dissector(encap->trailer_proto_name));
            if (proto_name) {
                proto_item_append_text(item, ", Trailer: %s (%s)", encap->trailer_proto_name, proto_name);
            }
        }
    }
}