Ethereal-dev: Re: [Ethereal-dev] Problems registering a new protocol
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Ed Warnicke <hagbard@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 22 Oct 2000 16:01:43 -0400 (EDT)
OK, here is my packet-mgcp.c, it's almost unaltered from what the
build-dissector.pl script produced, so it's absolutely useless
as a dissector, but if I can just figure out why it won't register
I'll correct that. Here are the packet-mgcp.c followed by the
packet-mgcp.h.
Ed
-----------------------------Cut Here------------------------------
/* packet-mgcp.c
* Routines for mgcp packet disassembly
*
* $Id: $
*
* Copyright (c) 2000 by YOUR NAME HERE <YOUR EMAIL HERE>
*
* Ethereal - Network traffic analyzer
* By Gerald Combs
* Copyright 1999 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <glib.h>
#include <string.h>
#include "packet.h"
#include "resolv.h"
#include "prefs.h"
#include "strutil.h"
#define TCP_PORT_MGCP 2437
void proto_reg_handoff_mgcp(void);
static int proto_mgcp = -1;
/* Delete the following if you do not use it, or add to it if you need */
static int hf_mgcp_req = -1;
static int hf_mgcp_rsp = -1;
static int ett_mgcp = -1;
static int tcp_port = 0;
/* Add your functions here */
static int global_mgcp_tcp_port = TCP_PORT_MGCP;
#if 0
static void
dissect_mgcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
#else
static void
dissect_mgcp(const u_char *pd, int offset, frame_data *fd,
proto_tree *tree)
{
tvbuff_t *tvb = tvb_create_from_top(offset);
packet_info *pinfo = π
#endif
proto_tree *mgcp_tree, *ti;
/* Add your variables here */
#if 0
CHECK_DISPLAY_AS_DATA(proto_mgcp, tvb, pinfo, tree);
#else
OLD_CHECK_DISPLAY_AS_DATA(proto_mgcp, pd, offset, fd, tree);
#endif
/* Add your dissection code here */
if (check_col(fd, COL_PROTOCOL))
col_add_str(fd, COL_PROTOCOL, "MGCP");
if (check_col(fd, COL_INFO)) { /* Check the type ... */
/* col_add_fstr(fd, COL_INFO, "%s", format_text(cmd,
END_OF_FRAME)); */
col_add_fstr(fd,COL_INFO, "%s", "HI");
}
if (tree) { /* Build the tree info ... */
/* Add your dissection code here to build a tree */
}
}
/* Register all the bits needed with the filtering engine */
void
proto_register_mgcp(void)
{
static hf_register_info hf[] = {
{ &hf_mgcp_req,
/* Change the following to the type you need */
{ "Request", "mgcp.req", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
{ &hf_mgcp_rsp,
{ "Response", "mgcp.rsp", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "" }},
/* Add more fields here */
};
static gint *ett[] = {
&ett_mgcp
};
module_t *mgcp_module;
/* Register our configuration options for , particularly our port */
mgcp_module = prefs_register_module("mgcp", "MGCP",
proto_reg_handoff_mgcp);
prefs_register_uint_preference(mgcp_module, "tcp.port", "MGCP TCP Port",
"Set the port for messages (if other"
" than the default of <ADD PORT HERE>)",
10, &global_mgcp_tcp_port);
proto_mgcp = proto_register_protocol("ADD NAME HERE",
"mgcp");
proto_register_field_array(proto_mgcp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
/* The registration hand-off routine */
void
proto_reg_handoff_mgcp(void)
{
static int mgcp_prefs_initialized = FALSE;
if (mgcp_prefs_initialized) {
old_dissector_delete("tcp.port", tcp_port, dissect_mgcp);
}
else {
mgcp_prefs_initialized = TRUE;
}
/* Set our port number for future use */
tcp_port = global_mgcp_tcp_port;
old_dissector_add("tcp.port", global_mgcp_tcp_port, dissect_mgcp);
}
----------------------------Cut Here---------------------------------
/* packet-mgcp.h
*
* $Id: packet-mgcp.h,v 1.2 2000/08/11 13:34:12 deniel Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@xxxxxxxx>
* 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.
*/
#ifndef __PACKET_MGCP_H__
#define __PACKET_MGCP_H__
void dissect_mgcp(const u_char *, int, frame_data *, proto_tree *);
#endif
----------------------------Cut Here---------------------------------
On Sun, 22 Oct 2000, Guy Harris wrote:
> On Sun, Oct 22, 2000 at 02:43:01PM -0400, Ed Warnicke wrote:
> > I am slightly concerned that at the end of the
> > register_all_protocol_handoffs function there are duplicate entries for
> >
> > {extern void proto_reg_handoff_bxxp (void); proto_reg_handoff_bxxp ();}
> > {extern void proto_reg_handoff_diameter (void);
> > proto_reg_handoff_diameter ();}
> > {extern void proto_reg_handoff_mgcp (void); proto_reg_handoff_mgcp ();}
> > {extern void proto_reg_handoff_smtp (void); proto_reg_handoff_smtp ();}
>
> That's because the dissectors in question declare the "reg_handoff"
> routines for the protocols, as well as defining them, and the script
> that generates "register.c" recognizes both the declaration and the
> definition.
>
> I'm not sure why they're declared (if it's to squelch GCC warnings,
> why then didn't they declare the register routine?), and I'll remove the
> declarations, unless somebody comes up with a reason why the handoff
> registration routines for those dissectors *must* be called twice.
>
> > So now I make. Everything compiles fine and links fine and make
> > terminates with no complaints over the warning level from the compiler.
> >
> > I run the newly compiled ethereal. Everything launches fine, no problems.
> >
> > I bring click on Edit->Protocols and the Protocols dialog comes
> > up. It doesn't show mgcp (but it does show bxxp, diameter, and smtp,
> > which is why I think the duplication mentioned above is benign).
>
> Protocols show up in the Protocols dialog if they've been registered;
> registration is done by the registration routine, not by the handoff
> registration routine, and it's the handoff registration routines in
> question that are being called twice.
>
> > I close the proto_dlg. I try to enter the string "mgcp" in the
> > filter textbox at the button of the window. I get a response
> > 'Unable to parse filter string "mgcp"'. Clearly something has gone
> > wrong.
> >
> > So I proceeded to go through this process again with the skeleton code
> > provided in the doc/README.developer file and with skeleton code
> > generated by the build-dissector.pl script (running make dist-clean
> > between attempts). Both yielded the same response.
> >
> > I'm stuck. What am I doing wrong?
>
> I'm stuck, too, because I don't have a copy of your
> "proto_register_mgcp()" routine, and thus can't tell what it's doing
> wrong so that the MGCP protocol doesn't get registered.
>
> _______________________________________________
> Ethereal-dev mailing list
> Ethereal-dev@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-dev
>
- Follow-Ups:
- Re: [Ethereal-dev] Problems registering a new protocol
- From: Guy Harris
- Re: [Ethereal-dev] Problems registering a new protocol
- References:
- Re: [Ethereal-dev] Problems registering a new protocol
- From: Guy Harris
- Re: [Ethereal-dev] Problems registering a new protocol
- Prev by Date: Re: [Ethereal-dev] Problems registering a new protocol
- Next by Date: Re: [Ethereal-dev] Problems registering a new protocol
- Previous by thread: Re: [Ethereal-dev] Problems registering a new protocol
- Next by thread: Re: [Ethereal-dev] Problems registering a new protocol
- Index(es):