2 * Routines for ftp packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-ftp.c,v 1.11 2000/01/07 22:05:30 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-pop.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
39 #ifdef HAVE_NETINET_IN_H
40 # include <netinet/in.h>
47 static int proto_ftp = -1;
48 static int hf_ftp_response = -1;
49 static int hf_ftp_request = -1;
50 static int hf_ftp_request_command = -1;
51 static int hf_ftp_request_data = -1;
52 static int hf_ftp_response_code = -1;
53 static int hf_ftp_response_data = -1;
55 static gint ett_ftp = -1;
58 dissect_ftp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
60 proto_tree *ftp_tree, *ti;
61 gchar rr[50], rd[1500];
62 int i1 = (u_char *)strchr(pd + offset, ' ') - (pd + offset); /* Where is that space */
64 int max_data = pi.captured_len - offset;
66 memset(rr, '\0', sizeof(rr));
67 memset(rd, '\0', sizeof(rd));
71 /* Hmmm, check if there was no space in there ... */
75 i1 = max_data; /* Make things below work */
76 strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1));
81 strncpy(rr, pd + offset, MIN(i1, sizeof(rr) - 1));
82 i2 = ((u_char *)strchr(pd + offset + i1 + 1, '\r') - (pd + offset)) - i1 - 1;
83 if (i2 > max_data - i1 - 1 || i2 < 0) {
84 i2 = max_data - i1 - 1;
87 strncpy(rd, pd + offset + i1 + 1, MIN(i2, sizeof(rd) - 1));
93 strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1)); /* Lazy, CRLF */
97 if (check_col(fd, COL_PROTOCOL))
98 col_add_str(fd, COL_PROTOCOL, "FTP");
100 if (check_col(fd, COL_INFO)) {
102 col_add_fstr(fd, COL_INFO, "%s: %s %s", (pi.match_port == pi.destport)? "Request" : "Response", rr, rd);
108 ti = proto_tree_add_item(tree, proto_ftp, offset, END_OF_FRAME, NULL);
109 ftp_tree = proto_item_add_subtree(ti, ett_ftp);
111 if (pi.match_port == pi.destport) { /* Request */
113 proto_tree_add_item_hidden(ftp_tree, hf_ftp_request,
115 proto_tree_add_item_hidden(ftp_tree, hf_ftp_response,
117 proto_tree_add_item_format(ftp_tree, hf_ftp_request_command,
118 offset, i1, rr, "Request: %s", rr);
119 proto_tree_add_item_format(ftp_tree, hf_ftp_request_data,
120 offset + i1 + 1, END_OF_FRAME,
121 rd, "Request Arg: %s", rd);
125 proto_tree_add_item_hidden(ftp_tree, hf_ftp_request,
127 proto_tree_add_item_hidden(ftp_tree, hf_ftp_response,
129 proto_tree_add_item_format(ftp_tree, hf_ftp_response_code,
131 atoi(rr), "Response: %s", rr);
132 proto_tree_add_item_format(ftp_tree, hf_ftp_response_data,
133 offset + i1 + 1, END_OF_FRAME,
134 rd, "Response Arg: %s", rd);
141 dissect_ftpdata(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
145 if (check_col(fd, COL_PROTOCOL))
146 col_add_str(fd, COL_PROTOCOL, "FTP DATA");
148 if (check_col(fd, COL_INFO)) {
150 col_add_fstr(fd, COL_INFO, "FTP Data ...");
156 ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
157 "File Transfer Protocol Data");
163 proto_register_ftp(void)
165 static hf_register_info hf[] = {
167 { "Response", "ftp.response", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
171 { "Request", "ftp.request", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
174 { &hf_ftp_request_command,
175 { "Request command", "ftp.request.command", FT_STRING, BASE_NONE, NULL, 0x0,
178 { &hf_ftp_request_data,
179 { "Request data", "ftp.request.data", FT_STRING, BASE_NONE, NULL, 0x0,
182 { &hf_ftp_response_code,
183 { "Response code", "ftp.response.code", FT_UINT8, BASE_DEC, NULL, 0x0,
186 { &hf_ftp_response_data,
187 { "Response data", "ftp.reponse.data", FT_STRING, BASE_NONE, NULL, 0x0,
190 static gint *ett[] = {
194 proto_ftp = proto_register_protocol("File Transfer Protocol", "ftp");
195 proto_register_field_array(proto_ftp, hf, array_length(hf));
196 proto_register_subtree_array(ett, array_length(ett));