Remove all $Id$ from top of file
[metze/wireshark/wip.git] / epan / dissectors / dcerpc / idl2wrs.c
index e5740890bea235637cdd07248bf12a12c5623944..8c4f73b0d1a96b1c4a54b7310a2e635c9054a270 100644 (file)
@@ -1,9 +1,31 @@
-/* 
+/* idl2wrs.c
+ * DCE RPC IDL to Wireshark dissector compiler
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
 TODO
    check that every cnf defined type,hffield,rename,... has been referenced
    at least once and if not,   abort with an error
 
-   need to distinguish between NTTIME (absolute time) and relative time 
+   need to distinguish between NTTIME (absolute time) and relative time
 
    prune_xxx should only act inside of '[' ']'
 
@@ -35,15 +57,15 @@ TODO
    NTTIME_hyper A 64 bit integer representing a NTTIME
    NTTIME_1sec
 
-   unistr       A conformant and varying unicode string
+   unistr              A conformant and varying unicode string
 
-   ascstr       A conformant and varying ascii string
+   ascstr              A conformant and varying ascii string
 
 
-   SID          A SID structure.
+   SID                 A SID structure.
 
    uuid_t      A 16 byte FT_GUID blob.
-   GUID                
+   GUID
 
 
    policy_handle
@@ -53,7 +75,7 @@ TODO
    NTTIME
 */
 
-/* All field dissectors that call a normal type 
+/* All field dissectors that call a normal type
    (i.e. not a pointer, not an array)
    has a local variable  guint param declared which is passed on to the
    type dissector.
@@ -67,28 +89,36 @@ TODO
 #include <stdlib.h>
 #include <stdarg.h>
 
-FILE *fh, *tfh, *eth_code, *eth_hdr, *eth_hf, *eth_hfarr, *eth_ett, *eth_ettarr, *eth_ft, *eth_handoff;
-char *uuid=NULL;
-char *version=NULL;
-char *pointer_default=NULL;
-char *ifname=NULL;
-char hf_status[256];
-int lineno,linepos;
-char line[1024];
+#undef IDL2WRS_DEBUG
+
+static FILE *tfh, *eth_code, *eth_hdr, *eth_hf, *eth_hfarr, *eth_ett, *eth_ettarr, *eth_ft, *eth_handoff;
+static char *uuid=NULL;
+static char *version=NULL;
+static const char *pointer_default=NULL;
+static char *ifname=NULL;
+static char hf_status[256];
+static int lineno,linepos;
+static char line[1024];
 
-void FPRINTF(FILE *fh, const char *format, ...)
+static void FPRINTF(FILE *fh, const char *format, ...)
 {
        va_list args;
+
+#ifdef IDL2WRS_DEBUG
        va_start(args, format);
        vfprintf (stderr, format, args);
-       if (fh)
-               vfprintf (fh, format, args);
        va_end(args);
+#endif
+       if (fh) {
+               va_start(args, format);
+               vfprintf (fh, format, args);
+               va_end(args);
+       }
 }
 
 typedef struct _pointer_item_t {
        struct _pointer_item_t *next;
-       char *type;
+       const char *type;
 } pointer_item_t;
 
 #define BI_CASE                        0x00000001
@@ -102,8 +132,8 @@ typedef struct _pointer_item_t {
 #define BI_BITMAP32            0x00000200
 #define BI_SWITCH_TYPE         0x00000400
 typedef struct _bracket_item_t {
-       long int flags;
-       char *case_name;
+       unsigned int flags;
+       const char *case_name;
        pointer_item_t *pointer_list;
        int union_tag_size;
 } bracket_item_t;
@@ -112,7 +142,7 @@ typedef struct _no_emit_item_t {
        struct _no_emit_item_t *next;
        char *name;
 } no_emit_item_t;
-no_emit_item_t *no_emit_list=NULL;
+static no_emit_item_t *no_emit_list=NULL;
 
 typedef struct _hf_rename_item_t {
        struct _hf_rename_item_t *next;
@@ -120,7 +150,7 @@ typedef struct _hf_rename_item_t {
        char *old_name;
        char *new_name;
 } hf_rename_item_t;
-hf_rename_item_t *hf_rename_list=NULL;
+static hf_rename_item_t *hf_rename_list=NULL;
 
 typedef struct _enum_list_t {
        struct _enum_list_t *next;
@@ -128,14 +158,12 @@ typedef struct _enum_list_t {
        int val;
 } enum_list_t;
 
-
 typedef struct _token_item_t {
        struct _token_item_t *next;
        char *str;
 } token_item_t;
-token_item_t *token_list=NULL;
-token_item_t *last_token_item=NULL;
-
+static token_item_t *token_list=NULL;
+static token_item_t *last_token_item=NULL;
 
 typedef struct _type_item_t {
        struct _type_item_t *next;
@@ -147,43 +175,44 @@ typedef struct _type_item_t {
        char *vals;
        int alignment;
 } type_item_t;
-type_item_t *type_list=NULL;
+static type_item_t *type_list=NULL;
 
 typedef struct _union_tag_size_item_t {
        struct _union_tag_size_item_t *next;
        char *name;
        int size;
 } union_tag_size_item_t;
-union_tag_size_item_t *union_tag_size_list=NULL;
+static union_tag_size_item_t *union_tag_size_list=NULL;
 
 typedef struct _hf_field_item_t {
        struct _hf_field_item_t *next;
        char *name;
        char *ft_type;
 } hf_field_item_t;
-hf_field_item_t *hf_field_list=NULL;
+static hf_field_item_t *hf_field_list=NULL;
 
 typedef struct _dissector_param_value_t {
        struct _dissector_param_value_t *next;
        char *name;
        char *value;
 } dissector_param_value_t;
-dissector_param_value_t *dissector_param_list=NULL;
+static dissector_param_value_t *dissector_param_list=NULL;
 
 static type_item_t *find_type(char *name);
+static int Exit(int code);
 
-void
+static void
 register_dissector_param_value(char *name, char *value)
 {
        dissector_param_value_t *dpv;
-       dpv=malloc(sizeof(dissector_param_value_t));
+       dpv=(dissector_param_value_t*)malloc(sizeof(dissector_param_value_t));
        dpv->next=dissector_param_list;
        dissector_param_list=dpv;
        dpv->name=strdup(name);
        dpv->value=strdup(value);
 }
 
-char *
+static const char *
 find_dissector_param_value(char *name)
 {
        dissector_param_value_t *dpv;
@@ -195,7 +224,7 @@ find_dissector_param_value(char *name)
        return "0";
 }
 
-pointer_item_t *
+static pointer_item_t *
 prepend_pointer_list(pointer_item_t *ptrs, int num_pointers)
 {
        pointer_item_t *pi;
@@ -207,7 +236,7 @@ prepend_pointer_list(pointer_item_t *ptrs, int num_pointers)
        }
        if(!pi)pi=ptrs;
        while(num_pointers--){
-               pi=malloc(sizeof(pointer_item_t));
+               pi=(pointer_item_t*)malloc(sizeof(pointer_item_t));
                pi->next=ptrs;
                pi->type=pointer_default;
                ptrs=pi;
@@ -217,8 +246,8 @@ prepend_pointer_list(pointer_item_t *ptrs, int num_pointers)
        return ptrs;
 }
 
-char *
-ptr_to_define(char *pointer_type)
+static const char *
+ptr_to_define(const char *pointer_type)
 {
        if(!strcmp(pointer_type, "unique")){
                return "NDR_POINTER_UNIQUE";
@@ -228,11 +257,11 @@ ptr_to_define(char *pointer_type)
                return "NDR_POINTER_PTR";
        }
 
-       fprintf(stderr, "prt_to_define,     weirdo pointer :%s\n", pointer_type);
+       fprintf(stderr, "prt_to_define,         weirdo pointer :%s\n", pointer_type);
        exit(10);
 }
 
-int
+static int
 get_union_tag_size(char *name)
 {
        union_tag_size_item_t *utsi;
@@ -242,17 +271,17 @@ get_union_tag_size(char *name)
                }
        }
        fprintf(stderr, "ERROR: size of tag for union:%s is not known\n", name);
-       fprintf(stderr, "  use the UNION_TAG_SIZE directive to specify it in teh conformance file\n", name);
+       fprintf(stderr, "  use the UNION_TAG_SIZE directive to specify it in teh conformance file\n");
        exit(10);
 }
 
 
 /* this function will add an entry to the hf_rename list */
-void
+static void
 register_hf_rename(char *old_name, char *new_name)
 {
        hf_rename_item_t *new_item;
-       new_item=malloc(sizeof(hf_rename_item_t));
+       new_item=(hf_rename_item_t*)malloc(sizeof(hf_rename_item_t));
        new_item->next=hf_rename_list;
        hf_rename_list=new_item;
        new_item->refcount=0;
@@ -261,9 +290,9 @@ register_hf_rename(char *old_name, char *new_name)
 }
 
 /* this function checks that all hf_rename fields have actually been referenced
-   if not   out conformance file is stale
+   if not      out conformance file is stale
 */
-void
+static void
 check_hf_rename_refcount(void)
 {
        hf_rename_item_t *hri;
@@ -277,18 +306,22 @@ check_hf_rename_refcount(void)
        }
 }
 
-hf_field_item_t *
+static hf_field_item_t *
 find_hf_field(char *name)
 {
        hf_field_item_t *hfi;
 
        for(hfi=hf_field_list;hfi;hfi=hfi->next){
                if(!strcmp(hfi->name, name)){
-                       return hfi;
+                       break;
                }
        }
-       fprintf(stderr, "find_hf_field:  unknown hf_field:%s\n",name);
-       Exit(10);
+       if (!hfi) {
+               fprintf(stderr, "find_hf_field:  unknown hf_field:%s\n",name);
+               Exit(10);
+       }
+
+       return hfi;
 }
 
 
@@ -297,8 +330,8 @@ find_hf_field(char *name)
    from this function.
    for fields that are to be renamed  no code is generated
 */
-char *
-register_hf_field(char *hf_name, char *title, char *filter_name, char *ft_type, char *base_type, char *valsstring, char *mask, char *blurb)
+static const char *
+register_hf_field(const char *hf_name, const char *title, const char *filter_name, const char *ft_type, const char *base_type, const char *valsstring, const char *mask, const char *blurb)
 {
        hf_field_item_t *hfi;
        hf_rename_item_t *hri;
@@ -316,29 +349,29 @@ register_hf_field(char *hf_name, char *title, char *filter_name, char *ft_type,
                }
        }
 
-       hfi=malloc(sizeof(hf_field_item_t));
+       hfi=(hf_field_item_t*)malloc(sizeof(hf_field_item_t));
        hfi->next=hf_field_list;
        hf_field_list=hfi;
        hfi->name=strdup(hf_name);
        hfi->ft_type=strdup(ft_type);
 
        FPRINTF(eth_hf, "static int %s = -1;\n", hf_name);
-       FPRINTF(eth_hfarr, "        { &%s,\n", hf_name);
-       FPRINTF(eth_hfarr, "          { \"%s\", \"%s\", %s, %s,\n", title, filter_name, ft_type, base_type);
-       FPRINTF(eth_hfarr, "          %s, %s,\n", valsstring, mask);
+       FPRINTF(eth_hfarr, "            { &%s,\n", hf_name);
+       FPRINTF(eth_hfarr, "              { \"%s\", \"%s\", %s, %s,\n", title, filter_name, ft_type, base_type);
+       FPRINTF(eth_hfarr, "              %s, %s,\n", valsstring, mask);
        if (strlen(blurb) > 0)
-               FPRINTF(eth_hfarr, "         \"%s\", HFILL }},\n", blurb);
+               FPRINTF(eth_hfarr, "             \"%s\", HFILL }},\n", blurb);
        else
-               FPRINTF(eth_hfarr, "         NULL, HFILL }},\n");
+               FPRINTF(eth_hfarr, "             NULL, HFILL }},\n");
        FPRINTF(eth_hfarr, "\n");
 
        return hf_name;
 }
 
-/* this function will parse the no emit list and decide whether code should 
+/* this function will parse the no emit list and decide whether code should
    be generated for this dissector or if we should only register the type.
 */
-int
+static int
 check_if_to_emit(char *name)
 {
        no_emit_item_t *nel;
@@ -352,11 +385,11 @@ check_if_to_emit(char *name)
        return 1;
 }
 
-
-void
+#if 0
+static void
 prune_keywords(char *name)
 {
-       token_item_t *ti, *prevti;
+       token_item_t *ti;
 
        for(ti=token_list;ti;ti=ti->next){
                if(!ti->next){
@@ -371,8 +404,10 @@ prune_keywords(char *name)
                }
        }
 }
-void
-rename_tokens(char *old_name, char *new_name)
+#endif
+
+static void
+rename_tokens(const char *old_name, const char *new_name)
 {
        token_item_t *ti;
 
@@ -383,8 +418,8 @@ rename_tokens(char *old_name, char *new_name)
        }
 }
 
-void
-prune_keyword_parameters(char *name)
+static void
+prune_keyword_parameters(const char *name)
 {
        token_item_t *ti, *tmpti;
 
@@ -405,10 +440,10 @@ prune_keyword_parameters(char *name)
 }
 
 /* this function will parse a bracket item
-       [ ... ]
+          [ ... ]
    it will return the token of the next item following the ']'
 */
-token_item_t *
+static token_item_t *
 parsebrackets(token_item_t *ti, bracket_item_t **bracket){
        bracket_item_t *br;
        type_item_t *type_item;
@@ -419,7 +454,7 @@ parsebrackets(token_item_t *ti, bracket_item_t **bracket){
        }
        ti=ti->next;
 
-       br=malloc(sizeof(bracket_item_t));
+       br=(bracket_item_t*)malloc(sizeof(bracket_item_t));
        *bracket=br;
        br->flags=0;
        br->case_name=NULL;
@@ -686,7 +721,7 @@ parsebrackets(token_item_t *ti, bracket_item_t **bracket){
                        pointer_item_t *newpi;
 
                        br->flags|=BI_POINTER;
-                       newpi=malloc(sizeof(pointer_item_t));
+                       newpi=(pointer_item_t*)malloc(sizeof(pointer_item_t));
                        newpi->next=NULL;
                        newpi->type=ti->str;
                        newpi->next=br->pointer_list;
@@ -698,17 +733,19 @@ parsebrackets(token_item_t *ti, bracket_item_t **bracket){
                fprintf(stderr, "ERROR: parsebrackets should not be reached  unknown tag:%s\n", ti->str);
                Exit(10);
        }
+
+       return NULL;
 }
-                       
+
 /* this function will register a new type learnt from the IDL file
 */
-static type_item_t * 
-register_new_type(char *name, char *dissectorname, char *ft_type, char *base_type, char *mask, char *valsstring, int alignment){
+static type_item_t *
+register_new_type(const char *name, const char *dissectorname, const char *ft_type, const char *base_type, const char *mask, const char *valsstring, int alignment){
        type_item_t *new_type;
 
 FPRINTF(NULL,"XXX new type:%s dissector:%s Type:%s Base:%s Mask:%s Vals:%s alignment:%d\n", name, dissectorname, ft_type, base_type, mask, valsstring, alignment);
 
-       new_type=malloc(sizeof(type_item_t));
+       new_type=(type_item_t*)malloc(sizeof(type_item_t));
        new_type->next=type_list;
        new_type->name=strdup(name);
        new_type->dissector=strdup(dissectorname);
@@ -725,7 +762,7 @@ FPRINTF(NULL,"XXX new type:%s dissector:%s Type:%s Base:%s Mask:%s Vals:%s align
 
 /* this function will print the remaining content of the token list
 */
-void printtokenlist(int count)
+static void printtokenlist(int count)
 {
        token_item_t *ti;
        fprintf(stderr, "TOKENLIST:\n");
@@ -733,7 +770,7 @@ void printtokenlist(int count)
                fprintf(stderr, "Token \"%s\"\n",ti->str);
        }
        if(!count){
-               fprintf(stderr, "    ...\n");
+               fprintf(stderr, "        ...\n");
        }
 }
 
@@ -744,13 +781,13 @@ void printtokenlist(int count)
  * [ <fields> ] inteface <ifname> {
  *
  * we are interested in the fields:
- *     uuid
- *     version
- *     pointer_default
+ *        uuid
+ *        version
+ *        pointer_default
  *
  * this function will also remove the header from the token list
  */
-void parseheader(void)
+static void parseheader(void)
 {
        char filter_name[256];
        token_item_t *ti;
@@ -759,7 +796,7 @@ void parseheader(void)
 
        ti=token_list;
        if(!ti){
-               fprintf(stderr, "ERRO: no tokens\n");
+               fprintf(stderr, "ERROR: no tokens\n");
                Exit(10);
        }
 
@@ -829,7 +866,7 @@ void parseheader(void)
        register_hf_field(hf_status, "Return code", filter_name, "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", "0", "");
 
        FPRINTF(eth_ett, "static gint ett_%s = -1;\n", ifname);
-       FPRINTF(eth_ettarr, "        &ett_%s,\n", ifname);
+       FPRINTF(eth_ettarr, "            &ett_%s,\n", ifname);
 
        /* the body must start with { */
        if(strcmp(token_list->str, "{")){
@@ -845,8 +882,8 @@ void parseheader(void)
                Exit(10);
        }
        FPRINTF(eth_code,"static e_uuid_t uuid_dcerpc_%s = {\n", ifname);
-       FPRINTF(eth_code,"    0x%c%c%c%c%c%c%c%c, 0x%c%c%c%c, 0x%c%c%c%c,\n",uuid[1],uuid[2],uuid[3],uuid[4],uuid[5],uuid[6],uuid[7],uuid[8],uuid[10],uuid[11],uuid[12],uuid[13],uuid[15],uuid[16],uuid[17],uuid[18]);
-       FPRINTF(eth_code,"    { 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c}\n",uuid[20],uuid[21],uuid[22],uuid[23],uuid[25],uuid[26],uuid[27],uuid[28],uuid[29],uuid[30],uuid[31],uuid[32],uuid[33],uuid[34],uuid[35],uuid[36]);
+       FPRINTF(eth_code,"        0x%c%c%c%c%c%c%c%c, 0x%c%c%c%c, 0x%c%c%c%c,\n",uuid[1],uuid[2],uuid[3],uuid[4],uuid[5],uuid[6],uuid[7],uuid[8],uuid[10],uuid[11],uuid[12],uuid[13],uuid[15],uuid[16],uuid[17],uuid[18]);
+       FPRINTF(eth_code,"        { 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c, 0x%c%c}\n",uuid[20],uuid[21],uuid[22],uuid[23],uuid[25],uuid[26],uuid[27],uuid[28],uuid[29],uuid[30],uuid[31],uuid[32],uuid[33],uuid[34],uuid[35],uuid[36]);
        FPRINTF(eth_code,"};\n");
        FPRINTF(eth_code,"\n");
 
@@ -854,20 +891,20 @@ void parseheader(void)
        FPRINTF(eth_code,"static guint16 ver_%s = %d;\n", ifname, major);
        FPRINTF(eth_code,"\n");
 
-       FPRINTF(eth_handoff, "    dcerpc_init_uuid(proto_%s, ett_%s,\n", ifname, ifname);
-       FPRINTF(eth_handoff, "        &uuid_dcerpc_%s, ver_%s,\n", ifname, ifname);
-       FPRINTF(eth_handoff, "        function_dissectors, hf_%s_opnum);\n", ifname);
+       FPRINTF(eth_handoff, "    dcerpc_init_uuid(proto_%s, ett_%s,\n", ifname, ifname);
+       FPRINTF(eth_handoff, "            &uuid_dcerpc_%s, ver_%s,\n", ifname, ifname);
+       FPRINTF(eth_handoff, "            function_dissectors, hf_%s_opnum);\n", ifname);
 }
 
 
 
-/* this helper function is called by the tokenizer and will just append the 
+/* this helper function is called by the tokenizer and will just append the
    current token to the linked list
 */
-void pushtoken(char *token)
+static void pushtoken(char *token)
 {
        token_item_t *new_token_item;
-       new_token_item=malloc(sizeof(token_item_t));
+       new_token_item=(token_item_t*)malloc(sizeof(token_item_t));
        new_token_item->next=NULL;
        new_token_item->str=token;
        if(!token_list){
@@ -881,17 +918,17 @@ void pushtoken(char *token)
 /* this function reads the idl file and translates it into tokens.
    the tokens are stored in a linked list  token_list of type token_item_t
 */
-void tokenize(void)
+static void tokenize(FILE *fh)
 {
        int ch;
        int fullinecomment=0;
        int normalcomment=0;
        int insidequote=0;
        char qs[1024];
-       int qspos;
+       int qspos=0;
        int insidetoken=0;
        char token[1024];
-       int tokenpos;
+       int tokenpos=0;
 
        while(!feof(fh)){
                ch=fgetc(fh);
@@ -917,7 +954,7 @@ void tokenize(void)
                                if(nextch=='*'){
                                        normalcomment=1;
                                        continue;
-                               } 
+                               }
                                ungetc(nextch, fh);
                        }
                } else {
@@ -927,7 +964,7 @@ void tokenize(void)
                                if(nextch=='/'){
                                        normalcomment=0;
                                        continue;
-                               } 
+                               }
                                ungetc(nextch, fh);
                        }
                        continue;
@@ -1024,9 +1061,9 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1036,9 +1073,9 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1048,9 +1085,9 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1061,22 +1098,24 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
-                       tmptype=register_new_type("int32", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
-                       tmptype=register_new_type("long", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
+                       if (!strcmp(name,"int32"))
+                               tmptype=register_new_type("int32", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
+                       else
+                               tmptype=register_new_type("long", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
                } else if( (!strcmp(name,"uint8")) ){
                        sprintf(dissectorname, "%s_dissect_%s", ifname, name);
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1087,22 +1126,24 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
-                       tmptype=register_new_type("int8", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
-                       tmptype=register_new_type("char", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
+                       if (!strcmp(name,"int8"))
+                               tmptype=register_new_type("int8", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
+                       else
+                               tmptype=register_new_type("char", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
                } else if(!strcmp(name,"bool8")){
                        sprintf(dissectorname, "%s_dissect_%s", ifname, name);
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1112,9 +1153,9 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, 2, hf_index, FALSE, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, di, drep, 2, hf_index, FALSE, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1124,9 +1165,9 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, 1, hf_index, FALSE, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, di, drep, 1, hf_index, FALSE, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1137,9 +1178,9 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1152,11 +1193,11 @@ find_type(char *name)
                        FPRINTF(eth_code, "static proto_item *hnd_item;\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep,\n");
-                       FPRINTF(eth_code, "                   hf_index, &policy_hnd, &hnd_item,\n");
-                       FPRINTF(eth_code, "                   param&0x01, param&0x02);\n");
+                       FPRINTF(eth_code, "    offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, di, drep,\n");
+                       FPRINTF(eth_code, "                               hf_index, &policy_hnd, &hnd_item,\n");
+                       FPRINTF(eth_code, "                               param&0x01, param&0x02);\n");
 
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
@@ -1168,57 +1209,57 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
+                       FPRINTF(eth_code, "    offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, hf_index);\n");
 
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
-                       tmptype=register_new_type("NTTIME", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
+                       tmptype=register_new_type("NTTIME", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
                } else if(!strcmp(name,"NTTIME_hyper")){
                        /* 8 bytes, aligned to 8 bytes */
                        sprintf(dissectorname, "%s_dissect_%s", ifname, name);
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    ALIGN_TO_8_BYTES;\n");
-                       FPRINTF(eth_code, "    offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
+                       FPRINTF(eth_code, "    offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, hf_index);\n");
 
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
-                       tmptype=register_new_type("NTTIME_hyper", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
+                       tmptype=register_new_type("NTTIME_hyper", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
                } else if(!strcmp(name,"NTTIME_1sec")){
                        /* 8 bytes, aligned to 8 bytes */
                        sprintf(dissectorname, "%s_dissect_%s", ifname, name);
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    ALIGN_TO_8_BYTES;\n");
-                       FPRINTF(eth_code, "    offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
+                       FPRINTF(eth_code, "    offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, hf_index);\n");
 
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
-                       tmptype=register_new_type("NTTIME_1sec", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
+                       tmptype=register_new_type("NTTIME_1sec", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
                } else if(!strcmp(name,"udlong")){
                        /* 8 bytes, aligned to 4 bytes */
                        sprintf(dissectorname, "%s_dissect_%s", ifname, name);
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
@@ -1230,10 +1271,10 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
@@ -1245,11 +1286,11 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    \n");
                        FPRINTF(eth_code, "    ALIGN_TO_8_BYTES;\n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint64(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
@@ -1260,27 +1301,25 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    \n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_time_t(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_time_t(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
-                       tmptype=register_new_type("time_t", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
+                       tmptype=register_new_type("time_t", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
                } else if(!strcmp(name,"SID")){
                        sprintf(dissectorname, "%s_dissect_%s", ifname, name);
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
-                       FPRINTF(eth_code, "    dcerpc_info *di = (dcerpc_info *)pinfo->private_data;\n");
-                       FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    di->hf_index=hf_index;\n");
 
-                       FPRINTF(eth_code, "    offset=dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, di, drep, param);\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -1290,10 +1329,10 @@ find_type(char *name)
                        FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    \n");
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
@@ -1307,7 +1346,7 @@ find_type(char *name)
 
 
 /* this function will skip past an entire declare ... ; statement */
-void skipdeclare(void)
+static void skipdeclare(void)
 {
        token_item_t *ti;
 
@@ -1326,16 +1365,15 @@ void skipdeclare(void)
 }
 
 /* this function will parse a
-       const
+          const
    and generate the appropriate code
    const must be followed by a suitable keyword [uint16|uint32|...]
    the const will later be removed from the token list
    the function assumes that the const is the first object in the token_list
 */
-void parseconst(void)
+static void parseconst(void)
 {
        token_item_t *ti;
-       type_item_t *type_item;
        char *name, *value;
 
        /* first must be the keyword const */
@@ -1346,7 +1384,7 @@ void parseconst(void)
        }
        ti=ti->next;
 
-       /* just skip second token */            
+       /* just skip second token */
        ti=ti->next;
 
        /* third is a variable and not a type */
@@ -1356,7 +1394,7 @@ void parseconst(void)
        }
        name=ti->str;
        ti=ti->next;
-       
+
        /* fourth is '=' */
        if(strcmp(ti->str, "=")){
                fprintf(stderr, "ERROR: const  fourth token is not '='\n");
@@ -1385,15 +1423,15 @@ void parseconst(void)
 }
 
 /* this function will parse a
-       typedef struct {
+          typedef struct {
    construct and generate the appropriate code.
    the typedef will be removed from the token_list once it has been processed
    the function assumes that the typedef is the first object in the token_list
    the function will be called twice, once with pass=0 and once with pass=1
-   which controls whether subdissectors are to be generated or whether the 
-   struct dissector itself is to be generated 
+   which controls whether subdissectors are to be generated or whether the
+   struct dissector itself is to be generated
 */
-void parsetypedefstruct(int pass)
+static void parsetypedefstruct(int pass)
 {
        token_item_t *ti, *tmpti;
        char *struct_name;
@@ -1405,7 +1443,7 @@ void parsetypedefstruct(int pass)
        char hf_index[256];
        bracket_item_t *bi=NULL;
        pointer_item_t *pi;
-       char *pointer_type;
+       const char *pointer_type;
        char *field_name;
        int fixed_array_size;
        int is_array_of_pointers;
@@ -1454,6 +1492,11 @@ void parsetypedefstruct(int pass)
                        continue;
                }
        }
+       if(!tmpti || !tmpti->next){
+               fprintf(stderr, "ERROR: typedefstruct  missing matching '}'\n");
+               Exit(10);
+       }
+
        struct_name=tmpti->next->str;
        sprintf(dissectorname, "%s_dissect_%s", ifname, struct_name);
 
@@ -1475,11 +1518,11 @@ void parsetypedefstruct(int pass)
        /* pass 1  generate header for the struct dissector */
        if(pass==1){
                FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, struct_name);
-               FPRINTF(eth_ettarr, "        &ett_%s_%s,\n", ifname, struct_name);
-               FPRINTF(eth_hdr, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);\n", dissectorname);
+               FPRINTF(eth_ettarr, "            &ett_%s_%s,\n", ifname, struct_name);
+               FPRINTF(eth_hdr, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param);\n", dissectorname);
                FPRINTF(eth_code, "\n");
                FPRINTF(eth_code, "int\n");
-               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                FPRINTF(eth_code, "{\n");
                FPRINTF(eth_code, "    proto_item *item=NULL;\n");
                FPRINTF(eth_code, "    proto_tree *tree=NULL;\n");
@@ -1506,8 +1549,8 @@ void parsetypedefstruct(int pass)
                }
                FPRINTF(eth_code, "    old_offset=offset;\n");
                FPRINTF(eth_code, "    if(parent_tree){\n");
-               FPRINTF(eth_code, "        item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);\n");
-               FPRINTF(eth_code, "        tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, struct_name);
+               FPRINTF(eth_code, "        item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);\n");
+               FPRINTF(eth_code, "        tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, struct_name);
                FPRINTF(eth_code, "    }\n");
                FPRINTF(eth_code, "\n");
        }
@@ -1540,7 +1583,7 @@ void parsetypedefstruct(int pass)
                                Exit(10);
                        }
                }
-               
+
                /* handle the type, verify that we KNOW this type */
                type_item=find_type(ti->str);
                if(!type_item){
@@ -1608,7 +1651,7 @@ void parsetypedefstruct(int pass)
                /* pass 0  generate subdissectors */
                if(pass==0){
                        char filter_name[256];
-                       char *hf;
+                       const char *hf;
 
                        sprintf(tmpstr, "%s_dissect_%s_%s", ifname, struct_name, field_name);
                        ptmpstr=strdup(tmpstr);
@@ -1617,11 +1660,11 @@ void parsetypedefstruct(int pass)
                          sprintf(filter_name, "%s.%s.%s", ifname, struct_name, field_name);
                          hf=register_hf_field(hf_index, field_name, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
                          FPRINTF(eth_code, "static int\n");
-                         FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
+                         FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", ptmpstr);
                          FPRINTF(eth_code, "{\n");
-                         FPRINTF(eth_code, "    guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
-                         FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
-                         FPRINTF(eth_code, "    return offset;\n");
+                         FPRINTF(eth_code, "    guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
+                         FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, di, drep, %s, param);\n", type_item->dissector, hf);
+                         FPRINTF(eth_code, "    return offset;\n");
                          FPRINTF(eth_code, "}\n");
                          FPRINTF(eth_code, "\n");
                        } else {
@@ -1634,29 +1677,29 @@ void parsetypedefstruct(int pass)
                                sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
                                if(check_if_to_emit(tmpstr)){
                                  FPRINTF(eth_code, "static int\n");
-                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
+                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
                                  FPRINTF(eth_code, "{\n");
-                                 FPRINTF(eth_code, "    offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, drep, %s, %s, \"%s\", -1);\n", ptmpstr, ptr_to_define(pointer_type), field_name);
-                                 FPRINTF(eth_code, "    return offset;\n");
+                                 FPRINTF(eth_code, "    offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, di, drep, %s, %s, \"%s\", -1);\n", ptmpstr, ptr_to_define(pointer_type), field_name);
+                                 FPRINTF(eth_code, "    return offset;\n");
                                  FPRINTF(eth_code, "}\n");
                                  FPRINTF(eth_code, "\n");
                                } else {
                                  FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
                                }
-                               
+
                                ptmpstr=strdup(tmpstr);
                        } else if(fixed_array_size){
                                sprintf(tmpstr, "fixedarray_%s", ptmpstr);
                                if(check_if_to_emit(tmpstr)){
                                  FPRINTF(eth_code, "static int\n");
-                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
+                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
                                  FPRINTF(eth_code, "{\n");
-                                 FPRINTF(eth_code, "    int count=%d;\n",fixed_array_size);
-                                 FPRINTF(eth_code, "    while(count--){\n");
-                                 FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
-                                 FPRINTF(eth_code, "    }\n");
+                                 FPRINTF(eth_code, "    int count=%d;\n",fixed_array_size);
+                                 FPRINTF(eth_code, "    while(count--){\n");
+                                 FPRINTF(eth_code, "            offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr);
+                                 FPRINTF(eth_code, "    }\n");
                                  FPRINTF(eth_code, "\n");
-                                 FPRINTF(eth_code, "    return offset;\n");
+                                 FPRINTF(eth_code, "    return offset;\n");
                                  FPRINTF(eth_code, "}\n");
                                  FPRINTF(eth_code, "\n");
                                } else {
@@ -1669,55 +1712,55 @@ void parsetypedefstruct(int pass)
                        if(bi){
                          switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
                          case 0:
-                           break;
+                               break;
                          case BI_SIZE_IS:
-                           sprintf(tmpstr, "ucarray_%s", ptmpstr);
-                           if(check_if_to_emit(tmpstr)){
-                             FPRINTF(eth_code, "static int\n");
-                             FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
-                             FPRINTF(eth_code, "{\n");
-                             FPRINTF(eth_code, "    offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
-                             FPRINTF(eth_code, "    return offset;\n");
-                             FPRINTF(eth_code, "}\n");
-                             FPRINTF(eth_code, "\n");
-                           } else {
-                             FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
-                           }
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucarray_%s", ptmpstr);
+                               if(check_if_to_emit(tmpstr)){
+                                 FPRINTF(eth_code, "static int\n");
+                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
+                                 FPRINTF(eth_code, "{\n");
+                                 FPRINTF(eth_code, "    offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr);
+                                 FPRINTF(eth_code, "    return offset;\n");
+                                 FPRINTF(eth_code, "}\n");
+                                 FPRINTF(eth_code, "\n");
+                               } else {
+                                 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
+                               }
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          case BI_LENGTH_IS:
-                           sprintf(tmpstr, "uvarray_%s", ptmpstr);
-                           if(check_if_to_emit(tmpstr)){
-                             FPRINTF(eth_code, "static int\n");
-                             FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
-                             FPRINTF(eth_code, "{\n");
-                             FPRINTF(eth_code, "    offset=dissect_ndr_uvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
-                             FPRINTF(eth_code, "    return offset;\n");
-                             FPRINTF(eth_code, "}\n");
-                             FPRINTF(eth_code, "\n");
-                           } else {
-                             FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
-                           }
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "uvarray_%s", ptmpstr);
+                               if(check_if_to_emit(tmpstr)){
+                                 FPRINTF(eth_code, "static int\n");
+                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
+                                 FPRINTF(eth_code, "{\n");
+                                 FPRINTF(eth_code, "    offset=dissect_ndr_uvarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr);
+                                 FPRINTF(eth_code, "    return offset;\n");
+                                 FPRINTF(eth_code, "}\n");
+                                 FPRINTF(eth_code, "\n");
+                               } else {
+                                 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
+                               }
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          case BI_SIZE_IS|BI_LENGTH_IS:
-                           sprintf(tmpstr, "ucvarray_%s", ptmpstr);
-                           if(check_if_to_emit(tmpstr)){
-                             FPRINTF(eth_code, "static int\n");
-                             FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
-                             FPRINTF(eth_code, "{\n");
-                             FPRINTF(eth_code, "    offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
-                             FPRINTF(eth_code, "    return offset;\n");
-                             FPRINTF(eth_code, "}\n");
-                             FPRINTF(eth_code, "\n");
-                           } else {
-                             FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
-                           }
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucvarray_%s", ptmpstr);
+                               if(check_if_to_emit(tmpstr)){
+                                 FPRINTF(eth_code, "static int\n");
+                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
+                                 FPRINTF(eth_code, "{\n");
+                                 FPRINTF(eth_code, "    offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr);
+                                 FPRINTF(eth_code, "    return offset;\n");
+                                 FPRINTF(eth_code, "}\n");
+                                 FPRINTF(eth_code, "\n");
+                               } else {
+                                 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
+                               }
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          default:
-                           fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
-                           Exit(10);
+                               fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
+                               Exit(10);
                          }
                        }
 
@@ -1728,16 +1771,16 @@ void parsetypedefstruct(int pass)
                                sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
                                if(check_if_to_emit(tmpstr)){
                                  FPRINTF(eth_code, "static int\n");
-                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
+                                 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
                                  FPRINTF(eth_code, "{\n");
-                                 FPRINTF(eth_code, "    offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, drep, %s, %s, \"%s\", -1);\n", ptmpstr, ptr_to_define(pointer_type), field_name);
-                                 FPRINTF(eth_code, "    return offset;\n");
+                                 FPRINTF(eth_code, "    offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, di, drep, %s, %s, \"%s\", -1);\n", ptmpstr, ptr_to_define(pointer_type), field_name);
+                                 FPRINTF(eth_code, "    return offset;\n");
                                  FPRINTF(eth_code, "}\n");
                                  FPRINTF(eth_code, "\n");
                                } else {
                                  FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
                                }
-                               
+
                                ptmpstr=strdup(tmpstr);
                        }
                }
@@ -1761,22 +1804,22 @@ void parsetypedefstruct(int pass)
                        if(bi){
                          switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
                          case 0:
-                           break;
+                               break;
                          case BI_SIZE_IS:
-                           sprintf(tmpstr, "ucarray_%s", ptmpstr);
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucarray_%s", ptmpstr);
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          case BI_LENGTH_IS:
-                           sprintf(tmpstr, "uvarray_%s", ptmpstr);
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "uvarray_%s", ptmpstr);
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          case BI_SIZE_IS|BI_LENGTH_IS:
-                           sprintf(tmpstr, "ucvarray_%s", ptmpstr);
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucvarray_%s", ptmpstr);
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          default:
-                           fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
-                           Exit(10);
+                               fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
+                               Exit(10);
                          }
                        }
 
@@ -1787,8 +1830,8 @@ void parsetypedefstruct(int pass)
                                sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
                                ptmpstr=strdup(tmpstr);
                        }
-                               
-                       FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
+
+                       FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr);
                        FPRINTF(eth_code, "\n");
                }
 
@@ -1811,12 +1854,12 @@ void parsetypedefstruct(int pass)
 
 typedef_struct_finished:
        FPRINTF(NULL,"\nEND STRUCT:%s pass:%d\n-------\n",struct_name,pass);
-       
+
        /* only advance token_list for pass==1
           ti now points to the '}' token
        */
        if(pass==1){
-               if(strcmp(ti->str,"}")){
+               if(!ti || strcmp(ti->str,"}")){
                        fprintf(stderr, "ERROR: struct does not end with '}'\n");
                        Exit(10);
                }
@@ -1825,40 +1868,37 @@ typedef_struct_finished:
                /* just skip the name */
                ti=ti->next;
 
-               if(strcmp(ti->str,";")){
+               if(!ti || strcmp(ti->str,";")){
                        fprintf(stderr, "ERROR: struct does not end with ';'\n");
                        Exit(10);
                }
                ti=ti->next;
-               
+
                token_list=ti;
        }
 }
 
 /* this function will parse a
-       typedef bitmap {
+          typedef bitmap {
    construct and generate the appropriate code.
    the typedef will be removed from the token_list once it has been processed
    the function assumes that the typedef is the first object in the token_list
    the function will be called twice, once with pass=0 and once with pass=1
-   which controls whether subdissectors are to be generated or whether the 
-   bitmap dissector itself is to be generated 
+   which controls whether subdissectors are to be generated or whether the
+   bitmap dissector itself is to be generated
 
    bitmaps are by default 32 bits
 */
-void parsetypedefbitmap(int pass)
+static void parsetypedefbitmap(int pass)
 {
        token_item_t *ti, *tmpti;
        char *bitmap_name;
        char dissectorname[256], hf_bitname[256];
-       int alignment, val;
+       int alignment;
+       unsigned int val;
        char *name, *value;
        bracket_item_t *bi=NULL;
 
-       char tmpstr[256], *ptmpstr;
-       type_item_t *type_item;
-       char hf_index[256];
-
        ti=token_list;
        if(strcmp(ti->str, "typedef")){
                fprintf(stderr, "ERROR: typedefbitmap  first token is not 'typedef'\n");
@@ -1867,7 +1907,7 @@ void parsetypedefbitmap(int pass)
        ti=ti->next;
 
        alignment=4;  /* default size is 32 bits */
-       
+
        if(!strcmp(ti->str, "[")){
                ti=parsebrackets(ti, &bi);
        }
@@ -1884,7 +1924,7 @@ void parsetypedefbitmap(int pass)
                        alignment=1;
                }
        }
-               
+
 
        if(strcmp(ti->str, "bitmap")){
                fprintf(stderr, "ERROR: typedefbitmap  second token is not 'bitmap'\n");
@@ -1908,6 +1948,10 @@ void parsetypedefbitmap(int pass)
                        break;
                }
        }
+       if (!tmpti || !tmpti->next){
+               fprintf(stderr, "ERROR: typedefbitmap missing matching '}'\n");
+               Exit(10);
+       }
        bitmap_name=tmpti->next->str;
        sprintf(dissectorname, "%s_dissect_%s", ifname, bitmap_name);
 
@@ -1916,11 +1960,11 @@ void parsetypedefbitmap(int pass)
        /* pass 1  generate header for the struct dissector */
        if(pass==1){
                FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, bitmap_name);
-               FPRINTF(eth_ettarr, "        &ett_%s_%s,\n", ifname, bitmap_name);
-               FPRINTF(eth_hdr, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);\n", dissectorname);
+               FPRINTF(eth_ettarr, "            &ett_%s_%s,\n", ifname, bitmap_name);
+               FPRINTF(eth_hdr, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param);\n", dissectorname);
                FPRINTF(eth_code, "\n");
                FPRINTF(eth_code, "int\n");
-               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                FPRINTF(eth_code, "{\n");
                FPRINTF(eth_code, "    proto_item *item=NULL;\n");
                FPRINTF(eth_code, "    proto_tree *tree=NULL;\n");
@@ -1940,17 +1984,17 @@ void parsetypedefbitmap(int pass)
                }
                FPRINTF(eth_code, "\n");
                FPRINTF(eth_code, "    if(parent_tree){\n");
-               FPRINTF(eth_code, "        item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, %d, TRUE);\n", alignment);
-               FPRINTF(eth_code, "        tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, bitmap_name);
+               FPRINTF(eth_code, "        item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, %d, ENC_LITTLE_ENDIAN);\n", alignment);
+               FPRINTF(eth_code, "        tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, bitmap_name);
                FPRINTF(eth_code, "    }\n");
                FPRINTF(eth_code, "\n");
                switch(alignment){
                case 1:
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, NULL, drep, -1, &flags);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint8(tvb, offset, pinfo, NULL, di, drep, -1, &flags);\n");
                        FPRINTF(eth_code, "\n");
                        break;
                case 4:
-                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &flags);\n");
+                       FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, NULL, di, drep, -1, &flags);\n");
                        FPRINTF(eth_code, "\n");
                        break;
                default:
@@ -1982,6 +2026,7 @@ void parsetypedefbitmap(int pass)
 
                value=ti->str;
                ti=ti->next;
+               val=0;
                if(!strncmp(value, "0x", 2)){
                        sscanf(value, "0x%x", &val);
                } else {
@@ -1996,11 +2041,11 @@ void parsetypedefbitmap(int pass)
 
                if(pass==0){
                        char filter_name[256], base_name[256], tfs_name[256];
-                       char *hf;
+
                        sprintf(filter_name, "%s.%s.%s", ifname, bitmap_name, name);
                        sprintf(base_name, "%d", alignment*8);
                        sprintf(tfs_name, "TFS(&%s_tfs)", name);
-                       hf=register_hf_field(hf_bitname, name, filter_name, "FT_BOOLEAN", base_name, tfs_name, value, "");
+                       register_hf_field(hf_bitname, name, filter_name, "FT_BOOLEAN", base_name, tfs_name, value, "");
 
                        FPRINTF(eth_code, "static const true_false_string %s_tfs = {\n",name);
                        FPRINTF(eth_code, "    \"%s is SET\",\n", name);
@@ -2012,7 +2057,7 @@ void parsetypedefbitmap(int pass)
                if(pass==1){
                        FPRINTF(eth_code, "    proto_tree_add_boolean(tree, %s, tvb, offset-%d, %d, flags);\n", hf_bitname, alignment, alignment);
                        FPRINTF(eth_code, "    if(flags&%s){\n", value);
-                       FPRINTF(eth_code, "        proto_item_append_text(item, \" %s\");\n", name);
+                       FPRINTF(eth_code, "        proto_item_append_text(item, \" %s\");\n", name);
                        FPRINTF(eth_code, "    }\n");
                        FPRINTF(eth_code, "    flags&=(~%s);\n", value);
                        FPRINTF(eth_code, "\n");
@@ -2026,7 +2071,7 @@ void parsetypedefbitmap(int pass)
 
        if(pass==1){
                FPRINTF(eth_code, "    if(flags){\n");
-               FPRINTF(eth_code, "        proto_item_append_text(item, \"UNKNOWN-FLAGS\");\n");
+               FPRINTF(eth_code, "        proto_item_append_text(item, \"UNKNOWN-FLAGS\");\n");
                FPRINTF(eth_code, "    }\n");
                FPRINTF(eth_code, "\n");
                FPRINTF(eth_code, "    return offset;\n");
@@ -2045,12 +2090,12 @@ void parsetypedefbitmap(int pass)
        }
 
        FPRINTF(NULL,"\nEND BITMAP:%s pass:%d\n-------\n",bitmap_name,pass);
-       
+
        /* only advance token_list for pass==1
           ti now points to the '}' token
        */
        if(pass==1){
-               if(strcmp(ti->str,"}")){
+               if(!ti || strcmp(ti->str,"}")){
                        fprintf(stderr, "ERROR: bitmap does not end with '}'\n");
                        Exit(10);
                }
@@ -2059,12 +2104,12 @@ void parsetypedefbitmap(int pass)
                /* just skip the name */
                ti=ti->next;
 
-               if(strcmp(ti->str,";")){
+               if(!ti || strcmp(ti->str,";")){
                        fprintf(stderr, "ERROR: bitmap does not end with ';'\n");
                        Exit(10);
                }
                ti=ti->next;
-               
+
                token_list=ti;
        }
 }
@@ -2072,12 +2117,12 @@ void parsetypedefbitmap(int pass)
 /* a case tag might be a negative number, i.e. contain a '-' sign which
    is not valid inside a symbol name in c.
 */
-char *
-case2str(char *str)
+static const char *
+case2str(const char *str)
 {
   char *newstr;
   if(str[0]!='-'){
-    return str;
+       return str;
   }
   newstr=strdup(str);
   newstr[0]='m';
@@ -2085,15 +2130,15 @@ case2str(char *str)
 }
 
 /* this function will parse a
-       typedef union {
+          typedef union {
    construct and generate the appropriate code.
    the typedef will be removed from the token_list once it has been processed
    the function assumes that the typedef is the first object in the token_list
    the function will be called twice, once with pass=0 and once with pass=1
-   which controls whether subdissectors are to be generated or whether the 
-   union dissector itself is to be generated 
+   which controls whether subdissectors are to be generated or whether the
+   union dissector itself is to be generated
 */
-void parsetypedefunion(int pass)
+static void parsetypedefunion(int pass)
 {
        char *union_name;
        token_item_t *ti, *tmpti;
@@ -2150,6 +2195,11 @@ void parsetypedefunion(int pass)
                        continue;
                }
        }
+
+       if (!tmpti || !tmpti->next){
+               fprintf(stderr, "ERROR: typedefunion  missing matching '}'\n");
+               Exit(10);
+       }
        union_name=tmpti->next->str;
        sprintf(dissectorname, "%s_dissect_union_%s", ifname, union_name);
 
@@ -2162,8 +2212,8 @@ void parsetypedefunion(int pass)
        }
 
        /* this is pass 0  so reset alignment to the minimum possible value
-          and update as items are processed. 
-          we need alignment when pass 1 is run 
+          and update as items are processed.
+          we need alignment when pass 1 is run
        */
        if(pass==0){
                alignment=tag_alignment;
@@ -2172,10 +2222,10 @@ void parsetypedefunion(int pass)
        /* pass 1  generate header for the struct dissector */
        if(pass==1){
                FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, union_name);
-               FPRINTF(eth_ettarr, "        &ett_%s_%s,\n", ifname, union_name);
+               FPRINTF(eth_ettarr, "            &ett_%s_%s,\n", ifname, union_name);
                FPRINTF(eth_code, "\n");
                FPRINTF(eth_code, "static int\n");
-               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
                FPRINTF(eth_code, "{\n");
                FPRINTF(eth_code, "    proto_item *item=NULL;\n");
                FPRINTF(eth_code, "    proto_tree *tree=NULL;\n");
@@ -2195,7 +2245,7 @@ void parsetypedefunion(int pass)
                        FPRINTF(eth_code, "\n");
                        break;
                case 4:
-                       FPRINTF(eth_code, "    guint32 level;\n");
+                       FPRINTF(eth_code, "    guint32 level = 0;\n");
                        FPRINTF(eth_code, "\n");
                        FPRINTF(eth_code, "    ALIGN_TO_4_BYTES;\n");
                        FPRINTF(eth_code, "\n");
@@ -2206,8 +2256,8 @@ void parsetypedefunion(int pass)
                }
                FPRINTF(eth_code, "    old_offset=offset;\n");
                FPRINTF(eth_code, "    if(parent_tree){\n");
-               FPRINTF(eth_code, "        item=proto_tree_add_text(parent_tree, tvb, offset, -1, \"%s\");\n", union_name);
-               FPRINTF(eth_code, "        tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, union_name);
+               FPRINTF(eth_code, "        item=proto_tree_add_text(parent_tree, tvb, offset, -1, \"%s\");\n", union_name);
+               FPRINTF(eth_code, "        tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, union_name);
                FPRINTF(eth_code, "    }\n");
                FPRINTF(eth_code, "\n");
                switch(tag_alignment){
@@ -2215,11 +2265,11 @@ void parsetypedefunion(int pass)
                        break;
                case 2:
                        FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree,\n");
-                       FPRINTF(eth_code, "                              drep, hf_index, &level);\n");
+                       FPRINTF(eth_code, "                                                      di, drep, hf_index, &level);\n");
                break;
                case 4:
                        FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree,\n");
-                       FPRINTF(eth_code, "                              drep, hf_index, &level);\n");
+                       FPRINTF(eth_code, "                                                      di, drep, hf_index, &level);\n");
                        break;
                default:
                        fprintf(stderr, "ERROR: typedefunion 2 can not handle alignment:%d\n",alignment);
@@ -2310,18 +2360,19 @@ void parsetypedefunion(int pass)
                /* pass 0  generate subdissectors */
                if(pass==0){
                        char filter_name[256];
-                       char *hf;
+                       const char *hf;
+
                        sprintf(tmpstr, "%s_dissect_union_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
                        ptmpstr=strdup(tmpstr);
 
                        sprintf(filter_name, "%s.%s.%s", ifname, union_name, ti->str);
                        hf=register_hf_field(hf_index, ti->str, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
-               
+
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", ptmpstr);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
-                       FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
+                       FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, di, drep, %s, param);\n", type_item->dissector, hf);
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -2330,15 +2381,15 @@ void parsetypedefunion(int pass)
                        while(num_pointers--){
                                sprintf(tmpstr, "%s_%s", ptmpstr, "unique");
                                FPRINTF(eth_code, "static int\n");
-                               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
+                               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
                                FPRINTF(eth_code, "{\n");
-                               FPRINTF(eth_code, "    offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, drep, %s, NDR_POINTER_UNIQUE, \"%s\", -1);\n", ptmpstr, ti->str);
+                               FPRINTF(eth_code, "    offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, di, drep, %s, NDR_POINTER_UNIQUE, \"%s\", -1);\n", ptmpstr, ti->str);
                                FPRINTF(eth_code, "    return offset;\n");
                                FPRINTF(eth_code, "}\n");
                                FPRINTF(eth_code, "\n");
-                               
+
                                ptmpstr=strdup(tmpstr);
-                               
+
                        }
                }
 
@@ -2350,7 +2401,7 @@ void parsetypedefunion(int pass)
                                sprintf(tmpstr, "%s_%s", ptmpstr, "unique");
                                ptmpstr=strdup(tmpstr);
                        }
-                       
+
                        if(bi->flags&BI_CASE_DEFAULT){
                                FPRINTF(eth_code, "    default:\n");
                        } else {
@@ -2361,20 +2412,20 @@ void parsetypedefunion(int pass)
                        case 1:
                                break;
                        case 2:
-                               FPRINTF(eth_code, "        ALIGN_TO_2_BYTES;\n");
+                               FPRINTF(eth_code, "        ALIGN_TO_2_BYTES;\n");
                                break;
                        case 4:
-                               FPRINTF(eth_code, "        ALIGN_TO_4_BYTES;\n");
+                               FPRINTF(eth_code, "        ALIGN_TO_4_BYTES;\n");
                                break;
                        case 8:
-                               FPRINTF(eth_code, "        ALIGN_TO_8_BYTES;\n");
+                               FPRINTF(eth_code, "        ALIGN_TO_8_BYTES;\n");
                                break;
                        default:
                                fprintf(stderr, "ERROR: typedefunion 3 can not handle alignment:%d\n",item_alignment);
                                Exit(10);
                        }
-                       FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
-                       FPRINTF(eth_code, "        break;\n");
+                       FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr);
+                       FPRINTF(eth_code, "        break;\n");
                        FPRINTF(eth_code, "\n");
                }
                ti=ti->next;
@@ -2407,12 +2458,12 @@ void parsetypedefunion(int pass)
        }
 
        FPRINTF(NULL,"\nEND UNION:%s pass:%d\n-------\n",union_name,pass);
-       
+
        /* only advance token_list for pass==1
           ti now points to the '}' token
        */
        if(pass==1){
-               if(strcmp(ti->str,"}")){
+               if(!ti || strcmp(ti->str,"}")){
                        fprintf(stderr, "ERROR: union does not end with '}'\n");
                        Exit(10);
                }
@@ -2421,35 +2472,35 @@ void parsetypedefunion(int pass)
                /* just skip the name */
                ti=ti->next;
 
-               if(strcmp(ti->str,";")){
+               if(!ti || strcmp(ti->str,";")){
                        fprintf(stderr, "ERROR: union does not end with ';'\n");
                        Exit(10);
                }
                ti=ti->next;
-               
+
                token_list=ti;
        }
 }
 
 
 /* this function will parse a
-       WERROR function (
+          WERROR function (
    construct and generate the appropriate code.
    the function will be removed from the token_list once it has been processed
    the function assumes that the function is the first object in the token_list
    the function will be called three times with
-     pass=0   generate subdissectors and entries for the function table
-     pass=1   generate code for the REQUEST
-     pass=2   generate code for the REPLY
+        pass=0   generate subdissectors and entries for the function table
+        pass=1   generate code for the REQUEST
+        pass=2   generate code for the REPLY
 */
-void parsefunction(int pass)
+static void parsefunction(int pass)
 {
        char *function_name;
        static int funcno=0;
        token_item_t *ti;
        bracket_item_t *bi=NULL;
        pointer_item_t *pi;
-       char *pointer_type;
+       const char *pointer_type;
 
        char tmpstr[256], *ptmpstr;
        int level, num_pointers;
@@ -2475,9 +2526,9 @@ void parsefunction(int pass)
        FPRINTF(NULL,"\nFUNCTION:%s pass:%d\n-------\n",function_name,pass);
 
        if(pass==0){
-               FPRINTF(eth_ft, "    { %d, \"%s\",\n",funcno,function_name);
-               FPRINTF(eth_ft, "        %s_dissect_%s_request,\n", ifname, function_name);
-               FPRINTF(eth_ft, "        %s_dissect_%s_response },\n", ifname, function_name);
+               FPRINTF(eth_ft, "        { %d, \"%s\",\n",funcno,function_name);
+               FPRINTF(eth_ft, "                %s_dissect_%s_request,\n", ifname, function_name);
+               FPRINTF(eth_ft, "                %s_dissect_%s_response },\n", ifname, function_name);
                funcno++;
        }
 
@@ -2485,7 +2536,7 @@ void parsefunction(int pass)
        if((pass==1)||(pass==2)){
                FPRINTF(eth_code, "\n");
                FPRINTF(eth_code, "static int\n");
-               FPRINTF(eth_code, "%s_dissect_%s_%s(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, guint8 *drep _U_)\n", ifname, function_name, (pass==1)?"request":"response");
+               FPRINTF(eth_code, "%s_dissect_%s_%s(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, guint8 *drep _U_)\n", ifname, function_name, (pass==1)?"request":"response");
                FPRINTF(eth_code, "{\n");
        }
 
@@ -2550,20 +2601,19 @@ void parsefunction(int pass)
                /* pass 0  generate subdissectors */
                if(pass==0){
                        char filter_name[256];
-                       char *hf;
+                       const char *hf;
 
                        sprintf(tmpstr, "%s_dissect_%s_%s", ifname, function_name, ti->str);
                        ptmpstr=strdup(tmpstr);
 
-
                        sprintf(filter_name, "%s.%s.%s", ifname, function_name, ti->str);
                        hf=register_hf_field(hf_index, ti->str, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
 
                        FPRINTF(eth_code, "static int\n");
-                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
+                       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", ptmpstr);
                        FPRINTF(eth_code, "{\n");
                        FPRINTF(eth_code, "    guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
-                       FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
+                       FPRINTF(eth_code, "    offset=%s(tvb, offset, pinfo, tree, di, drep, %s, param);\n", type_item->dissector, hf);
                        FPRINTF(eth_code, "    return offset;\n");
                        FPRINTF(eth_code, "}\n");
                        FPRINTF(eth_code, "\n");
@@ -2573,32 +2623,32 @@ void parsefunction(int pass)
                        if(bi){
                          switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
                          case 0:
-                           break;
+                               break;
                          case BI_SIZE_IS|BI_LENGTH_IS:
-                           sprintf(tmpstr, "ucvarray_%s", ptmpstr);
-                           FPRINTF(eth_code, "static int\n");
-                           FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
-                           FPRINTF(eth_code, "{\n");
-                           FPRINTF(eth_code, "    offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
-                           FPRINTF(eth_code, "    return offset;\n");
-                           FPRINTF(eth_code, "}\n");
-                           FPRINTF(eth_code, "\n");
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucvarray_%s", ptmpstr);
+                               FPRINTF(eth_code, "static int\n");
+                               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
+                               FPRINTF(eth_code, "{\n");
+                               FPRINTF(eth_code, "    offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr);
+                               FPRINTF(eth_code, "    return offset;\n");
+                               FPRINTF(eth_code, "}\n");
+                               FPRINTF(eth_code, "\n");
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          case BI_SIZE_IS:
-                           sprintf(tmpstr, "ucarray_%s", ptmpstr);
-                           FPRINTF(eth_code, "static int\n");
-                           FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
-                           FPRINTF(eth_code, "{\n");
-                           FPRINTF(eth_code, "    offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
-                           FPRINTF(eth_code, "    return offset;\n");
-                           FPRINTF(eth_code, "}\n");
-                           FPRINTF(eth_code, "\n");
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucarray_%s", ptmpstr);
+                               FPRINTF(eth_code, "static int\n");
+                               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
+                               FPRINTF(eth_code, "{\n");
+                               FPRINTF(eth_code, "    offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr);
+                               FPRINTF(eth_code, "    return offset;\n");
+                               FPRINTF(eth_code, "}\n");
+                               FPRINTF(eth_code, "\n");
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          default:
-                           fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
-                           Exit(10);
+                               fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
+                               Exit(10);
                          }
                        }
 
@@ -2608,15 +2658,15 @@ void parsefunction(int pass)
                                pi=pi->next;
                                sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
                                FPRINTF(eth_code, "static int\n");
-                               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
+                               FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep)\n", tmpstr);
                                FPRINTF(eth_code, "{\n");
-                               FPRINTF(eth_code, "    offset=dissect_ndr_toplevel_pointer(tvb, offset, pinfo, tree, drep, %s, %s, \"%s\", -1);\n", ptmpstr, ptr_to_define(pointer_type), ti->str);
+                               FPRINTF(eth_code, "    offset=dissect_ndr_toplevel_pointer(tvb, offset, pinfo, tree, di, drep, %s, %s, \"%s\", -1);\n", ptmpstr, ptr_to_define(pointer_type), ti->str);
                                FPRINTF(eth_code, "    return offset;\n");
                                FPRINTF(eth_code, "}\n");
                                FPRINTF(eth_code, "\n");
-                               
+
                                ptmpstr=strdup(tmpstr);
-                               
+
                        }
                }
 
@@ -2627,18 +2677,18 @@ void parsefunction(int pass)
                        if(bi){
                          switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
                          case 0:
-                           break;
+                               break;
                          case BI_SIZE_IS|BI_LENGTH_IS:
-                           sprintf(tmpstr, "ucvarray_%s", ptmpstr);
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucvarray_%s", ptmpstr);
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          case BI_SIZE_IS:
-                           sprintf(tmpstr, "ucarray_%s", ptmpstr);
-                           ptmpstr=strdup(tmpstr);
-                           break;
+                               sprintf(tmpstr, "ucarray_%s", ptmpstr);
+                               ptmpstr=strdup(tmpstr);
+                               break;
                          default:
-                           fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
-                           Exit(10);
+                               fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
+                               Exit(10);
                          }
                        }
 
@@ -2649,15 +2699,15 @@ void parsefunction(int pass)
                                sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
                                ptmpstr=strdup(tmpstr);
                        }
-                       
-                       if((pass==1)&&(bi->flags&BI_IN)){       
-                               FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
-                               FPRINTF(eth_code, "        offset=dissect_deferred_pointers(pinfo, tvb, offset, drep);\n");
+
+                       if((pass==1)&&(bi->flags&BI_IN)){
+                               FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
+                               FPRINTF(eth_code, "        offset=dissect_deferred_pointers(pinfo, tvb, offset, di, drep);\n");
                                FPRINTF(eth_code, "\n");
                        }
-                       if((pass==2)&&(bi->flags&BI_OUT)){      
-                               FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
-                               FPRINTF(eth_code, "        offset=dissect_deferred_pointers(pinfo, tvb, offset, drep);\n");
+                       if((pass==2)&&(bi->flags&BI_OUT)){
+                               FPRINTF(eth_code, "        offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
+                               FPRINTF(eth_code, "        offset=dissect_deferred_pointers(pinfo, tvb, offset, di, drep);\n");
                                FPRINTF(eth_code, "\n");
                        }
                }
@@ -2672,7 +2722,7 @@ void parsefunction(int pass)
 
        if((pass==1)||(pass==2)){
                if(pass==2){
-                       FPRINTF(eth_code, "   offset=dissect_ntstatus(tvb, offset, pinfo, tree, drep, %s, NULL);\n", hf_status);
+                       FPRINTF(eth_code, "   offset=dissect_ntstatus(tvb, offset, pinfo, tree, di, drep, %s, NULL);\n", hf_status);
                        FPRINTF(eth_code, "\n");
                }
                FPRINTF(eth_code, "\n");
@@ -2681,40 +2731,42 @@ void parsefunction(int pass)
        }
 
        FPRINTF(NULL,"\nEND FUNCTION:%s pass:%d\n-------\n",function_name,pass);
-       
+
        /* only advance token_list for pass==2
           ti now points to the ')' token
        */
        if(pass==2){
-               if(strcmp(ti->str,")")){
+               if(!ti || strcmp(ti->str,")")){
                        fprintf(stderr, "ERROR: function does not end with ')'\n");
                        Exit(10);
                }
                ti=ti->next;
 
-               if(strcmp(ti->str,";")){
+               if(!ti || strcmp(ti->str,";")){
                        fprintf(stderr, "ERROR: function does not end with ';'\n");
                        Exit(10);
                }
                ti=ti->next;
-               
+
                token_list=ti;
        }
 }
 
 
 /* this function will parse a
-       typedef enum {
+          typedef enum {
    or a
-       typedef [ v1_enum ] enum {
+          typedef [ v1_enum ] enum {
    construct and generate the appropriate code.
    the typedef will be removed from the token_list once it has been processed
    the function assumes that the typedef is the first object in the token_list
 */
-void parsetypedefenum(void)
+static void parsetypedefenum(void)
 {
        token_item_t *ti;
        enum_list_t *enum_list, *el, *lastel;
+       char *p;
+       long val;
        int eval, enumsize;
        char dissectorname[256], valsstring[256], hfvalsstring[256];
 
@@ -2776,7 +2828,7 @@ void parsetypedefenum(void)
                 * 3, CONST = value}
                 * 4, CONST}
                 */
-               el=malloc(sizeof(enum_list_t));
+               el=(enum_list_t*)malloc(sizeof(enum_list_t));
                el->next=NULL;
                if(!enum_list){
                        enum_list=el;
@@ -2793,7 +2845,12 @@ void parsetypedefenum(void)
                if(!strcmp(ti->str,"=")){
                        ti=ti->next;
                        /* grab value */
-                       el->val=atoi(ti->str);
+                       val=strtol(ti->str,&p,0);
+                       if (p==ti->str||*p) {
+                               fprintf(stderr, "ERROR: typedefenum value is not a number\n");
+                               Exit(10);
+                       }
+                       el->val=val;
                        ti=ti->next;
                } else {
                        el->val=eval;
@@ -2834,7 +2891,7 @@ void parsetypedefenum(void)
 
        FPRINTF(eth_hdr, "\n");
        FPRINTF(eth_hdr, "extern const value_string %s[];\n", valsstring);
-       FPRINTF(eth_hdr, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param);\n", dissectorname);
+       FPRINTF(eth_hdr, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param);\n", dissectorname);
 
        FPRINTF(eth_code, "\n");
        FPRINTF(eth_code, "const value_string %s[] = {\n", valsstring);
@@ -2847,14 +2904,14 @@ void parsetypedefenum(void)
 
        FPRINTF(eth_code, "\n");
        FPRINTF(eth_code, "int\n");
-       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
+       FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, guint8 *drep, int hf_index, guint32 param _U_)\n", dissectorname);
        FPRINTF(eth_code, "{\n");
        switch(enumsize){
        case 16:
-               FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+               FPRINTF(eth_code, "    offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                break;
        case 32:
-               FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
+               FPRINTF(eth_code, "    offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
                break;
        default:
                fprintf(stderr,"ERROR enum unknown size\n");
@@ -2889,22 +2946,23 @@ typedef struct _trimmed_prefixes_t {
        struct _trimmed_prefixes_t *next;
        char *name;
 } trimmed_prefixes_t;
-trimmed_prefixes_t *prefixes_to_trim=NULL;
+static trimmed_prefixes_t *prefixes_to_trim=NULL;
 
-void preparetrimprefix(char *prefix_name)
+static void preparetrimprefix(char *prefix_name)
 {
        trimmed_prefixes_t *new_prefix;
-       new_prefix=malloc(sizeof(trimmed_prefixes_t));
+       new_prefix=(trimmed_prefixes_t*)malloc(sizeof(trimmed_prefixes_t));
        new_prefix->next=prefixes_to_trim;
        prefixes_to_trim=new_prefix;
        new_prefix->name=strdup(prefix_name);
 }
-void
+
+static void
 trimprefix(void)
 {
        token_item_t *ti;
        trimmed_prefixes_t *pfx;
-       int len;
+       size_t len;
 
        for(pfx=prefixes_to_trim;pfx;pfx=pfx->next){
                len=strlen(pfx->name);
@@ -2916,7 +2974,7 @@ trimprefix(void)
        }
 }
 
-int Exit(int code)
+static int Exit(int code)
 {
        fprintf(stderr, "The tokens remaining when aborting:\n");
        printtokenlist(10);
@@ -2924,13 +2982,13 @@ int Exit(int code)
        exit(code);
 }
 
-void usage(void)
+static void usage(void)
 {
        fprintf(stderr, "Usage: idl2wrs <interface>\n");
 }
 
-void
-mergefile(char *name, FILE *outfile)
+static void
+mergefile(const char *name, FILE *outfile)
 {
        FILE *infile;
 
@@ -2949,7 +3007,7 @@ mergefile(char *name, FILE *outfile)
 
 
 
-char *
+static char *
 str_read_string(char *str, char **name)
 {
        char tmpstr[256], *strptr;
@@ -2992,11 +3050,11 @@ str_read_string(char *str, char **name)
                        return ++str;
                }
                *strptr++ = *str++;
-       }                       
+       }
        return NULL;
 }
 
-void
+static void
 readcnffile(FILE *fh)
 {
        char cnfline[1024];
@@ -3004,19 +3062,18 @@ readcnffile(FILE *fh)
        FPRINTF(NULL, "Reading conformance file\n=======================\n");
        while(!feof(fh)){
                cnfline[0]=0;
-               fgets(cnfline, 1023, fh);
-               if(!cnfline[0]){
-                       continue;
-               }
+                if(!fgets(cnfline, 1023, fh) || !cnfline[0]){
+                        continue;
+                }
                if(cnfline[0]=='#'){
-                       /* ignore all comments */                       
+                       /* ignore all comments */
                } else if(!strncmp(cnfline, "NOEMIT", 6)){
                        no_emit_item_t *nei;
                        char *str, *name;
 
                        str=cnfline+6;
                        str=str_read_string(str, &name);
-                       nei=malloc(sizeof(no_emit_item_t));
+                       nei=(no_emit_item_t*)malloc(sizeof(no_emit_item_t));
                        nei->next=no_emit_list;
                        no_emit_list=nei;
                        nei->name=name;
@@ -3085,7 +3142,7 @@ readcnffile(FILE *fh)
                        str=str_read_string(str, &union_tag);
                        union_tag_size=atoi(union_tag);
                        FPRINTF(NULL, "UNION_TAG_SIZE: %s == %d\n", union_name, union_tag_size);
-                       utsi=malloc(sizeof(union_tag_size_item_t));
+                       utsi=(union_tag_size_item_t*)malloc(sizeof(union_tag_size_item_t));
                        utsi->next=union_tag_size_list;
                        union_tag_size_list=utsi;
                        utsi->name=strdup(union_name);
@@ -3108,10 +3165,10 @@ readcnffile(FILE *fh)
 int main(int argc, char *argv[])
 {
        char idlfile[256];
-       char cnffile[256];
        char tmplfile[256];
        char prefix_str[256];
        bracket_item_t *bi;
+       FILE *fh;
 
        if(argc!=2){
                usage();
@@ -3143,7 +3200,7 @@ int main(int argc, char *argv[])
 
        lineno=0;
        linepos=0;
-       tokenize();
+       tokenize(fh);
        prune_keyword_parameters("size_is");
        prune_keyword_parameters("length_is");
        rename_tokens("NTSTATUS", "WERROR");
@@ -3166,7 +3223,7 @@ int main(int argc, char *argv[])
           the appropriate handler
        */
        while(1) {
-               /* just skip any [ ] that starts a new construct */
+               /* just skip any [ ] that starts a new construct */
                if( !strcmp(token_list->str, "[") ){
                        token_list=parsebrackets(token_list, &bi);
                        continue;
@@ -3198,7 +3255,7 @@ int main(int argc, char *argv[])
                /* typedef struct { */
                if( !strcmp(token_list->str,"typedef") ){
                        token_item_t *tmpti;
-                       
+
                        tmpti=token_list->next;
                        if( !strcmp(tmpti->str, "[") ){
                                tmpti=parsebrackets(tmpti, &bi);
@@ -3214,7 +3271,7 @@ int main(int argc, char *argv[])
                /* typedef union { */
                if( !strcmp(token_list->str,"typedef") ){
                        token_item_t *tmpti;
-                       
+
                        tmpti=token_list->next;
                        if( !strcmp(tmpti->str, "[") ){
                                tmpti=parsebrackets(tmpti, &bi);
@@ -3230,7 +3287,7 @@ int main(int argc, char *argv[])
                /* typedef bitmap { */
                if( !strcmp(token_list->str,"typedef") ){
                        token_item_t *tmpti;
-                       
+
                        tmpti=token_list->next;
                        if( !strcmp(tmpti->str, "[") ){
                                tmpti=parsebrackets(tmpti, &bi);
@@ -3258,7 +3315,7 @@ int main(int argc, char *argv[])
                        continue;
                }
 
-               
+
                break;
        };
 
@@ -3274,7 +3331,7 @@ int main(int argc, char *argv[])
 
        /* unless the token_list now only contains a single token : '}'
           we have failed to compile the idl file properly
-        */
+               */
        if( strcmp(token_list->str, "}") || token_list->next){
                fprintf(stderr, "ERROR: we did not process all tokens. Compiler is incomplete.\n===========================================\n");
                printtokenlist(10);
@@ -3294,7 +3351,9 @@ int main(int argc, char *argv[])
        }
        while(!feof(tfh)){
                line[0]=0;
-               fgets(line, 1024, tfh);
+                if(!fgets(line, 1024, tfh) || !line[0]){
+                        continue;
+                }
                if(!strncmp(line, "ETH_CODE", 8)){
                        mergefile("ETH_CODE",fh);
                } else if(!strncmp(line, "ETH_HDR", 7)){
@@ -3318,7 +3377,6 @@ int main(int argc, char *argv[])
        fclose(fh);
        fclose(tfh);
 
-
        sprintf(line, "packet-dcerpc-%s.h", ifname);
        fh=fopen(line, "w");
        sprintf(tmplfile, "packet-dcerpc-%s-template.h", argv[1]);
@@ -3328,8 +3386,10 @@ int main(int argc, char *argv[])
                exit(10);
        }
        while(!feof(tfh)){
-               line[0]=0;
-               fgets(line, 1024, tfh);
+                line[0]=0;
+                if(!fgets(line, 1024, tfh) || !line[0]){
+                        continue;
+                }
                if(!strncmp(line, "ETH_CODE", 8)){
                        mergefile("ETH_CODE",fh);
                } else if(!strncmp(line, "ETH_HDR", 7)){
@@ -3356,6 +3416,15 @@ int main(int argc, char *argv[])
        fclose(fh);
        fclose(tfh);
 
+       remove("ETH_CODE");
+       remove("ETH_HDR");
+       remove("ETH_HFARR");
+       remove("ETH_HF");
+       remove("ETH_ETTARR");
+       remove("ETH_ETT");
+       remove("ETH_FT");
+       remove("ETH_HANDOFF");
+
        return 0;
 }