Make the "Save only marked frames" button in the "Save As..." dialog box
[obnox/wireshark/wip.git] / packet-tftp.c
index 6cc90fec1da989f3a7ddb8a41f51766c2f9de3b2..5aec3d5bdf1aae28e8dc65a8c720bcb5bcf3421f 100644 (file)
@@ -5,7 +5,7 @@
  * Craig Newell <CraigN@cheque.uq.edu.au>
  *     RFC2347 TFTP Option Extension
  *
- * $Id: packet-tftp.c,v 1.29 2001/11/03 02:19:10 guy Exp $
+ * $Id: packet-tftp.c,v 1.33 2001/12/03 03:59:40 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -55,6 +55,8 @@ static int hf_tftp_error_string = -1;
 
 static gint ett_tftp = -1;
 
+static dissector_handle_t tftp_handle;
+
 #define UDP_PORT_TFTP    69
 
 #define        TFTP_RRQ        1
@@ -97,10 +99,7 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        gint            offset = 0;
        guint16         opcode;
        u_int           i1;
-
-       CHECK_DISPLAY_AS_DATA(proto_tftp, tvb, pinfo, tree);
-
-       pinfo->current_proto = "TFTP";
+       guint16         error;
 
        /*
         * The first TFTP packet goes to the TFTP port; the second one
@@ -126,7 +125,7 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
          if (conversation == NULL) {
            conversation = conversation_new(&pinfo->src, &pinfo->dst, PT_UDP,
                                            pinfo->srcport, 0, NO_PORT2);
-           conversation_set_dissector(conversation, dissect_tftp);
+           conversation_set_dissector(conversation, tftp_handle);
          }
        }
 
@@ -238,21 +237,26 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
          break;
 
        case TFTP_ERROR:
+         error = tvb_get_ntohs(tvb, offset);
          if (tree) {
-           proto_tree_add_item(tftp_tree, hf_tftp_error_code, tvb, offset, 2,
-                           FALSE);
+           proto_tree_add_uint(tftp_tree, hf_tftp_error_code, tvb, offset, 2,
+                           error);
          }
          if (check_col(pinfo->fd, COL_INFO)) {
-           col_append_fstr(pinfo->fd, COL_INFO, ", Code: %i",
-                           tvb_get_ntohs(tvb, offset));
+           col_append_fstr(pinfo->fd, COL_INFO, ", Code: %s",
+                           val_to_str(error, tftp_error_code_vals, "Unknown (%u)"));
          }
          offset += 2;
 
+         i1 = tvb_strsize(tvb, offset);
          if (tree) {
-           i1 = tvb_strsize(tvb, offset);
            proto_tree_add_item(tftp_tree, hf_tftp_error_string, tvb, offset,
                i1, FALSE);
          }
+         if (check_col(pinfo->fd, COL_INFO)) {
+           col_append_fstr(pinfo->fd, COL_INFO, ", Message: %s",
+                           tvb_get_ptr(tvb, offset, i1));
+         }
          break;
 
        case TFTP_OACK:
@@ -335,10 +339,12 @@ proto_register_tftp(void)
                                       "TFTP", "tftp");
   proto_register_field_array(proto_tftp, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
+
+  tftp_handle = create_dissector_handle(dissect_tftp, proto_tftp);
 }
 
 void
 proto_reg_handoff_tftp(void)
 {
-  dissector_add("udp.port", UDP_PORT_TFTP, dissect_tftp, proto_tftp);
+  dissector_add("udp.port", UDP_PORT_TFTP, tftp_handle);
 }