2 * Routines for ftp packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-ftp.c,v 1.9 1999/10/12 06:20:05 gram Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@unicom.net>
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;
56 dissect_ftp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
58 proto_tree *ftp_tree, *ti;
59 gchar rr[50], rd[1500];
60 int i1 = (u_char *)strchr(pd + offset, ' ') - (pd + offset); /* Where is that space */
62 int max_data = pi.captured_len - offset;
64 memset(rr, '\0', sizeof(rr));
65 memset(rd, '\0', sizeof(rd));
69 /* Hmmm, check if there was no space in there ... */
73 i1 = max_data; /* Make things below work */
74 strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1));
79 strncpy(rr, pd + offset, MIN(i1, sizeof(rr) - 1));
80 i2 = ((u_char *)strchr(pd + offset + i1 + 1, '\r') - (pd + offset)) - i1 - 1;
81 if (i2 > max_data - i1 - 1 || i2 < 0) {
82 i2 = max_data - i1 - 1;
85 strncpy(rd, pd + offset + i1 + 1, MIN(i2, sizeof(rd) - 1));
91 strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1)); /* Lazy, CRLF */
95 if (check_col(fd, COL_PROTOCOL))
96 col_add_str(fd, COL_PROTOCOL, "FTP");
98 if (check_col(fd, COL_INFO)) {
100 col_add_fstr(fd, COL_INFO, "%s: %s %s", (pi.match_port == pi.destport)? "Request" : "Response", rr, rd);
106 ti = proto_tree_add_item(tree, proto_ftp, offset, END_OF_FRAME, NULL);
107 ftp_tree = proto_item_add_subtree(ti, ETT_FTP);
109 if (pi.match_port == pi.destport) { /* Request */
111 proto_tree_add_item_hidden(ftp_tree, hf_ftp_request,
113 proto_tree_add_item_hidden(ftp_tree, hf_ftp_response,
115 proto_tree_add_item_format(ftp_tree, hf_ftp_request_command,
116 offset, i1, rr, "Request: %s", rr);
117 proto_tree_add_item_format(ftp_tree, hf_ftp_request_data,
118 offset + i1 + 1, END_OF_FRAME,
119 rd, "Request Arg: %s", rd);
123 proto_tree_add_item_hidden(ftp_tree, hf_ftp_request,
125 proto_tree_add_item_hidden(ftp_tree, hf_ftp_response,
127 proto_tree_add_item_format(ftp_tree, hf_ftp_response_code,
129 atoi(rr), "Response: %s", rr);
130 proto_tree_add_item_format(ftp_tree, hf_ftp_response_data,
131 offset + i1 + 1, END_OF_FRAME,
132 rd, "Response Arg: %s", rd);
139 dissect_ftpdata(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
143 if (check_col(fd, COL_PROTOCOL))
144 col_add_str(fd, COL_PROTOCOL, "FTP DATA");
146 if (check_col(fd, COL_INFO)) {
148 col_add_fstr(fd, COL_INFO, "FTP Data ...");
154 ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
155 "File Transfer Protocol Data");
161 proto_register_ftp(void)
163 static hf_register_info hf[] = {
165 { "Response", "ftp.response", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
169 { "Request", "ftp.request", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
172 { &hf_ftp_request_command,
173 { "Request command", "ftp.request.command", FT_STRING, BASE_NONE, NULL, 0x0,
176 { &hf_ftp_request_data,
177 { "Request data", "ftp.request.data", FT_STRING, BASE_NONE, NULL, 0x0,
180 { &hf_ftp_response_code,
181 { "Response code", "ftp.response.code", FT_UINT8, BASE_DEC, NULL, 0x0,
184 { &hf_ftp_response_data,
185 { "Response data", "ftp.reponse.data", FT_STRING, BASE_NONE, NULL, 0x0,
189 proto_ftp = proto_register_protocol("File Transfer Protocol", "ftp");
190 proto_register_field_array(proto_ftp, hf, array_length(hf));