1999-12-06 23:57:51 +00:00
|
|
|
/* packet-irc.c
|
2001-02-03 08:07:04 +00:00
|
|
|
* Routines for IRC packet dissection
|
1999-12-06 23:57:51 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1999-12-06 23:57:51 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-12-03 04:00:26 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1999-12-06 23:57:51 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-tftp.c
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-12-06 23:57:51 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-12-06 23:57:51 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1999-12-06 23:57:51 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
1999-12-06 23:57:51 +00:00
|
|
|
|
|
|
|
static int proto_irc = -1;
|
|
|
|
static int hf_irc_request = -1;
|
|
|
|
static int hf_irc_response = -1;
|
|
|
|
|
|
|
|
static gint ett_irc = -1;
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
#define TCP_PORT_IRC 6667
|
|
|
|
/* good candidate for dynamic port specification */
|
|
|
|
|
|
|
|
static void
|
2005-09-23 21:33:02 +00:00
|
|
|
dissect_irc_request(proto_tree *tree, tvbuff_t *tvb, int offset, int linelen)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2005-09-23 21:33:02 +00:00
|
|
|
proto_tree_add_item(tree, hf_irc_request, tvb, offset, linelen, TRUE);
|
1999-12-06 23:57:51 +00:00
|
|
|
}
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
static void
|
2005-09-23 21:33:02 +00:00
|
|
|
dissect_irc_response(proto_tree *tree, tvbuff_t *tvb, int offset, int linelen)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2005-09-23 21:33:02 +00:00
|
|
|
proto_tree_add_item(tree, hf_irc_response, tvb, offset, linelen, TRUE);
|
1999-12-06 23:57:51 +00:00
|
|
|
}
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
static void
|
2001-02-03 07:58:27 +00:00
|
|
|
dissect_irc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
|
|
|
proto_tree *irc_tree, *ti;
|
2001-02-03 07:58:27 +00:00
|
|
|
gint offset = 0;
|
|
|
|
gint next_offset;
|
|
|
|
int linelen;
|
1999-12-06 23:57:51 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "IRC");
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2001-12-10 00:26:21 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO,
|
2001-02-03 08:07:04 +00:00
|
|
|
(pinfo->match_port == pinfo->destport) ? "Request" : "Response");
|
1999-12-06 23:57:51 +00:00
|
|
|
}
|
|
|
|
|
2001-02-03 07:58:27 +00:00
|
|
|
if (tree)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_irc, tvb, 0, -1, FALSE);
|
1999-12-06 23:57:51 +00:00
|
|
|
irc_tree = proto_item_add_subtree(ti, ett_irc);
|
|
|
|
|
2001-02-03 07:58:27 +00:00
|
|
|
/*
|
|
|
|
* Process the packet data, a line at a time.
|
|
|
|
*/
|
2005-09-23 21:33:02 +00:00
|
|
|
while (tvb_reported_length_remaining(tvb, offset) > 0)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2001-02-03 07:58:27 +00:00
|
|
|
/*
|
|
|
|
* Find the end of the line.
|
|
|
|
*/
|
2005-09-23 21:33:02 +00:00
|
|
|
linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
|
2005-10-24 02:35:43 +00:00
|
|
|
if (next_offset == offset) {
|
|
|
|
/*
|
|
|
|
* XXX - we really want the "show data a
|
|
|
|
* line at a time" loops in various
|
|
|
|
* dissectors to do reassembly and to
|
|
|
|
* throw an exception if there's no
|
|
|
|
* line ending in the current packet
|
|
|
|
* and we're not doing reassembly.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2001-02-03 07:58:27 +00:00
|
|
|
|
|
|
|
if (linelen != 0)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2001-02-03 08:07:04 +00:00
|
|
|
if (pinfo->match_port == pinfo->destport)
|
1999-12-06 23:57:51 +00:00
|
|
|
{
|
2005-09-23 21:33:02 +00:00
|
|
|
dissect_irc_request(irc_tree, tvb, offset, linelen);
|
1999-12-06 23:57:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-23 21:33:02 +00:00
|
|
|
dissect_irc_response(irc_tree, tvb, offset, linelen);
|
1999-12-06 23:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-03 07:58:27 +00:00
|
|
|
offset = next_offset;
|
1999-12-06 23:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_irc(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_irc_response,
|
|
|
|
{ "Response", "irc.response",
|
2005-09-23 21:33:02 +00:00
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
|
|
|
"Line of response message", HFILL }},
|
2002-08-28 21:04:11 +00:00
|
|
|
|
1999-12-06 23:57:51 +00:00
|
|
|
{ &hf_irc_request,
|
|
|
|
{ "Request", "irc.request",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2005-09-23 21:33:02 +00:00
|
|
|
"Line of request message", HFILL }},
|
1999-12-06 23:57:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_irc,
|
|
|
|
};
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_irc = proto_register_protocol("Internet Relay Chat", "IRC", "irc");
|
1999-12-06 23:57:51 +00:00
|
|
|
proto_register_field_array(proto_irc, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
2000-04-08 07:07:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_irc(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t irc_handle;
|
2000-04-08 07:07:42 +00:00
|
|
|
|
2001-12-03 04:00:26 +00:00
|
|
|
irc_handle = create_dissector_handle(dissect_irc, proto_irc);
|
|
|
|
dissector_add("tcp.port", TCP_PORT_IRC, irc_handle);
|
|
|
|
}
|