2 * Routines for tftp packet dissection
4 * Richard Sharpe <rsharpe@ns.aus.com>
5 * Craig Newell <CraigN@cheque.uq.edu.au>
6 * RFC2347 TFTP Option Extension
8 * $Id: packet-tftp.c,v 1.10 2000/02/09 17:15:47 gram Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@zing.org>
12 * Copyright 1998 Gerald Combs
14 * Copied from packet-bootp.c
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * 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>
46 static int proto_tftp = -1;
47 static int hf_tftp_type = -1;
48 static int hf_tftp_error_code = -1;
50 static gint ett_tftp = -1;
59 char *tftp_opcodes[8] = {
66 "Option Acknowledgement",
70 char *tftp_errors[8] = {
74 "Disk full or allocation exceeded",
75 "Illegal TFTP Operation",
76 "Unknown transfer ID",
77 "File already exists",
82 dissect_tftp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
84 proto_tree *tftp_tree;
88 if (check_col(fd, COL_PROTOCOL))
89 col_add_str(fd, COL_PROTOCOL, "TFTP");
91 if (check_col(fd, COL_INFO)) {
93 i1 = pntohs(&pd[offset]);
94 col_add_fstr(fd, COL_INFO, "TFTP %s", i1 <= OACK ? tftp_opcodes[i1 % 8] : "Unknown Request");
100 ti = proto_tree_add_item(tree, proto_tftp, offset, END_OF_FRAME, NULL);
101 tftp_tree = proto_item_add_subtree(ti, ett_tftp);
103 i1 = pntohs(pd+offset);
104 proto_tree_add_item_hidden(tftp_tree, hf_tftp_type, offset, 2, i1);
108 proto_tree_add_text(tftp_tree, offset, 2, "Read Request");
110 i1 = strlen(pd+offset);
111 proto_tree_add_text(tftp_tree, offset, i1+1, "Source File: %s", pd+offset);
113 i1 = strlen(pd+offset);
114 proto_tree_add_text(tftp_tree, offset, i1+1, "Type: %s",pd+offset);
116 while (offset < pi.captured_len) {
118 i1 = strlen(pd+offset); /* length of option */
119 i2 = strlen(pd+offset+i1+1); /* length of value */
120 proto_tree_add_text(tftp_tree, offset, i1+i2+2, "Option: %s = %s",
121 pd+offset, pd+offset+i1+1);
122 offset += i1 + i2 + 2;
126 proto_tree_add_text(tftp_tree, offset, 2, "Write Request");
128 i1 = strlen(pd+offset);
129 proto_tree_add_text(tftp_tree, offset, i1+1, "Destination File: %s", pd+offset);
131 i1 = strlen(pd+offset);
132 proto_tree_add_text(tftp_tree, offset, i1+1, "Type: %s",pd+offset);
134 while (offset < pi.captured_len) {
136 i1 = strlen(pd+offset); /* length of option */
137 i2 = strlen(pd+offset+i1+1); /* length of value */
138 proto_tree_add_text(tftp_tree, offset, i1+i2+2, "Option: %s = %s",
139 pd+offset, pd+offset+i1+1);
140 offset += i1 + i2 + 2;
144 proto_tree_add_text(tftp_tree, offset, 2, "Data Packet");
146 i1 = pntohs(pd+offset);
147 proto_tree_add_text(tftp_tree, offset, 2, "Block = %u", i1);
149 proto_tree_add_text(tftp_tree, offset, END_OF_FRAME,
150 "Data (%d bytes)", END_OF_FRAME);
153 proto_tree_add_text(tftp_tree, offset, 2, "Acknowledgement");
155 i1 = pntohs(pd+offset);
156 proto_tree_add_text(tftp_tree, offset, END_OF_FRAME, "Block = %u", i1);
159 proto_tree_add_text(tftp_tree, offset, 2, "Error Code");
161 i1 = pntohs(pd+offset);
162 proto_tree_add_item_hidden(tftp_tree, hf_tftp_error_code, offset, 2, i1);
163 proto_tree_add_text(tftp_tree, offset, 2, "Code = %s", tftp_errors[i1 % 8]);
165 proto_tree_add_text(tftp_tree, offset, END_OF_FRAME, "Error Message: %s", pd + offset);
168 proto_tree_add_text(tftp_tree, offset, 2, "Option Acknowledgement");
170 while (offset < pi.captured_len) {
172 i1 = strlen(pd+offset); /* length of option */
173 i2 = strlen(pd+offset+i1+1); /* length of value */
174 proto_tree_add_text(tftp_tree, offset, i1+i2+2, "Option: %s = %s",
175 pd+offset, pd+offset+i1+1);
176 offset += i1 + i2 + 2;
180 proto_tree_add_text(tftp_tree, offset, 2, "Unknown TFTP Request: %0X.", i1);
182 proto_tree_add_text(tftp_tree, offset, END_OF_FRAME,
183 "Data (%d bytes)", END_OF_FRAME);
191 proto_register_tftp(void)
194 static hf_register_info hf[] = {
196 { "Type", "tftp.type",
197 FT_UINT16, BASE_DEC, NULL, 0x0,
198 "TFTP message type" }},
200 { &hf_tftp_error_code,
201 { "Error code", "tftp.error.code",
202 FT_UINT16, BASE_DEC, NULL, 0x0,
203 "Error code in case of TFTP error message" }}
205 static gint *ett[] = {
209 proto_tftp = proto_register_protocol("Trivial File Transfer Protocol", "tftp");
210 proto_register_field_array(proto_tftp, hf, array_length(hf));
211 proto_register_subtree_array(ett, array_length(ett));