Ethereal-dev: [Ethereal-dev] [patch] interpret codes for FTP

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

From: Brad Hards <bhards@xxxxxxxxxxxxxx>
Date: Tue, 25 Feb 2003 18:53:20 +1100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

G'day,

The attached patch provides a textual interpretation for the various FTP 
response codes, based on the list in RFC 959. I also did some minor cleanups 
to the same area.

Please review and apply, as appropriate.

Brad
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE+WyDwW6pHgIdAuOMRAqCnAKCXxUgsuDP+/SILXl/2RZXG6tCEkwCfQ8Wi
cXf6TLxRV+fwimy6Pvy+WCo=
=sSDg
-----END PGP SIGNATURE-----
diff -Naur -X ethereal-dontdiff clean/ethereal-0.9.9/packet-ftp.c ethereal-0.9.9-ftp/packet-ftp.c
--- clean/ethereal-0.9.9/packet-ftp.c	2002-08-29 10:39:52.000000000 +1000
+++ ethereal-0.9.9-ftp/packet-ftp.c	2003-02-25 18:02:06.000000000 +1100
@@ -57,6 +57,52 @@
 #define TCP_PORT_FTPDATA		20
 #define TCP_PORT_FTP			21
 
+struct response_table {
+	guint32	code;
+	gchar	*text;
+} response_table[] = {
+	{ 110, "Restart marker reply" },
+	{ 120, "Service ready in nnn minutes" },
+	{ 125, "Data connection already open; transfer starting" },
+	{ 150, "File status okay; about to open data connection" },
+	{ 200, "Command okay" },
+	{ 202, "Command not implemented, superfluous at this site" },
+	{ 211, "System status, or system help reply" },
+	{ 212, "Directory status" },
+	{ 213, "File status" },
+	{ 214, "Help message" },
+	{ 215, "NAME system type" },
+	{ 220, "Service ready for new user" },
+	{ 221, "Service closing control connection" },
+	{ 225, "Data connection open; no transfer in progress" },
+	{ 226, "Closing data connection" },
+	{ 227, "Entering Passive Mode" },
+	{ 230, "User logged in, proceed" },
+	{ 250, "Requested file action okay, completed" },
+	{ 257, "PATHNAME created" },
+	{ 331, "User name okay, need password" },
+	{ 332, "Need account for login" },
+	{ 350, "Requested file action pending further information" },
+	{ 421, "Service not available, closing control connection" },
+	{ 425, "Can't open data connection" },
+	{ 426, "Connection closed; transfer aborted" },
+	{ 450, "Requested file action not taken" },
+	{ 451, "Requested action aborted: local error in processing" },
+	{ 452, "Requested action not taken. Insufficient storage space in system" },
+	{ 500, "Syntax error, command unrecognized" },
+	{ 501, "Syntax error in parameters or arguments" },
+	{ 502, "Command not implemented" },
+	{ 503, "Bad sequence of commands" },
+	{ 504, "Command not implemented for that parameter" },
+	{ 530, "Not logged in" },
+	{ 532, "Need account for storing files" },
+	{ 550, "Requested action not taken: File unavailable" },
+	{ 551, "Requested action aborted: page type unknown" },
+	{ 552, "Requested file action aborted: Exceeded storage allocation" },
+	{ 553, "Requested action not taken: File name not allowed" },
+	{ 0, "Unknown" },
+};
+		
 static void
 dissect_ftpdata(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
@@ -207,11 +253,13 @@
 	gint		offset = 0;
 	const guchar	*line;
 	guint32		code;
+	gchar		code_str[4];
 	gboolean	is_pasv_response = FALSE;
 	gint		next_offset;
 	int		linelen;
 	int		tokenlen;
 	const guchar	*next_token;
+	int		i = 0;
 
 	if (pinfo->match_port == pinfo->destport)
 		is_request = TRUE;
@@ -291,12 +339,30 @@
 			 * One-line reply, or first or last line
 			 * of a multi-line reply.
 			 */
-			code = (line[0] - '0')*100 + (line[1] - '0')*10
-			    + (line[2] - '0');
+			tvb_get_nstringz0(tvb, offset, 3, code_str);
+			code = strtoul(code_str, NULL, 10);
+			for (i = 0; response_table[i].code; i++) {
+				if (code == response_table[i].code)
+					break;
+			}
+				
 			if (tree) {
-				proto_tree_add_uint(ftp_tree,
-				    hf_ftp_response_code, tvb, offset, 3, code);
-
+				proto_tree_add_uint_hidden(ftp_tree,
+						    hf_ftp_response_code,
+						    tvb, offset, 3, code);
+
+				if (response_table[i].code) {
+					proto_tree_add_text(ftp_tree, tvb,
+							    offset, 3,
+							    "Response code: %i (%s)",
+							    code,
+							    response_table[i].text);
+				} else { /* no string */
+					proto_tree_add_text(ftp_tree, tvb,
+							    offset, 3,
+							    "Response code: %i",
+							    code);
+				}
 			}
 
 			/*