2 * Routines for pop packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-pop.c,v 1.25 2001/06/18 02:17:50 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
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.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
47 static int proto_pop = -1;
48 static int hf_pop_response = -1;
49 static int hf_pop_request = -1;
51 static gint ett_pop = -1;
53 #define TCP_PORT_POP 110
55 static gboolean response_is_continuation(const u_char *data);
58 dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
61 gboolean is_continuation;
69 const u_char *next_token;
71 if (check_col(pinfo->fd, COL_PROTOCOL))
72 col_set_str(pinfo->fd, COL_PROTOCOL, "POP");
75 * Find the end of the first line.
77 * Note that "tvb_find_line_end()" will return a value that is
78 * not longer than what's in the buffer, so the "tvb_get_ptr()"
79 * call won't throw an exception.
81 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
82 line = tvb_get_ptr(tvb, offset, linelen);
84 if (pinfo->match_port == pinfo->destport) {
86 is_continuation = FALSE;
89 is_continuation = response_is_continuation(line);
92 if (check_col(pinfo->fd, COL_INFO)) {
94 * Put the first line from the buffer into the summary
95 * if it's a POP request or reply (but leave out the
97 * Otherwise, just call it a continuation.
100 col_set_str(pinfo->fd, COL_INFO, "Continuation");
102 col_add_fstr(pinfo->fd, COL_INFO, "%s: %s",
103 is_request ? "Request" : "Response",
104 format_text(line, linelen));
108 ti = proto_tree_add_item(tree, proto_pop, tvb, offset,
109 tvb_length_remaining(tvb, offset), FALSE);
110 pop_tree = proto_item_add_subtree(ti, ett_pop);
112 if (is_continuation) {
114 * Put the whole packet into the tree as data.
116 dissect_data(tvb, 0, pinfo, pop_tree);
121 proto_tree_add_boolean_hidden(pop_tree,
122 hf_pop_request, tvb, 0, 0, TRUE);
124 proto_tree_add_boolean_hidden(pop_tree,
125 hf_pop_response, tvb, 0, 0, TRUE);
129 * Extract the first token, and, if there is a first
130 * token, add it as the request or reply code.
132 tokenlen = get_token_len(line, line + linelen, &next_token);
135 proto_tree_add_text(pop_tree, tvb, offset,
136 tokenlen, "Request: %s",
137 format_text(line, tokenlen));
139 proto_tree_add_text(pop_tree, tvb, offset,
140 tokenlen, "Response: %s",
141 format_text(line, tokenlen));
143 offset += next_token - line;
144 linelen -= next_token - line;
149 * Add the rest of the first line as request or
154 proto_tree_add_text(pop_tree, tvb, offset,
155 linelen, "Request Arg: %s",
156 format_text(line, linelen));
158 proto_tree_add_text(pop_tree, tvb, offset,
159 linelen, "Response Arg: %s",
160 format_text(line, linelen));
163 offset = next_offset;
166 * Show the rest of the request or response as text,
169 while (tvb_offset_exists(tvb, offset)) {
171 * Find the end of the line.
173 linelen = tvb_find_line_end(tvb, offset, -1,
179 proto_tree_add_text(pop_tree, tvb, offset,
180 next_offset - offset, "%s",
181 tvb_format_text(tvb, offset, next_offset - offset));
182 offset = next_offset;
187 static gboolean response_is_continuation(const u_char *data)
189 if (strncmp(data, "+OK", strlen("+OK")) == 0)
192 if (strncmp(data, "-ERR", strlen("-ERR")) == 0)
199 proto_register_pop(void)
202 static hf_register_info hf[] = {
204 { "Response", "pop.response",
205 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
206 "TRUE if POP response", HFILL }},
209 { "Request", "pop.request",
210 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
211 "TRUE if POP request", HFILL }}
213 static gint *ett[] = {
217 proto_pop = proto_register_protocol("Post Office Protocol", "POP", "pop");
218 proto_register_field_array(proto_pop, hf, array_length(hf));
219 proto_register_subtree_array(ett, array_length(ett));
223 proto_reg_handoff_pop(void)
225 dissector_add("tcp.port", TCP_PORT_POP, dissect_pop, proto_pop);