2 * Routines for nntp packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-nntp.c,v 1.7 2000/01/07 22:05:34 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
36 #ifdef HAVE_NETINET_IN_H
37 # include <netinet/in.h>
44 static int proto_nntp = -1;
45 static int hf_nntp_response = -1;
46 static int hf_nntp_request = -1;
48 static gint ett_nntp = -1;
51 dissect_nntp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
54 proto_tree *nntp_tree, *ti;
55 const u_char *data, *dataend;
56 const u_char *lineend, *eol;
58 int max_data = pi.captured_len - offset;
61 dataend = data + END_OF_FRAME;
62 if (dataend > data + max_data)
63 dataend = data + max_data;
65 if (pi.match_port == pi.destport)
70 if (check_col(fd, COL_PROTOCOL))
71 col_add_str(fd, COL_PROTOCOL, "NNTP");
73 if (check_col(fd, COL_INFO)) {
75 * Put the first line from the buffer into the summary.
77 lineend = find_line_end(data, dataend, &eol);
79 col_add_fstr(fd, COL_INFO, "%s: %s", type,
80 format_text(data, linelen));
85 ti = proto_tree_add_item(tree, proto_nntp, offset, END_OF_FRAME, NULL);
86 nntp_tree = proto_item_add_subtree(ti, ett_nntp);
88 if (pi.match_port == pi.destport) {
89 proto_tree_add_item_hidden(nntp_tree, hf_nntp_request, 0, 0, TRUE);
91 proto_tree_add_item_hidden(nntp_tree, hf_nntp_response, 0, 0, TRUE);
95 * Show the request or response as text, a line at a time.
96 * XXX - for requests, we could display the stuff after the
97 * first line, if any, based on what the request was, and
98 * for responses, we could display it based on what the
99 * matching request was, although the latter requires us to
100 * know what the matching request was....
102 while (data < dataend) {
104 * Find the end of the line.
106 lineend = find_line_end(data, dataend, &eol);
107 linelen = lineend - data;
112 proto_tree_add_text(nntp_tree, offset, linelen, "%s",
113 format_text(data, linelen));
121 proto_register_nntp(void)
124 static hf_register_info hf[] = {
126 { "Response", "nntp.response",
127 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
128 "TRUE if NNTP response" }},
131 { "Request", "nntp.request",
132 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
133 "TRUE if NNTP request" }}
135 static gint *ett[] = {
139 proto_nntp = proto_register_protocol("Network News Transfer Protocol",
141 proto_register_field_array(proto_nntp, hf, array_length(hf));
142 proto_register_subtree_array(ett, array_length(ett));