![Guy Harris](/assets/img/avatar_default.png)
statements. Move the setting of the Protocol column in various dissectors before anything is fetched from the packet, and also clear the Info column at that point in those and some other dissectors, so that if an exception is thrown, the columns don't reflect the previous protocol. Don't use col_add_fstr(..., "%s", string); Use col_add_str(..., string); as it does the same thing, but doesn't drag all the heavy *printf machinery in. Fix the DDTP dissector to set the Info column regardless of whether we're building a protocol tree or not, and to set it to "Encrypted payload" if the payload is encrypted. Also fix a typo in a field name. Register the FTP data dissector as being associated with the FTP data protocol, not the FTP protocol (the removed "CHECK_DISPLAY_AS_DATA()" call checked "proto_ftp_data", and the removed "pinfo->current_proto =" line set it to "FTP-DATA", so it should be associated with "proto_ftp_data"). Make the H1 dissector check whether the frame has at least 2 bytes in it before checking the first two bytes; heuristic dissectors must not throw exceptions until they've accepted the packet as one of theirs. Use "tvb_format_text()" rather than "tvb_get_ptr()" and "format_text()" in some dissectors where the result of "tvb_get_ptr()" is used only in the "format_text()" call. In the Quake dissector, don't check whether there are at least 4 bytes in the packet - if we return, the packet won't be dissected at all (it's not as if some other dissector will get to handle it), and, if we don't return, we'll throw an exception if there aren't at least 4 bytes in the packet, so the packet will be marked as short or malformed, as appropriate. In the RIPng dissector, associate the table of strings for the command field with the command field, so that the dissector doesn't have to format the string for the protocol tree entry itself, and so that the filter construction dialog box can let you select "Request" or "Response" from a list rather than requiring you to know the values for "Request" and "Response". Make "dissect_rpc()" static, as it's called only through a heuristic dissector list. Use "col_set_str()" to set the COL_PROTOCOL column for RPC protocols; the string used is from a table provided by the dissector, and is a string constant. Don't format the Info column for WSP into a buffer and then format that buffer into the column with "%s" - "col_add_fstr()" can do the formatting for you, without having to allocate your own buffer (or run through the *printf machinery twice). Don't fetch fields from the WTP packet until you're ready to use them, so that you don't throw an exception before you even set the Protocol column or clear the Info column. Use "pinfo->destport", not "pi.destport", in the Zebra dissector when checking whether the packet is a request or reply, and do the check by comparing with "pinfo->match_port" rather than TCP_PORT_ZEBRA (so that if the dissector is ever registered on another port, it still correctly determines whether the packet is a request or reply - the Network Monitor HTTP dissector has port 80 wired into its brain, which is a bit irritating if you're trying to get it to dissect HTTP proxy traffic on port 3128 or proxy administration UI traffic on port 3132). svn path=/trunk/; revision=2931
217 lines
6.1 KiB
C
217 lines
6.1 KiB
C
/* packet-rip.c
|
|
* Routines for RIPv1 and RIPv2 packet disassembly
|
|
* (c) Copyright Hannes R. Boehm <hannes@boehm.org>
|
|
*
|
|
* $Id: packet-rip.c,v 1.23 2001/01/22 08:03:45 guy Exp $
|
|
*
|
|
* Ethereal - Network traffic analyzer
|
|
* By Gerald Combs <gerald@zing.org>
|
|
* Copyright 1998 Gerald Combs
|
|
*
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
#include <sys/types.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
#include <netinet/in.h>
|
|
#endif
|
|
|
|
#include <string.h>
|
|
#include <glib.h>
|
|
#include "packet.h"
|
|
|
|
#define UDP_PORT_RIP 520
|
|
|
|
#define RIPv1 1
|
|
#define RIPv2 2
|
|
|
|
static const value_string version_vals[] = {
|
|
{ RIPv1, "RIPv1" },
|
|
{ RIPv2, "RIPv2" },
|
|
{ 0, NULL }
|
|
};
|
|
|
|
static const value_string command_vals[] = {
|
|
{ 1, "Request" },
|
|
{ 2, "Response" },
|
|
{ 3, "Traceon" },
|
|
{ 4, "Traceoff" },
|
|
{ 5, "Vendor specific (Sun)" },
|
|
{ 0, NULL }
|
|
};
|
|
|
|
#define RIP_HEADER_LENGTH 4
|
|
#define RIP_ENTRY_LENGTH 20
|
|
|
|
static int proto_rip = -1;
|
|
|
|
static gint ett_rip = -1;
|
|
static gint ett_rip_vec = -1;
|
|
|
|
static void dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
|
|
proto_tree *tree);
|
|
static void dissect_rip_authentication(tvbuff_t *tvb, int offset,
|
|
proto_tree *tree);
|
|
|
|
static void
|
|
dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
{
|
|
int offset = 0;
|
|
proto_tree *rip_tree = NULL;
|
|
proto_item *ti;
|
|
guint8 command;
|
|
guint8 version;
|
|
guint16 family;
|
|
guint reported_length;
|
|
|
|
if (check_col(pinfo->fd, COL_PROTOCOL))
|
|
col_set_str(pinfo->fd, COL_PROTOCOL, "RIP");
|
|
if (check_col(pinfo->fd, COL_INFO))
|
|
col_clear(pinfo->fd, COL_INFO);
|
|
|
|
command = tvb_get_guint8(tvb, 0);
|
|
version = tvb_get_guint8(tvb, 1);
|
|
|
|
if (check_col(pinfo->fd, COL_PROTOCOL))
|
|
col_add_str(pinfo->fd, COL_PROTOCOL,
|
|
val_to_str(version, version_vals, "RIP"));
|
|
if (check_col(pinfo->fd, COL_INFO))
|
|
col_add_str(pinfo->fd, COL_INFO,
|
|
val_to_str(command, command_vals, "Unknown command (%u)"));
|
|
|
|
if (tree) {
|
|
ti = proto_tree_add_item(tree, proto_rip, tvb, 0, tvb_length(tvb), FALSE);
|
|
rip_tree = proto_item_add_subtree(ti, ett_rip);
|
|
|
|
proto_tree_add_text(rip_tree, tvb, 0, 1, "Command: %u (%s)", command,
|
|
val_to_str(command, command_vals, "Unknown"));
|
|
proto_tree_add_text(rip_tree, tvb, 1, 1, "Version: %u", version);
|
|
if (version == RIPv2)
|
|
proto_tree_add_text(rip_tree, tvb, 2, 2, "Routing Domain: %u",
|
|
tvb_get_ntohs(tvb, 2));
|
|
|
|
/* skip header */
|
|
offset = RIP_HEADER_LENGTH;
|
|
|
|
/* zero or more entries */
|
|
reported_length = tvb_reported_length(tvb);
|
|
while (offset < reported_length) {
|
|
family = tvb_get_ntohs(tvb, offset);
|
|
switch (family) {
|
|
case 2: /* IP */
|
|
dissect_ip_rip_vektor(tvb, offset, version, rip_tree);
|
|
break;
|
|
case 0xFFFF:
|
|
dissect_rip_authentication(tvb, offset, rip_tree);
|
|
break;
|
|
default:
|
|
proto_tree_add_text(rip_tree, tvb, offset,
|
|
RIP_ENTRY_LENGTH, "Unknown address family %u",
|
|
family);
|
|
break;
|
|
}
|
|
|
|
offset += RIP_ENTRY_LENGTH;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
|
|
proto_tree *tree)
|
|
{
|
|
proto_item *ti;
|
|
proto_tree *rip_vektor_tree;
|
|
guint8 *ip;
|
|
guint32 metric;
|
|
|
|
ip = tvb_get_ptr(tvb, offset+4, 4);
|
|
metric = tvb_get_ntohl(tvb, offset+16);
|
|
ti = proto_tree_add_text(tree, tvb, offset,
|
|
RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
|
|
ip_to_str(ip), metric);
|
|
rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);
|
|
|
|
proto_tree_add_text(rip_vektor_tree, tvb, offset, 2,
|
|
"Address Family ID: IP");
|
|
if (version == RIPv2)
|
|
proto_tree_add_text(rip_vektor_tree, tvb, offset + 2, 2,
|
|
"Route Tag: %u", tvb_get_ntohs(tvb, offset+2));
|
|
proto_tree_add_text(rip_vektor_tree, tvb, offset + 4, 4, "IP Address: %s",
|
|
ip_to_str(ip));
|
|
if (version == RIPv2) {
|
|
proto_tree_add_text(rip_vektor_tree, tvb, offset + 8, 4,
|
|
"Netmask: %s",
|
|
ip_to_str(tvb_get_ptr(tvb, offset + 8, 4)));
|
|
proto_tree_add_text(rip_vektor_tree, tvb, offset + 12, 4,
|
|
"Next Hop: %s",
|
|
ip_to_str(tvb_get_ptr(tvb, offset+12, 4)));
|
|
}
|
|
proto_tree_add_text(rip_vektor_tree, tvb, offset + 16, 4, "Metric: %u",
|
|
metric);
|
|
}
|
|
|
|
static void
|
|
dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree)
|
|
{
|
|
proto_item *ti;
|
|
proto_tree *rip_authentication_tree;
|
|
guint16 authtype;
|
|
char authentication[16];
|
|
|
|
ti = proto_tree_add_text(tree, tvb, offset, RIP_ENTRY_LENGTH,
|
|
"Authentication");
|
|
rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec);
|
|
|
|
authtype = tvb_get_ntohs(tvb, offset + 2);
|
|
proto_tree_add_text(rip_authentication_tree, tvb, offset + 2, 2,
|
|
"Authentication type: %u", authtype);
|
|
if (authtype == 2) {
|
|
tvb_get_nstringz0(tvb, offset + 4, 16, authentication);
|
|
proto_tree_add_text(rip_authentication_tree, tvb, offset + 4, 16,
|
|
"Password: %s", authentication);
|
|
}
|
|
}
|
|
|
|
void
|
|
proto_register_rip(void)
|
|
{
|
|
/* static hf_register_info hf[] = {
|
|
{ &variable,
|
|
{ "Name", "rip.abbreviation", TYPE, VALS_POINTER }},
|
|
};*/
|
|
static gint *ett[] = {
|
|
&ett_rip,
|
|
&ett_rip_vec,
|
|
};
|
|
|
|
proto_rip = proto_register_protocol("Routing Information Protocol",
|
|
"RIP", "rip");
|
|
/* proto_register_field_array(proto_rip, hf, array_length(hf));*/
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
}
|
|
|
|
void
|
|
proto_reg_handoff_rip(void)
|
|
{
|
|
dissector_add("udp.port", UDP_PORT_RIP, dissect_rip, proto_rip);
|
|
}
|