Include <string.h> to get "strcmp()" declared.
[obnox/wireshark/wip.git] / packet-tftp.c
index bc7df10c85a7219a12d4701897bf4407d8e9032f..493df31a96e2d1b04000f2c527cf372dbae1ff13 100644 (file)
@@ -5,24 +5,24 @@
  * Craig Newell <CraigN@cheque.uq.edu.au>
  *     RFC2347 TFTP Option Extension
  *
- * $Id: packet-tftp.c,v 1.35 2002/01/21 07:36:44 guy Exp $
+ * $Id: packet-tftp.c,v 1.40 2002/08/28 21:00:36 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-bootp.c
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <glib.h>
 #include <epan/packet.h>
 #include <epan/conversation.h>
@@ -85,6 +77,7 @@ static const value_string tftp_error_code_vals[] = {
   { 5, "Unknown transfer ID" },
   { 6, "File already exists" },
   { 7, "No such user" },
+  { 8, "Option negotiation failed" },
   { 0, NULL }
 };
 
@@ -98,7 +91,9 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        conversation_t  *conversation;
        gint            offset = 0;
        guint16         opcode;
-       u_int           i1;
+       guint16         bytes;
+       guint16         blocknum;
+       guint           i1;
        guint16         error;
 
        /*
@@ -143,15 +138,14 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        if (tree) {
 
-         ti = proto_tree_add_item(tree, proto_tftp, tvb, offset,
-                           tvb_length_remaining(tvb, offset), FALSE);
+         ti = proto_tree_add_item(tree, proto_tftp, tvb, offset, -1, FALSE);
          tftp_tree = proto_item_add_subtree(ti, ett_tftp);
 
          proto_tree_add_uint(tftp_tree, hf_tftp_opcode, tvb,
                            offset, 2, opcode);
        }
        offset += 2;
-           
+
        switch (opcode) {
 
        case TFTP_RRQ:
@@ -209,30 +203,36 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
          break;
 
        case TFTP_DATA:
+         blocknum = tvb_get_ntohs(tvb, offset);
          if (tree) {
-           proto_tree_add_item(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
-                           FALSE);
+           proto_tree_add_uint(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
+                           blocknum);
          }
+         offset += 2;
+
+         bytes = tvb_reported_length_remaining(tvb, offset);
+
          if (check_col(pinfo->cinfo, COL_INFO)) {
-           col_append_fstr(pinfo->cinfo, COL_INFO, ", Block: %i",
-                           tvb_get_ntohs(tvb, offset));
+           col_append_fstr(pinfo->cinfo, COL_INFO, ", Block: %i%s",
+                   blocknum,
+                   (bytes < 512)?" (last)":"" );
          }
-         offset += 2;
 
          if (tree) {
-           proto_tree_add_text(tftp_tree, tvb, offset, tvb_length_remaining(tvb, offset),
-               "Data (%d bytes)", tvb_length_remaining(tvb, offset));
+           proto_tree_add_text(tftp_tree, tvb, offset, -1,
+               "Data (%d bytes)", bytes);
          }
          break;
 
        case TFTP_ACK:
+         blocknum = tvb_get_ntohs(tvb, offset);
          if (tree) {
-           proto_tree_add_item(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
-                           FALSE);
+           proto_tree_add_uint(tftp_tree, hf_tftp_blocknum, tvb, offset, 2,
+                           blocknum);
          }
          if (check_col(pinfo->cinfo, COL_INFO)) {
            col_append_fstr(pinfo->cinfo, COL_INFO, ", Block: %i",
-                           tvb_get_ntohs(tvb, offset));
+                           blocknum);
          }
          break;
 
@@ -266,8 +266,8 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        default:
          if (tree) {
-           proto_tree_add_text(tftp_tree, tvb, offset, tvb_length_remaining(tvb, offset),
-               "Data (%d bytes)", tvb_length_remaining(tvb, offset));
+           proto_tree_add_text(tftp_tree, tvb, offset, -1,
+               "Data (%d bytes)", tvb_reported_length_remaining(tvb, offset));
          }
          break;