2 * Routines for imap packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-imap.c,v 1.23 2003/06/11 20:03:39 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-tftp.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.
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
39 static int proto_imap = -1;
40 static int hf_imap_response = -1;
41 static int hf_imap_request = -1;
43 static gint ett_imap = -1;
44 static gint ett_imap_reqresp = -1;
46 #define TCP_PORT_IMAP 143
49 dissect_imap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
52 proto_tree *imap_tree, *reqresp_tree;
59 const guchar *next_token;
61 if (check_col(pinfo->cinfo, COL_PROTOCOL))
62 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IMAP");
65 * Find the end of the first line.
67 * Note that "tvb_find_line_end()" will return a value that is
68 * not longer than what's in the buffer, so the "tvb_get_ptr()"
69 * call won't throw an exception.
71 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
72 line = tvb_get_ptr(tvb, offset, linelen);
74 if (pinfo->match_port == pinfo->destport)
79 if (check_col(pinfo->cinfo, COL_INFO)) {
81 * Put the first line from the buffer into the summary
82 * (but leave out the line terminator).
84 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
85 is_request ? "Request" : "Response",
86 format_text(line, linelen));
90 ti = proto_tree_add_item(tree, proto_imap, tvb, offset, -1,
92 imap_tree = proto_item_add_subtree(ti, ett_imap);
95 proto_tree_add_boolean_hidden(imap_tree,
96 hf_imap_request, tvb, 0, 0, TRUE);
98 proto_tree_add_boolean_hidden(imap_tree,
99 hf_imap_response, tvb, 0, 0, TRUE);
103 * Put the line into the protocol tree.
105 ti = proto_tree_add_text(imap_tree, tvb, offset,
106 next_offset - offset, "%s",
107 tvb_format_text(tvb, offset, next_offset - offset));
108 reqresp_tree = proto_item_add_subtree(ti, ett_imap_reqresp);
111 * Show the first line as tags + requests or replies.
115 * Extract the first token, and, if there is a first
116 * token, add it as the request or reply tag.
118 tokenlen = get_token_len(line, line + linelen, &next_token);
121 proto_tree_add_text(reqresp_tree, tvb, offset,
122 tokenlen, "Request Tag: %s",
123 format_text(line, tokenlen));
125 proto_tree_add_text(reqresp_tree, tvb, offset,
126 tokenlen, "Response Tag: %s",
127 format_text(line, tokenlen));
129 offset += next_token - line;
130 linelen -= next_token - line;
135 * Add the rest of the line as request or reply data.
139 proto_tree_add_text(reqresp_tree, tvb, offset,
140 linelen, "Request: %s",
141 format_text(line, linelen));
143 proto_tree_add_text(reqresp_tree, tvb, offset,
144 linelen, "Response: %s",
145 format_text(line, linelen));
150 * XXX - show the rest of the frame; this requires that
151 * we handle literals, quoted strings, continuation
154 * This involves a state machine, and attaching
155 * state information to the packets.
161 proto_register_imap(void)
163 static hf_register_info hf[] = {
165 { "Response", "imap.response",
166 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
167 "TRUE if IMAP response", HFILL }},
170 { "Request", "imap.request",
171 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
172 "TRUE if IMAP request", HFILL }}
174 static gint *ett[] = {
179 proto_imap = proto_register_protocol("Internet Message Access Protocol",
181 proto_register_field_array(proto_imap, hf, array_length(hf));
182 proto_register_subtree_array(ett, array_length(ett));
186 proto_reg_handoff_imap(void)
188 dissector_handle_t imap_handle;
190 imap_handle = create_dissector_handle(dissect_imap, proto_imap);
191 dissector_add("tcp.port", TCP_PORT_IMAP, imap_handle);