2 * Routines for nntp packet dissection
3 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
5 * $Id: packet-nntp.c,v 1.27 2002/08/28 21:00:24 jmayer Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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.
34 #include <epan/packet.h>
35 #include <epan/strutil.h>
37 static int proto_nntp = -1;
38 static int hf_nntp_response = -1;
39 static int hf_nntp_request = -1;
41 static gint ett_nntp = -1;
43 #define TCP_PORT_NNTP 119
46 dissect_nntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
49 proto_tree *nntp_tree;
55 if (pinfo->match_port == pinfo->destport)
60 if (check_col(pinfo->cinfo, COL_PROTOCOL))
61 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NNTP");
63 if (check_col(pinfo->cinfo, COL_INFO)) {
65 * Put the first line from the buffer into the summary
66 * (but leave out the line terminator).
68 * Note that "tvb_find_line_end()" will return a value that
69 * is not longer than what's in the buffer, so the
70 * "tvb_get_ptr()" call won't throw an exception.
72 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset,
74 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s", type,
75 tvb_format_text(tvb, offset, linelen));
79 ti = proto_tree_add_item(tree, proto_nntp, tvb, offset, -1,
81 nntp_tree = proto_item_add_subtree(ti, ett_nntp);
83 if (pinfo->match_port == pinfo->destport) {
84 proto_tree_add_boolean_hidden(nntp_tree,
85 hf_nntp_request, tvb, 0, 0, TRUE);
87 proto_tree_add_boolean_hidden(nntp_tree,
88 hf_nntp_response, tvb, 0, 0, TRUE);
92 * Show the request or response as text, a line at a time.
93 * XXX - for requests, we could display the stuff after the
94 * first line, if any, based on what the request was, and
95 * for responses, we could display it based on what the
96 * matching request was, although the latter requires us to
97 * know what the matching request was....
99 while (tvb_offset_exists(tvb, offset)) {
101 * Find the end of the line.
103 tvb_find_line_end(tvb, offset, -1, &next_offset,
109 proto_tree_add_text(nntp_tree, tvb, offset,
110 next_offset - offset, "%s",
111 tvb_format_text(tvb, offset, next_offset - offset));
112 offset = next_offset;
118 proto_register_nntp(void)
120 static hf_register_info hf[] = {
122 { "Response", "nntp.response",
123 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
124 "TRUE if NNTP response", HFILL }},
127 { "Request", "nntp.request",
128 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
129 "TRUE if NNTP request", HFILL }}
131 static gint *ett[] = {
135 proto_nntp = proto_register_protocol("Network News Transfer Protocol",
137 proto_register_field_array(proto_nntp, hf, array_length(hf));
138 proto_register_subtree_array(ett, array_length(ett));
142 proto_reg_handoff_nntp(void)
144 dissector_handle_t nntp_handle;
146 nntp_handle = create_dissector_handle(dissect_nntp, proto_nntp);
147 dissector_add("tcp.port", TCP_PORT_NNTP, nntp_handle);