2 * Routines for nntp packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-nntp.c,v 1.16 2000/11/19 08:54:00 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>
45 static int proto_nntp = -1;
46 static int hf_nntp_response = -1;
47 static int hf_nntp_request = -1;
49 static gint ett_nntp = -1;
51 #define TCP_PORT_NNTP 119
54 dissect_nntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
57 proto_tree *nntp_tree;
64 CHECK_DISPLAY_AS_DATA(proto_nntp, tvb, pinfo, tree);
66 if (pinfo->match_port == pinfo->destport)
71 pinfo->current_proto = "NNTP";
73 if (check_col(pinfo->fd, COL_PROTOCOL))
74 col_set_str(pinfo->fd, COL_PROTOCOL, "NNTP");
76 if (check_col(pinfo->fd, COL_INFO)) {
78 * Put the first line from the buffer into the summary
79 * (but leave out the line terminator).
81 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
82 line = tvb_get_ptr(tvb, offset, linelen);
83 col_add_fstr(pinfo->fd, COL_INFO, "%s: %s", type,
84 format_text(line, linelen));
88 ti = proto_tree_add_item(tree, proto_nntp, tvb, offset,
89 tvb_length_remaining(tvb, offset), FALSE);
90 nntp_tree = proto_item_add_subtree(ti, ett_nntp);
92 if (pinfo->match_port == pinfo->destport) {
93 proto_tree_add_boolean_hidden(nntp_tree,
94 hf_nntp_request, tvb, 0, 0, TRUE);
96 proto_tree_add_boolean_hidden(nntp_tree,
97 hf_nntp_response, tvb, 0, 0, TRUE);
101 * Show the request or response as text, a line at a time.
102 * XXX - for requests, we could display the stuff after the
103 * first line, if any, based on what the request was, and
104 * for responses, we could display it based on what the
105 * matching request was, although the latter requires us to
106 * know what the matching request was....
108 while (tvb_offset_exists(tvb, offset)) {
110 * Find the end of the line.
112 tvb_find_line_end(tvb, offset, -1, &next_offset);
117 proto_tree_add_text(nntp_tree, tvb, offset,
118 next_offset - offset, "%s",
119 tvb_format_text(tvb, offset, next_offset - offset));
120 offset = next_offset;
126 proto_register_nntp(void)
128 static hf_register_info hf[] = {
130 { "Response", "nntp.response",
131 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
132 "TRUE if NNTP response" }},
135 { "Request", "nntp.request",
136 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
137 "TRUE if NNTP request" }}
139 static gint *ett[] = {
143 proto_nntp = proto_register_protocol("Network News Transfer Protocol",
145 proto_register_field_array(proto_nntp, hf, array_length(hf));
146 proto_register_subtree_array(ett, array_length(ett));
150 proto_reg_handoff_nntp(void)
152 dissector_add("tcp.port", TCP_PORT_NNTP, dissect_nntp);