Ethereal-dev: [Ethereal-dev] New dissector not working

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "bunty " <bunty123_4@xxxxxxxxxxxxxx>
Date: 2 Apr 2005 13:51:59 -0000

 
Hello,
    I added a new disscetor on linux to ethereal. I followed README.developer and write code. My aim is to add new header in between Ethernet header and IP header. My problem is that Ethereal is not displaying my header, instead display next all headers e.g. IP/ICMP headers.
   
    My code to add dissector is
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/ipproto.h>
#include "etypes.h"
#include "packet-myip.h"


void proto_reg_handoff_myip(void);
static int proto_myip = -1;
static gint ett_myip = -1;
static int hf_myip_num = -1;
static unsigned char* hf_myip_text = -1;
static void dissect_myip(tvbuff_t *, packet_info *, proto_tree *);
static dissector_handle_t data_handle;


void capture_myip(const guchar *pd, int offset, int len, packet_counts *ld) {
  if (!BYTES_ARE_IN_FRAME(offset, len, 28)) {
    ld->other++;
    return;
  }
  switch (pd[offset + 17]) {
    case IP_PROTO_SCTP:
      ld->sctp++;
      break;
    case IP_PROTO_TCP:
      ld->tcp++;
      break;
    case IP_PROTO_UDP:
      ld->udp++;
      break;
    case IP_PROTO_ICMP:
    case IP_PROTO_ICMPV6:      /* XXX - separate counters? */
      ld->icmp++;
      break;
    case IP_PROTO_OSPF:
      ld->ospf++;
      break;
    case IP_PROTO_GRE:
      ld->gre++;
      break;
    case IP_PROTO_VINES:
      ld->vines++;
      break;
    default:
      ld->other++;
  }
}


static void dissect_myip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
     if (check_col(pinfo->cinfo, COL_PROTOCOL))
          col_set_str(pinfo->cinfo, COL_PROTOCOL, "myip");
if (check_col(pinfo->cinfo, COL_INFO))
          col_clear(pinfo->cinfo, COL_INFO);
}

void proto_register_myip(void)
{               
  module_t *myip_module;
     static hf_register_info hf[] = {
          { &hf_myip_text,
          { "myip_text",          "myip.text", FT_STRING, BASE_HEX, NULL, 0x0,"", HFILL }},
          { &hf_myip_num,
          { "myip_num",          "myip.num", FT_UINT32, BASE_DEC, NULL, 0x0,"", HFILL }}
};

     static gint *ett[] = {
          &ett_myip,
     };
     proto_myip = proto_register_protocol("My Internet Protocol","MYIP", "myip");
     proto_register_field_array(proto_myip, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
        myip_module = prefs_register_protocol(proto_myip, proto_reg_handoff_myip);
}

void proto_reg_handoff_myip(void)
{
dissector_handle_t myip_handle;
     data_handle = find_dissector("data");
      myip_handle = find_dissector("myip");
     dissector_add("ethertype", ETHERTYPE_MYIP, myip_handle);

}


        I also dont understood how to call IP header parsing and display not only my header contents but also all subsequent header. I only getting hex dump of all packet except my header but actally at application layer i am receiving packet without error.
Thanks in advance.
regards,
bunty.