more
authorStefan Metzmacher <metze@samba.org>
Tue, 21 Nov 2017 16:43:37 +0000 (17:43 +0100)
committerStefan Metzmacher <metze@samba.org>
Sun, 20 Jan 2019 22:14:58 +0000 (23:14 +0100)
Change-Id: I728c27b95edb2c47d708ec89b31a404e4a30e4cb

epan/dissectors/packet-nmf.c

index 53e16d65dc8389186485d320219cab0dac714e66..48fd7c4c24fa3e974db2d891dbff0648f0e569de 100644 (file)
@@ -43,7 +43,7 @@ static int hf_nmf_record_type = -1;
 static int hf_nmf_version_major = -1;
 static int hf_nmf_version_minor = -1;
 static int hf_nmf_mode_value = -1;
 static int hf_nmf_version_major = -1;
 static int hf_nmf_version_minor = -1;
 static int hf_nmf_mode_value = -1;
-static int hf_nmf_length = -1;
+static int hf_nmf_via_length = -1;
 
 enum nmf_record_type {
        NMF_VERSION_RECORD              = 0x00,
 
 enum nmf_record_type {
        NMF_VERSION_RECORD              = 0x00,
@@ -85,17 +85,36 @@ static const value_string mode_values[] = {
        { 0, NULL }
 };
 
        { 0, NULL }
 };
 
-#if 0
 static int
 static int
-dissect_nmf_record_size(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
-                       int offset, guint32 *_size)
+dissect_nmf_record_size(tvbuff_t *tvb, proto_tree *tree,
+                       int hf_index, int offset, guint32 *_size)
 {
 {
+       proto_item *item = NULL;
+       guint8 byte = tvb_get_guint8(tvb, offset);
+       guint32 size = 0;
+       guint8 shift = 0;
+       int start_offset = offset;
+
+       do {
+               byte = tvb_get_guint8(tvb, offset);
+               offset += 1;
+
+               size |= (guint32)(byte & 0x7F) << shift;
+               shift += 7;
+       } while (byte & 0x80);
+
        if (_size != NULL) {
        if (_size != NULL) {
-               *_size = 0;
+               *_size = size;
        }
        }
+
+       item = proto_tree_add_item(tree, hf_index, tvb,
+                                  start_offset, -1, ENC_NA);
+       proto_item_set_end(item, tvb, offset);
+       proto_item_append_text(item, ": %u (0x%x)",
+                               (guint)size, (guint)size);
+
        return offset;
 }
        return offset;
 }
-#endif
 
 static int
 dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
 
 static int
 dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
@@ -104,6 +123,7 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offs
        proto_tree *record_tree = NULL;
        const gchar *record_name = NULL;
        enum nmf_record_type record_type;
        proto_tree *record_tree = NULL;
        const gchar *record_name = NULL;
        enum nmf_record_type record_type;
+       guint32 size = 0;
 
        record_item = proto_tree_add_item(tree, hf_nmf_record, tvb, offset, -1, ENC_NA);
        proto_item_append_text(record_item, ", start_offset=0x%x, ", (guint)offset);
 
        record_item = proto_tree_add_item(tree, hf_nmf_record, tvb, offset, -1, ENC_NA);
        proto_item_append_text(record_item, ", start_offset=0x%x, ", (guint)offset);
@@ -135,7 +155,18 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offs
                offset += 1;
                break;
        case NMF_VIA_RECORD:
                offset += 1;
                break;
        case NMF_VIA_RECORD:
+               offset = dissect_nmf_record_size(tvb, record_tree,
+                                                hf_nmf_via_length,
+                                                offset, &size);
+               if (offset <= 0) {
+                       return -1;
+               }
+
+               offset += size;
+               break;
        case NMF_KNOWN_ENCODING_RECORD:
        case NMF_KNOWN_ENCODING_RECORD:
+               offset += 1;
+               break;
        case NMF_EXTENSIBLE_ENCODING_RECORD:
        case NMF_UNSIZED_ENVELOPE_RECORD:
        case NMF_SIZED_ENVELOPE_RECORD:
        case NMF_EXTENSIBLE_ENCODING_RECORD:
        case NMF_UNSIZED_ENVELOPE_RECORD:
        case NMF_SIZED_ENVELOPE_RECORD:
@@ -145,7 +176,6 @@ dissect_nmf_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offs
        case NMF_UPGRADE_RESPONSE_RECORD:
        case NMF_PREAMBLE_ACK_RECORD:
        case NMF_PREAMBLE_END_RECORD:
        case NMF_UPGRADE_RESPONSE_RECORD:
        case NMF_PREAMBLE_ACK_RECORD:
        case NMF_PREAMBLE_END_RECORD:
-               offset += 2;
                break;
        }
 
                break;
        }
 
@@ -208,9 +238,9 @@ void proto_register_nmf(void)
        { &hf_nmf_mode_value,
                { "Mode", "nmf.mode.value",
                FT_UINT8, BASE_DEC, VALS(mode_values), 0, NULL, HFILL }},
        { &hf_nmf_mode_value,
                { "Mode", "nmf.mode.value",
                FT_UINT8, BASE_DEC, VALS(mode_values), 0, NULL, HFILL }},
-       { &hf_nmf_length,
-               { "Length", "nmf.length",
-               FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL }},
+       { &hf_nmf_via_length,
+               { "Length", "nmf.via.length",
+               FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
        };
 
        proto_nmf = proto_register_protocol("NMF (.NET Message Framing Protocol)",
        };
 
        proto_nmf = proto_register_protocol("NMF (.NET Message Framing Protocol)",