2 * Routines for imap packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-imap.c,v 1.22 2002/08/28 21:00:17 jmayer 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;
45 #define TCP_PORT_IMAP 143
48 dissect_imap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
51 proto_tree *imap_tree, *ti;
57 const guchar *next_token;
59 if (check_col(pinfo->cinfo, COL_PROTOCOL))
60 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IMAP");
63 * Find the end of the first line.
65 * Note that "tvb_find_line_end()" will return a value that is
66 * not longer than what's in the buffer, so the "tvb_get_ptr()"
67 * call won't throw an exception.
69 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
70 line = tvb_get_ptr(tvb, offset, linelen);
72 if (pinfo->match_port == pinfo->destport)
77 if (check_col(pinfo->cinfo, COL_INFO)) {
79 * Put the first line from the buffer into the summary
80 * (but leave out the line terminator).
82 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
83 is_request ? "Request" : "Response",
84 format_text(line, linelen));
88 ti = proto_tree_add_item(tree, proto_imap, tvb, offset, -1,
90 imap_tree = proto_item_add_subtree(ti, ett_imap);
93 proto_tree_add_boolean_hidden(imap_tree,
94 hf_imap_request, tvb, 0, 0, TRUE);
96 proto_tree_add_boolean_hidden(imap_tree,
97 hf_imap_response, tvb, 0, 0, TRUE);
101 * Show the first line as tags + requests or replies.
105 * Extract the first token, and, if there is a first
106 * token, add it as the request or reply tag.
108 tokenlen = get_token_len(line, line + linelen, &next_token);
111 proto_tree_add_text(imap_tree, tvb, offset,
112 tokenlen, "Request Tag: %s",
113 format_text(line, tokenlen));
115 proto_tree_add_text(imap_tree, tvb, offset,
116 tokenlen, "Response Tag: %s",
117 format_text(line, tokenlen));
119 offset += next_token - line;
120 linelen -= next_token - line;
125 * Add the rest of the line as request or reply data.
129 proto_tree_add_text(imap_tree, tvb, offset,
130 linelen, "Request: %s",
131 format_text(line, linelen));
133 proto_tree_add_text(imap_tree, tvb, offset,
134 linelen, "Response: %s",
135 format_text(line, linelen));
140 * XXX - show the rest of the frame; this requires that
141 * we handle literals, quoted strings, continuation
144 * This involves a state machine, and attaching
145 * state information to the packets.
151 proto_register_imap(void)
153 static hf_register_info hf[] = {
155 { "Response", "imap.response",
156 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
157 "TRUE if IMAP response", HFILL }},
160 { "Request", "imap.request",
161 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
162 "TRUE if IMAP request", HFILL }}
164 static gint *ett[] = {
168 proto_imap = proto_register_protocol("Internet Message Access Protocol",
170 proto_register_field_array(proto_imap, hf, array_length(hf));
171 proto_register_subtree_array(ett, array_length(ett));
175 proto_reg_handoff_imap(void)
177 dissector_handle_t imap_handle;
179 imap_handle = create_dissector_handle(dissect_imap, proto_imap);
180 dissector_add("tcp.port", TCP_PORT_IMAP, imap_handle);