Ethereal-dev: [ethereal-dev] TFTP Option Support (RFC2347)

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Craig Newell (W2/VK4YEQ)" <craign@xxxxxxxxxxxxxxxx>
Date: Thu, 27 Jan 2000 01:46:57 -0500 (EST)
Hi All,

  Here is my first attempt at adding to Ethereal - TFTP Options Support
(RFC2347).  I hope this is the required format patch, else email me
directly and I will try again.  

	Thanks,

		CraigN
---
      Craig Newell                email: CraigN@xxxxxxxxxxxxxxxx
      Free Spirit                 icbm:  somewhere in NJ, USA

Index: packet-tftp.c
===================================================================
RCS file: /cvsroot/ethereal/packet-tftp.c,v
retrieving revision 1.8
diff -u -r1.8 packet-tftp.c
--- packet-tftp.c	2000/01/07 22:05:41	1.8
+++ packet-tftp.c	2000/01/27 06:45:30
@@ -2,6 +2,8 @@
  * Routines for tftp packet dissection
  *
  * Richard Sharpe <rsharpe@xxxxxxxxxx>
+ * Craig Newell <CraigN@xxxxxxxxxxxxxxxx>
+ *	RFC2347 TFTP Option Extension
  *
  * $Id: packet-tftp.c,v 1.8 2000/01/07 22:05:41 guy Exp $
  *
@@ -52,6 +54,7 @@
 #define	DATA	3
 #define	ACK	4
 #define	ERROR	5
+#define OACK	6
 
 char *tftp_opcodes[8] = {
   "Unknown Request",
@@ -60,7 +63,7 @@
   "Data Packet",
   "Acknowledgement",
   "Error Code",
-  "Unknown Request",
+  "Option Acknowledgement",
   "Unknown Request"
 };
 
@@ -88,7 +91,7 @@
 	if (check_col(fd, COL_INFO)) {
 
 	  i1 = pntohs(&pd[offset]);
-	  col_add_fstr(fd, COL_INFO, "TFTP %s", i1 <= ERROR ? tftp_opcodes[i1 % 8] : "Unknown Request");
+	  col_add_fstr(fd, COL_INFO, "TFTP %s", i1 <= OACK ? tftp_opcodes[i1 % 8] : "Unknown Request");
 
 	}
 
@@ -106,16 +109,36 @@
 	    offset += 2;
 	    i1 = strlen(pd+offset);
 	    proto_tree_add_text(tftp_tree, offset, i1+1, "Source File: %s", pd+offset);
+	    offset += i1 + 1;
+	    i1 = strlen(pd+offset);
+	    proto_tree_add_text(tftp_tree, offset, i1+1, "Type: %s",pd+offset);
 	    offset += i1 + 1;
-	    proto_tree_add_text(tftp_tree, offset, END_OF_FRAME, "Type: %s",pd+offset);
+	    while (offset < pi.captured_len) {
+	      int i2;
+	      i1 = strlen(pd+offset);			/* length of option */
+	      i2 = strlen(pd+offset+i1+1);		/* length of value */
+	      proto_tree_add_text(tftp_tree, offset, i1+i2+2, "Option: %s = %s", 
+                pd+offset, pd+offset+i1+1);
+	      offset += i1 + i2 + 2;
+	    }
 	    break;
 	  case WRQ:
 	    proto_tree_add_text(tftp_tree, offset, 2, "Write Request");
 	    offset += 2;
 	    i1 = strlen(pd+offset);
 	    proto_tree_add_text(tftp_tree, offset, i1+1, "Destination File: %s", pd+offset);
+	    offset += i1 + 1;
+	    i1 = strlen(pd+offset);
+	    proto_tree_add_text(tftp_tree, offset, i1+1, "Type: %s",pd+offset);
 	    offset += i1 + 1;
-	    proto_tree_add_text(tftp_tree, offset+2, END_OF_FRAME, "Type: %s",pd+offset);
+	    while (offset < pi.captured_len) {
+	      int i2;
+	      i1 = strlen(pd+offset);			/* length of option */
+	      i2 = strlen(pd+offset+i1+1);		/* length of value */
+	      proto_tree_add_text(tftp_tree, offset, i1+i2+2, "Option: %s = %s", 
+                pd+offset, pd+offset+i1+1);
+	      offset += i1 + i2 + 2;
+	    }
 	    break;
 	  case DATA:
 	    proto_tree_add_text(tftp_tree, offset, 2, "Data Packet");
@@ -140,6 +163,21 @@
 	    proto_tree_add_text(tftp_tree, offset, 2, "Code = %s", tftp_errors[i1 % 8]);
 	    offset += 2;
 	    proto_tree_add_text(tftp_tree, offset, END_OF_FRAME, "Error Message: %s", pd + offset);
+	    break;
+	  case OACK:
+	    proto_tree_add_text(tftp_tree, offset, 2, "Option Acknowledgement");
+	    offset += 2;
+	    i1 = pntohs(pd+offset);
+	    proto_tree_add_text(tftp_tree, offset, 2, "Block = %u", i1);
+	    offset += 2;
+	    while (offset < pi.captured_len) {
+	      int i2;
+	      i1 = strlen(pd+offset);			/* length of option */
+	      i2 = strlen(pd+offset+i1+1);		/* length of value */
+	      proto_tree_add_text(tftp_tree, offset, i1+i2+2, "Option: %s = %s", 
+                pd+offset, pd+offset+i1+1);
+	      offset += i1 + i2 + 2;
+	    }
 	    break;
 	  default:
 	    proto_tree_add_text(tftp_tree, offset, 2, "Unknown TFTP Request: %0X.", i1);