2 * Routines for IRC packet dissection
6 * http://www.irchelp.org/irchelp/rfc/
8 * and the RFCs and other documents it mentions, such as RFC 1459, RFCs
9 * 2810, 2811, 2812, and 2813,
11 * http://www.irchelp.org/irchelp/rfc/ctcpspec.html
15 * http://www.invlogic.com/irc/ctcp.html
19 * Wireshark - Network traffic analyzer
20 * By Gerald Combs <gerald@wireshark.org>
21 * Copyright 1998 Gerald Combs
23 * Copied from packet-tftp.c
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
48 #include <epan/packet.h>
50 static int proto_irc = -1;
51 static int hf_irc_request = -1;
52 static int hf_irc_response = -1;
54 static gint ett_irc = -1;
56 #define TCP_PORT_IRC 6667
57 /* good candidate for dynamic port specification */
60 dissect_irc_request(proto_tree *tree, tvbuff_t *tvb, int offset, int linelen)
62 proto_tree_add_item(tree, hf_irc_request, tvb, offset, linelen, TRUE);
66 dissect_irc_response(proto_tree *tree, tvbuff_t *tvb, int offset, int linelen)
68 proto_tree_add_item(tree, hf_irc_response, tvb, offset, linelen, TRUE);
72 dissect_irc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
74 proto_tree *irc_tree, *ti;
79 if (check_col(pinfo->cinfo, COL_PROTOCOL))
80 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IRC");
82 if (check_col(pinfo->cinfo, COL_INFO))
84 col_set_str(pinfo->cinfo, COL_INFO,
85 (pinfo->match_port == pinfo->destport) ? "Request" : "Response");
90 ti = proto_tree_add_item(tree, proto_irc, tvb, 0, -1, FALSE);
91 irc_tree = proto_item_add_subtree(ti, ett_irc);
94 * Process the packet data, a line at a time.
96 while (tvb_reported_length_remaining(tvb, offset) > 0)
99 * Find the end of the line.
101 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
102 if (next_offset == offset) {
104 * XXX - we really want the "show data a
105 * line at a time" loops in various
106 * dissectors to do reassembly and to
107 * throw an exception if there's no
108 * line ending in the current packet
109 * and we're not doing reassembly.
116 if (pinfo->match_port == pinfo->destport)
118 dissect_irc_request(irc_tree, tvb, offset, linelen);
122 dissect_irc_response(irc_tree, tvb, offset, linelen);
125 offset = next_offset;
131 proto_register_irc(void)
133 static hf_register_info hf[] = {
135 { "Response", "irc.response",
136 FT_STRING, BASE_NONE, NULL, 0x0,
137 "Line of response message", HFILL }},
140 { "Request", "irc.request",
141 FT_STRING, BASE_NONE, NULL, 0x0,
142 "Line of request message", HFILL }},
145 static gint *ett[] = {
148 proto_irc = proto_register_protocol("Internet Relay Chat", "IRC", "irc");
149 proto_register_field_array(proto_irc, hf, array_length(hf));
150 proto_register_subtree_array(ett, array_length(ett));
154 proto_reg_handoff_irc(void)
156 dissector_handle_t irc_handle;
158 irc_handle = create_dissector_handle(dissect_irc, proto_irc);
159 dissector_add("tcp.port", TCP_PORT_IRC, irc_handle);