Note that for THE3GPP_IPV6_DNS_SERVERS we probably *do* need to handle
[obnox/wireshark/wip.git] / packet-tftp.c
index 7304ae5ebfcaa5c3ed5f6938682b5539b335a533..e559e47a4c15adf70bfb7c45e54ef396be4471bf 100644 (file)
@@ -5,24 +5,24 @@
  * Craig Newell <CraigN@cheque.uq.edu.au>
  *     RFC2347 TFTP Option Extension
  *
- * $Id: packet-tftp.c,v 1.36 2002/01/24 09:20:52 guy Exp $
+ * $Id: packet-tftp.c,v 1.41 2003/12/24 10:48:13 guy 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;
 
        /*
@@ -150,7 +145,7 @@ dissect_tftp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                            offset, 2, opcode);
        }
        offset += 2;
-           
+
        switch (opcode) {
 
        case TFTP_RRQ:
@@ -208,30 +203,38 @@ 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, -1,
-               "Data (%d bytes)", tvb_reported_length_remaining(tvb, offset));
+         if (bytes != 0) {
+           if (tree) {
+             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;