2 * Routines for IRC packet dissection
4 * $Id: packet-irc.c,v 1.21 2002/08/28 21:00:18 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-tftp.c
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <epan/packet.h>
37 static int proto_irc = -1;
38 static int hf_irc_request = -1;
39 static int hf_irc_response = -1;
40 static int hf_irc_command = -1;
42 static gint ett_irc = -1;
44 #define TCP_PORT_IRC 6667
45 /* good candidate for dynamic port specification */
48 dissect_irc_request(proto_tree *tree, tvbuff_t *tvb, int offset, int len,
49 const char *line, int linelen)
51 proto_tree_add_boolean_hidden(tree, hf_irc_request, tvb, offset, len,
53 proto_tree_add_text(tree, tvb, offset, len, "Request Line: %.*s",
58 dissect_irc_response(proto_tree *tree, tvbuff_t *tvb, int offset, int len,
59 const char *line, int linelen)
61 proto_tree_add_boolean_hidden(tree, hf_irc_response, tvb, offset, len,
63 proto_tree_add_text(tree, tvb, offset, len, "Response Line: %.*s",
68 dissect_irc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
70 proto_tree *irc_tree, *ti;
76 if (check_col(pinfo->cinfo, COL_PROTOCOL))
77 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IRC");
79 if (check_col(pinfo->cinfo, COL_INFO))
81 col_set_str(pinfo->cinfo, COL_INFO,
82 (pinfo->match_port == pinfo->destport) ? "Request" : "Response");
87 ti = proto_tree_add_item(tree, proto_irc, tvb, 0, -1, FALSE);
88 irc_tree = proto_item_add_subtree(ti, ett_irc);
91 * Process the packet data, a line at a time.
93 while (tvb_offset_exists(tvb, offset))
96 * Find the end of the line.
98 linelen = tvb_find_line_end(tvb, offset, -1,
102 * Get a buffer that refers to the line (without
103 * the line terminator).
105 line = tvb_get_ptr(tvb, offset, linelen);
109 if (pinfo->match_port == pinfo->destport)
111 dissect_irc_request(irc_tree, tvb,
112 offset, next_offset - offset,
117 dissect_irc_response(irc_tree, tvb,
118 offset, next_offset - offset,
122 offset = next_offset;
128 proto_register_irc(void)
130 static hf_register_info hf[] = {
132 { "Response", "irc.response",
133 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
134 "TRUE if IRC response", HFILL }},
137 { "Request", "irc.request",
138 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
139 "TRUE if IRC request", HFILL }},
142 { "Command", "irc.command",
143 FT_STRING, BASE_NONE, NULL, 0x0,
144 "Command associated with request", HFILL }}
147 static gint *ett[] = {
150 proto_irc = proto_register_protocol("Internet Relay Chat", "IRC", "irc");
151 proto_register_field_array(proto_irc, hf, array_length(hf));
152 proto_register_subtree_array(ett, array_length(ett));
156 proto_reg_handoff_irc(void)
158 dissector_handle_t irc_handle;
160 irc_handle = create_dissector_handle(dissect_irc, proto_irc);
161 dissector_add("tcp.port", TCP_PORT_IRC, irc_handle);