2 * Routines for pop packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-pop.c,v 1.11 1999/11/20 23:03:09 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@unicom.net>
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>
46 static int proto_pop = -1;
47 static int hf_pop_response = -1;
48 static int hf_pop_request = -1;
50 static gint ett_pop = -1;
52 static gboolean is_continuation(const u_char *data);
55 dissect_pop(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
57 proto_tree *pop_tree, *ti;
58 gchar rr[50], rd[1500];
59 int i1 = (u_char *)strchr(pd + offset, ' ') - (pd + offset); /* Where is that space */
61 int max_data = pi.captured_len - offset;
63 memset(rr, '\0', sizeof(rr));
64 memset(rd, '\0', sizeof(rd));
66 if ((i1 > max_data) || (i1 <= 0)) {
69 strncpy(rr, pd + offset, MIN(max_data - 2, sizeof(rr) - 1));
74 strncpy(rr, pd + offset, MIN(i1, sizeof(rr) - 1));
75 i2 = ((u_char *)strchr(pd + offset + i1 + 1, '\r') - (pd + offset)) - i1 - 1;
76 if (i2 > max_data - i1 - 1 || i2 <= 0) {
77 i2 = ((u_char *)strchr(pd + offset + i1 + 1, '\n') - (pd + offset)) - i1 - 1;
78 if (i2 > max_data - i1 - 1 || i2 <= 0)
79 i2 = max_data - i1 - 1;
81 strncpy(rd, pd + offset + i1 + 1, MIN(i2, sizeof(rd) - 1));
84 if (check_col(fd, COL_PROTOCOL))
85 col_add_str(fd, COL_PROTOCOL, "POP");
87 if (check_col(fd, COL_INFO)) {
89 * Do it like HTTP does.
90 * Put the first line from the buffer into the summary,
91 * if it's an POP request or reply.
92 * Otherwise, just call it a continuation.
94 if (pi.match_port == pi.srcport && is_continuation(pd+offset))
95 col_add_str(fd, COL_INFO, "Continuation");
97 col_add_fstr(fd, COL_INFO, "%s: %s %s", (pi.match_port == pi.destport)? "Request" : "Response", rr, rd);
102 ti = proto_tree_add_item(tree, proto_pop, offset, END_OF_FRAME, NULL);
103 pop_tree = proto_item_add_subtree(ti, ett_pop);
105 if (pi.match_port == pi.destport) { /* Request */
106 proto_tree_add_item_hidden(pop_tree, hf_pop_request, offset, i1, TRUE);
107 proto_tree_add_text(pop_tree, offset, i1, "Request: %s", rr);
110 proto_tree_add_text(pop_tree, offset + i1 + 1, END_OF_FRAME, "Request Arg: %s", rd);
114 proto_tree_add_item_hidden(pop_tree, hf_pop_response, offset, i1, TRUE);
116 if (is_continuation(pd+offset))
117 dissect_data(pd, offset, fd, pop_tree);
119 proto_tree_add_text(pop_tree, offset, i1, "Response: %s", rr);
122 proto_tree_add_text(pop_tree, offset + i1 + 1, END_OF_FRAME, "Response Arg: %s", rd);
130 proto_register_pop(void)
133 static hf_register_info hf[] = {
135 { "Response", "pop.response",
136 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
137 "TRUE if POP response" }},
140 { "Request", "pop.request",
141 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
142 "TRUE if POP request" }}
144 static gint *ett[] = {
148 proto_pop = proto_register_protocol("Post Office Protocol", "pop");
149 proto_register_field_array(proto_pop, hf, array_length(hf));
150 proto_register_subtree_array(ett, array_length(ett));
153 static gboolean is_continuation(const u_char *data)
155 if (strncmp(data, "+OK", strlen("+OK")) == 0)
158 if (strncmp(data, "-ERR", strlen("-ERR")) == 0)