2 * Routines for MSX irc packet dissection
4 * $Id: packet-irc.c,v 1.10 2001/01/03 06:55:29 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
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.
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 # include <netinet/in.h>
45 static int proto_irc = -1;
46 static int hf_irc_request = -1;
47 static int hf_irc_response = -1;
48 static int hf_irc_command = -1;
50 static gint ett_irc = -1;
52 #define TCP_PORT_IRC 6667
53 /* good candidate for dynamic port specification */
56 dissect_irc_request(proto_tree *tree, char *line, int offset, int len)
58 proto_tree_add_boolean_hidden(tree, hf_irc_request, NullTVB,
60 proto_tree_add_text(tree, NullTVB, offset,
61 len, "Request Line: %s", line);
65 dissect_irc_response(proto_tree *tree, char *line, int offset, int len)
67 proto_tree_add_boolean_hidden(tree, hf_irc_response, NullTVB,
69 proto_tree_add_text(tree, NullTVB, offset,
70 len, "Response Line: %s", line);
74 dissect_irc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
76 proto_tree *irc_tree, *ti;
81 OLD_CHECK_DISPLAY_AS_DATA(proto_irc, pd, offset, fd, tree);
83 if (check_col(fd, COL_PROTOCOL))
84 col_set_str(fd, COL_PROTOCOL, "IRC");
86 if (check_col(fd, COL_INFO))
88 col_add_fstr(fd, COL_INFO, "%s",
89 (pi.match_port == pi.destport) ? "Request" : "Response");
94 ti = proto_tree_add_item(tree, proto_irc, NullTVB, offset, END_OF_FRAME, FALSE);
95 irc_tree = proto_item_add_subtree(ti, ett_irc);
97 tmpline = (char *)g_malloc( pi.captured_len );
99 while ( i < pd + pi.captured_len )
106 /* copy up to end or cr/nl */
107 while ( i < pd + pi.captured_len && *i != '\r' && *i != '\n' )
109 tmpline[cur++] = *(i++);
115 while ( i < pd + pi.captured_len &&
116 (*i == '\r' || *i == '\n') )
122 if ( strlen(tmpline) > 0 )
124 if (pi.match_port == pi.destport)
126 dissect_irc_request(irc_tree, tmpline, start, len);
130 dissect_irc_response(irc_tree, tmpline, start, len);
140 proto_register_irc(void)
142 static hf_register_info hf[] = {
144 { "Response", "irc.response",
145 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
146 "TRUE if IRC response" }},
149 { "Request", "irc.request",
150 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
151 "TRUE if IRC request" }},
154 { "Command", "irc.command",
155 FT_STRING, BASE_NONE, NULL, 0x0,
156 "Command associated with request" }}
159 static gint *ett[] = {
162 proto_irc = proto_register_protocol("Internet Relay Chat", "IRC", "irc");
163 proto_register_field_array(proto_irc, hf, array_length(hf));
164 proto_register_subtree_array(ett, array_length(ett));
168 proto_reg_handoff_irc(void)
170 old_dissector_add("tcp.port", TCP_PORT_IRC, dissect_irc);