2 * IDL to Wireshark dissector compiler
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 check that every cnf defined type,hffield,rename,... has been referenced
28 at least once and if not, abort with an error
30 need to distinguish between NTTIME (absolute time) and relative time
32 prune_xxx should only act inside of '[' ']'
34 add support for bool8,16,32,64 with tfs strings
36 add the remaining array type (uvarray)
38 add code to verify that union tag length is correct
40 /* List of built in types :
41 WERROR A 32 bit integer holding a DCE/NT status code.
46 uint16 A 16 bit integer
49 uint32 A 32 bit integer
52 uint64 A 64 bit integer
54 udlong A 64 bit integer aligned on 4 byte boundary
57 time_t A 32 bit integer holding a unix style time_t
59 NTTIME_hyper A 64 bit integer representing a NTTIME
62 unistr A conformant and varying unicode string
64 ascstr A conformant and varying ascii string
69 uuid_t A 16 byte FT_GUID blob.
80 /* All field dissectors that call a normal type
81 (i.e. not a pointer, not an array)
82 has a local variable guint param declared which is passed on to the
84 The default value is 0 but the PARAM_VALUE conformance tag can be used to
86 This is only meaningful if the called type dissector actually does anything
96 static FILE *tfh, *eth_code, *eth_hdr, *eth_hf, *eth_hfarr, *eth_ett, *eth_ettarr, *eth_ft, *eth_handoff;
97 static char *uuid=NULL;
98 static char *version=NULL;
99 static char *pointer_default=NULL;
100 static char *ifname=NULL;
101 static char hf_status[256];
102 static int lineno,linepos;
103 static char line[1024];
105 static void FPRINTF(FILE *fh, const char *format, ...)
108 va_start(args, format);
110 vfprintf (stderr, format, args);
113 vfprintf (fh, format, args);
117 typedef struct _pointer_item_t {
118 struct _pointer_item_t *next;
122 #define BI_CASE 0x00000001
123 #define BI_CASE_DEFAULT 0x00000002
124 #define BI_IN 0x00000004
125 #define BI_OUT 0x00000008
126 #define BI_SIZE_IS 0x00000010
127 #define BI_LENGTH_IS 0x00000020
128 #define BI_POINTER 0x00000040
129 #define BI_BITMAP8 0x00000100
130 #define BI_BITMAP32 0x00000200
131 #define BI_SWITCH_TYPE 0x00000400
132 typedef struct _bracket_item_t {
135 pointer_item_t *pointer_list;
139 typedef struct _no_emit_item_t {
140 struct _no_emit_item_t *next;
143 static no_emit_item_t *no_emit_list=NULL;
145 typedef struct _hf_rename_item_t {
146 struct _hf_rename_item_t *next;
147 int refcount; /* number of times this rename has been referenced */
151 static hf_rename_item_t *hf_rename_list=NULL;
153 typedef struct _enum_list_t {
154 struct _enum_list_t *next;
159 typedef struct _token_item_t {
160 struct _token_item_t *next;
163 static token_item_t *token_list=NULL;
164 static token_item_t *last_token_item=NULL;
166 typedef struct _type_item_t {
167 struct _type_item_t *next;
176 static type_item_t *type_list=NULL;
178 typedef struct _union_tag_size_item_t {
179 struct _union_tag_size_item_t *next;
182 } union_tag_size_item_t;
183 static union_tag_size_item_t *union_tag_size_list=NULL;
185 typedef struct _hf_field_item_t {
186 struct _hf_field_item_t *next;
190 static hf_field_item_t *hf_field_list=NULL;
192 typedef struct _dissector_param_value_t {
193 struct _dissector_param_value_t *next;
196 } dissector_param_value_t;
197 static dissector_param_value_t *dissector_param_list=NULL;
199 static type_item_t *find_type(char *name);
200 static int Exit(int code);
203 register_dissector_param_value(char *name, char *value)
205 dissector_param_value_t *dpv;
206 dpv=malloc(sizeof(dissector_param_value_t));
207 dpv->next=dissector_param_list;
208 dissector_param_list=dpv;
209 dpv->name=strdup(name);
210 dpv->value=strdup(value);
214 find_dissector_param_value(char *name)
216 dissector_param_value_t *dpv;
217 for(dpv=dissector_param_list;dpv;dpv=dpv->next){
218 if(!strcmp(name,dpv->name)){
225 static pointer_item_t *
226 prepend_pointer_list(pointer_item_t *ptrs, int num_pointers)
232 if(num_pointers)num_pointers--;
236 while(num_pointers--){
237 pi=malloc(sizeof(pointer_item_t));
239 pi->type=pointer_default;
248 ptr_to_define(char *pointer_type)
250 if(!strcmp(pointer_type, "unique")){
251 return "NDR_POINTER_UNIQUE";
252 } else if(!strcmp(pointer_type, "ref")){
253 return "NDR_POINTER_REF";
254 } else if(!strcmp(pointer_type, "ptr")){
255 return "NDR_POINTER_PTR";
258 fprintf(stderr, "prt_to_define, weirdo pointer :%s\n", pointer_type);
263 get_union_tag_size(char *name)
265 union_tag_size_item_t *utsi;
266 for(utsi=union_tag_size_list;utsi;utsi=utsi->next){
267 if(!strcmp(name, utsi->name)){
271 fprintf(stderr, "ERROR: size of tag for union:%s is not known\n", name);
272 fprintf(stderr, " use the UNION_TAG_SIZE directive to specify it in teh conformance file\n");
277 /* this function will add an entry to the hf_rename list */
279 register_hf_rename(char *old_name, char *new_name)
281 hf_rename_item_t *new_item;
282 new_item=malloc(sizeof(hf_rename_item_t));
283 new_item->next=hf_rename_list;
284 hf_rename_list=new_item;
285 new_item->refcount=0;
286 new_item->old_name=strdup(old_name);
287 new_item->new_name=strdup(new_name);
290 /* this function checks that all hf_rename fields have actually been referenced
291 if not out conformance file is stale
294 check_hf_rename_refcount(void)
296 hf_rename_item_t *hri;
298 /* dont generate code for renamed hf fields just return the new name*/
299 for(hri=hf_rename_list;hri;hri=hri->next){
301 fprintf(stderr, "ERROR: the hf_rename field:%s was never referenced. it is likely the conformance file is stale\n", hri->old_name);
307 static hf_field_item_t *
308 find_hf_field(char *name)
310 hf_field_item_t *hfi;
312 for(hfi=hf_field_list;hfi;hfi=hfi->next){
313 if(!strcmp(hfi->name, name)){
318 fprintf(stderr, "find_hf_field: unknown hf_field:%s\n",name);
326 /* this function will create the code required for a hf field.
327 it MIGHT rename the field so a user MUST use the name returned
329 for fields that are to be renamed no code is generated
332 register_hf_field(char *hf_name, char *title, char *filter_name, char *ft_type, char *base_type, char *valsstring, char *mask, char *blurb)
334 hf_field_item_t *hfi;
335 hf_rename_item_t *hri;
337 /* dont generate code for renamed hf fields just return the new name*/
338 for(hri=hf_rename_list;hri;hri=hri->next){
339 if(!strcmp(hf_name, hri->old_name)){
340 hfi=find_hf_field(hri->new_name);
341 if(strcmp(ft_type, hfi->ft_type)){
342 fprintf(stderr, "register_hf_field: hf_fields %s and %s have different types %s %s\n",hf_name,hfi->name,ft_type,hfi->ft_type);
346 return hri->new_name;
350 hfi=malloc(sizeof(hf_field_item_t));
351 hfi->next=hf_field_list;
353 hfi->name=strdup(hf_name);
354 hfi->ft_type=strdup(ft_type);
356 FPRINTF(eth_hf, "static int %s = -1;\n", hf_name);
357 FPRINTF(eth_hfarr, " { &%s,\n", hf_name);
358 FPRINTF(eth_hfarr, " { \"%s\", \"%s\", %s, %s,\n", title, filter_name, ft_type, base_type);
359 FPRINTF(eth_hfarr, " %s, %s,\n", valsstring, mask);
360 if (strlen(blurb) > 0)
361 FPRINTF(eth_hfarr, " \"%s\", HFILL }},\n", blurb);
363 FPRINTF(eth_hfarr, " NULL, HFILL }},\n");
364 FPRINTF(eth_hfarr, "\n");
369 /* this function will parse the no emit list and decide whether code should
370 be generated for this dissector or if we should only register the type.
373 check_if_to_emit(char *name)
377 for(nel=no_emit_list;nel;nel=nel->next){
378 if(!strcmp(name, nel->name)){
379 FPRINTF(NULL, "SKIPPED emitting of %s\n",name);
388 prune_keywords(char *name)
392 for(ti=token_list;ti;ti=ti->next){
396 if(!strcmp(ti->next->str, name)){
397 if(!strcmp(ti->next->next->str, ",")){
398 ti->next=ti->next->next->next;
400 ti->next=ti->next->next;
408 rename_tokens(char *old_name, char *new_name)
412 for(ti=token_list;ti;ti=ti->next){
413 if(!strcmp(ti->str, old_name)){
414 ti->str=strdup(new_name);
420 prune_keyword_parameters(char *name)
422 token_item_t *ti, *tmpti;
424 for(ti=token_list;ti;ti=ti->next){
425 if(!strcmp(ti->str, name)){
426 if(!strcmp(ti->next->str, "(")){
429 if(!strcmp(tmpti->str, ")")){
430 ti->next=tmpti->next;
440 /* this function will parse a bracket item
442 it will return the token of the next item following the ']'
444 static token_item_t *
445 parsebrackets(token_item_t *ti, bracket_item_t **bracket){
447 type_item_t *type_item;
449 if(strcmp(ti->str, "[")){
450 fprintf(stderr, "ERROR: parsebrackets first token is not '['\n");
455 br=malloc(sizeof(bracket_item_t));
459 br->pointer_list=NULL;
462 if( !strcmp(ti->str, "{")
463 ||!strcmp(ti->str, "}")){
464 fprintf(stderr, "ERROR: parsebrackets '{' '}' inside bracket item\n");
468 if(!strcmp(ti->str, "[")){
469 fprintf(stderr, "ERROR: parsebrackets '[' inside bracket item\n");
474 if(!strcmp(ti->str, "]")){
475 /* check for [ ... ] [ ...] */
478 if(!strcmp(ti->str, "[")){
485 /* just ignore all ',' */
486 if(!strcmp(ti->str, ",")){
491 /* case '(' tag ')' */
492 if(!strcmp(ti->str, "case")){
496 if(strcmp(ti->str, "(")){
497 fprintf(stderr, "ERROR: parsebrackets case not followed by '('\n");
503 br->case_name=ti->str;
506 if(strcmp(ti->str, ")")){
507 fprintf(stderr, "ERROR: parsebrackets case does not end with ')'\n");
515 if(!strcmp(ti->str, "default")){
517 br->flags|=BI_CASE_DEFAULT;
518 br->case_name="default";
525 if(!strcmp(ti->str, "in")){
532 if(!strcmp(ti->str, "out")){
538 /* public : we dont care about this one */
539 if(!strcmp(ti->str, "public")){
544 /* gensize : we dont care about this one */
545 if(!strcmp(ti->str, "gensize")){
551 if(!strcmp(ti->str, "switch_is")){
552 fprintf(stderr, "WARNING: parsebrackets can not handle switch_is properly yet so we can not verify the tag size\n");
554 if(!strcmp(ti->str, ")")){
564 if(!strcmp(ti->str, "subcontext")){
566 if(!strcmp(ti->str, ")")){
575 /* value we dont care about this one so just skip it */
576 if(!strcmp(ti->str, "value")){
579 if( strcmp(ti->str, "(") ){
580 fprintf(stderr, "WARNING: parsebrackets value was not followed by '('\n");
585 if(!strcmp(ti->str, "(")){
590 if(!strcmp(ti->str, ")")){
603 /* range we dont care about this one so just skip it */
604 if(!strcmp(ti->str, "range")){
607 if( strcmp(ti->str, "(") ){
608 fprintf(stderr, "WARNING: parsebrackets range was not followed by '('\n");
613 if(!strcmp(ti->str, "(")){
618 if(!strcmp(ti->str, ")")){
631 /* flag we dont care about this one so just skip it */
632 if(!strcmp(ti->str, "flag")){
635 if( strcmp(ti->str, "(") ){
636 fprintf(stderr, "WARNING: parsebrackets flag was not followed by '('\n");
641 if(!strcmp(ti->str, "(")){
646 if(!strcmp(ti->str, ")")){
660 if(!strcmp(ti->str, "switch_type")){
661 br->flags|=BI_SWITCH_TYPE;
664 if(strcmp(ti->str, "(")){
665 fprintf(stderr, "WARNING: parsebrackets switch_type was not followed by '('\n");
670 type_item=find_type(ti->str);
672 fprintf(stderr, "ERROR : parsebrackets switch_type unknown type %s\n",ti->str);
675 br->union_tag_size=type_item->alignment;
678 if(strcmp(ti->str, ")")){
679 fprintf(stderr, "WARNING: parsebrackets switch_type did not end with ')'\n");
688 if(!strcmp(ti->str, "size_is")){
689 br->flags|=BI_SIZE_IS;
695 if(!strcmp(ti->str, "length_is")){
696 br->flags|=BI_LENGTH_IS;
702 if(!strcmp(ti->str, "bitmap8bit")){
703 br->flags|=BI_BITMAP8;
709 if(!strcmp(ti->str, "bitmap32bit")){
710 br->flags|=BI_BITMAP32;
715 /* ref, unique or ptr */
716 if(!strcmp(ti->str, "ref")
717 || !strcmp(ti->str, "unique")
718 || !strcmp(ti->str, "ptr")){
719 pointer_item_t *newpi;
721 br->flags|=BI_POINTER;
722 newpi=malloc(sizeof(pointer_item_t));
725 newpi->next=br->pointer_list;
726 br->pointer_list=newpi;
731 fprintf(stderr, "ERROR: parsebrackets should not be reached unknown tag:%s\n", ti->str);
738 /* this function will register a new type learnt from the IDL file
741 register_new_type(char *name, char *dissectorname, char *ft_type, char *base_type, char *mask, char *valsstring, int alignment){
742 type_item_t *new_type;
744 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);
746 new_type=malloc(sizeof(type_item_t));
747 new_type->next=type_list;
748 new_type->name=strdup(name);
749 new_type->dissector=strdup(dissectorname);
750 new_type->ft_type=strdup(ft_type);
751 new_type->base_type=strdup(base_type);
752 new_type->mask=strdup(mask);
753 new_type->vals=strdup(valsstring);
754 new_type->alignment=alignment;
761 /* this function will print the remaining content of the token list
763 static void printtokenlist(int count)
766 fprintf(stderr, "TOKENLIST:\n");
767 for(ti=token_list;ti&&count;count--,ti=ti->next){
768 fprintf(stderr, "Token \"%s\"\n",ti->str);
771 fprintf(stderr, " ...\n");
776 /* this function will parse the header and pick up the fields
777 * we are interested in.
778 * the header is supposed to start at the very first token and look like
779 * [ <fields> ] inteface <ifname> {
781 * we are interested in the fields:
786 * this function will also remove the header from the token list
788 static void parseheader(void)
790 char filter_name[256];
797 fprintf(stderr, "ERROR: no tokens\n");
801 /* first token must be '[' */
802 if( strcmp(ti->str, "[") ){
803 fprintf(stderr, "ERROR: first token is not '['\n");
807 for(ti=token_list;ti;ti=ti->next){
808 if( !strcmp(ti->str, "[")){
812 if( !strcmp(ti->str, "]")){
820 if( !strcmp(ti->str, "uuid")){
821 uuid=ti->next->next->str;
822 FPRINTF(NULL,"UUID:%s\n",uuid);
824 if( !strcmp(ti->str, "version")){
825 version=ti->next->next->str;
826 FPRINTF(NULL,"VERSION:%s\n",version);
828 if( !strcmp(ti->str, "pointer_default")){
829 if(!strcmp(ti->next->next->str, "unique")){
830 pointer_default="unique";
831 } else if(!strcmp(ti->next->next->str, "ptr")){
832 pointer_default="ptr";
834 fprintf(stderr, "ERROR: unknown pointer type\n");
837 FPRINTF(NULL,"POINTER_DEFAULT:%s\n",pointer_default);
842 fprintf(stderr, "ERROR: ran outof tokens inside header\n");
846 if(strcmp(token_list->str, "interface")){
847 fprintf(stderr, "ERROR: interface not found\n");
850 token_list=token_list->next;
852 ifname=token_list->str;
853 token_list=token_list->next;
854 FPRINTF(NULL,"Interface:%s\n",ifname);
857 sprintf(hf_status, "hf_%s_opnum", ifname);
858 sprintf(filter_name, "%s.opnum", ifname);
859 register_hf_field(hf_status, "Operation", filter_name, "FT_UINT16", "BASE_DEC", "NULL", "0", "");
862 sprintf(hf_status, "hf_%s_rc", ifname);
863 sprintf(filter_name, "%s.rc", ifname);
864 register_hf_field(hf_status, "Return code", filter_name, "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", "0", "");
866 FPRINTF(eth_ett, "static gint ett_%s = -1;\n", ifname);
867 FPRINTF(eth_ettarr, " &ett_%s,\n", ifname);
869 /* the body must start with { */
870 if(strcmp(token_list->str, "{")){
871 fprintf(stderr, "ERROR: body does not start with '{'\n");
875 /* skip the initial '{' */
876 token_list=token_list->next;
879 fprintf(stderr, "ERROR: no uuid found\n");
882 FPRINTF(eth_code,"static e_uuid_t uuid_dcerpc_%s = {\n", ifname);
883 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]);
884 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]);
885 FPRINTF(eth_code,"};\n");
886 FPRINTF(eth_code,"\n");
888 sscanf(version, "%d.%d", &major, &minor);
889 FPRINTF(eth_code,"static guint16 ver_%s = %d;\n", ifname, major);
890 FPRINTF(eth_code,"\n");
892 FPRINTF(eth_handoff, " dcerpc_init_uuid(proto_%s, ett_%s,\n", ifname, ifname);
893 FPRINTF(eth_handoff, " &uuid_dcerpc_%s, ver_%s,\n", ifname, ifname);
894 FPRINTF(eth_handoff, " function_dissectors, hf_%s_opnum);\n", ifname);
899 /* this helper function is called by the tokenizer and will just append the
900 current token to the linked list
902 static void pushtoken(char *token)
904 token_item_t *new_token_item;
905 new_token_item=malloc(sizeof(token_item_t));
906 new_token_item->next=NULL;
907 new_token_item->str=token;
909 token_list=new_token_item;
911 last_token_item->next=new_token_item;
913 last_token_item=new_token_item;
916 /* this function reads the idl file and translates it into tokens.
917 the tokens are stored in a linked list token_list of type token_item_t
919 static void tokenize(FILE *fh)
922 int fullinecomment=0;
934 /* full line comment */
936 if( (ch=='\n')||(ch=='\r') ){
942 if( (ch=='#')&&(linepos==0) ){
948 if(normalcomment==0){
977 pushtoken(strdup(qs));
980 qs[qspos++]=(char)ch;
999 pushtoken(strdup(token));
1002 /*printf("line %d [%s]\n",lineno,line);*/
1011 pushtoken(strdup(token));
1025 pushtoken(strdup(token));
1029 pushtoken(strdup(token));
1036 token[tokenpos++]=(char)ch;
1037 line[linepos++]=(char)ch;
1045 static type_item_t *
1046 find_type(char *name)
1048 type_item_t *tmptype;
1049 for(tmptype=type_list;tmptype;tmptype=tmptype->next){
1050 if(!strcmp(tmptype->name, name)){
1054 /* autogenerate built in types */
1056 char dissectorname[256];
1057 if(!strcmp(name,"uint16")){
1058 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1059 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1060 FPRINTF(eth_code, "\n");
1061 FPRINTF(eth_code, "static int\n");
1062 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);
1063 FPRINTF(eth_code, "{\n");
1064 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1065 FPRINTF(eth_code, " return offset;\n");
1066 FPRINTF(eth_code, "}\n");
1067 FPRINTF(eth_code, "\n");
1068 tmptype=register_new_type("uint16", dissectorname, "FT_UINT16", "BASE_DEC", "0", "NULL", 2);
1069 } else if(!strcmp(name,"int16")){
1070 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1071 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1072 FPRINTF(eth_code, "\n");
1073 FPRINTF(eth_code, "static int\n");
1074 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);
1075 FPRINTF(eth_code, "{\n");
1076 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1077 FPRINTF(eth_code, " return offset;\n");
1078 FPRINTF(eth_code, "}\n");
1079 FPRINTF(eth_code, "\n");
1080 tmptype=register_new_type("int16", dissectorname, "FT_INT16", "BASE_DEC", "0", "NULL", 2);
1081 } else if(!strcmp(name,"uint32")){
1082 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1083 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1084 FPRINTF(eth_code, "\n");
1085 FPRINTF(eth_code, "static int\n");
1086 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);
1087 FPRINTF(eth_code, "{\n");
1088 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1089 FPRINTF(eth_code, " return offset;\n");
1090 FPRINTF(eth_code, "}\n");
1091 FPRINTF(eth_code, "\n");
1092 tmptype=register_new_type("uint32", dissectorname, "FT_UINT32", "BASE_DEC", "0", "NULL", 4);
1093 } else if( (!strcmp(name,"int32"))
1094 || (!strcmp(name,"long")) ){
1095 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1096 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1097 FPRINTF(eth_code, "\n");
1098 FPRINTF(eth_code, "static int\n");
1099 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);
1100 FPRINTF(eth_code, "{\n");
1101 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1102 FPRINTF(eth_code, " return offset;\n");
1103 FPRINTF(eth_code, "}\n");
1104 FPRINTF(eth_code, "\n");
1105 if (!strcmp(name,"int32"))
1106 tmptype=register_new_type("int32", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
1108 tmptype=register_new_type("long", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
1109 } else if( (!strcmp(name,"uint8")) ){
1110 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1111 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1112 FPRINTF(eth_code, "\n");
1113 FPRINTF(eth_code, "static int\n");
1114 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);
1115 FPRINTF(eth_code, "{\n");
1116 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1117 FPRINTF(eth_code, " return offset;\n");
1118 FPRINTF(eth_code, "}\n");
1119 FPRINTF(eth_code, "\n");
1120 tmptype=register_new_type("uint8", dissectorname, "FT_UINT8", "BASE_DEC", "0", "NULL", 1);
1121 } else if( (!strcmp(name,"int8"))
1122 || (!strcmp(name, "char")) ){
1123 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1124 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1125 FPRINTF(eth_code, "\n");
1126 FPRINTF(eth_code, "static int\n");
1127 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);
1128 FPRINTF(eth_code, "{\n");
1129 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1130 FPRINTF(eth_code, " return offset;\n");
1131 FPRINTF(eth_code, "}\n");
1132 FPRINTF(eth_code, "\n");
1133 if (!strcmp(name,"int8"))
1134 tmptype=register_new_type("int8", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1136 tmptype=register_new_type("char", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1137 } else if(!strcmp(name,"bool8")){
1138 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1139 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1140 FPRINTF(eth_code, "\n");
1141 FPRINTF(eth_code, "static int\n");
1142 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);
1143 FPRINTF(eth_code, "{\n");
1144 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1145 FPRINTF(eth_code, " return offset;\n");
1146 FPRINTF(eth_code, "}\n");
1147 FPRINTF(eth_code, "\n");
1148 tmptype=register_new_type("bool8", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1149 } else if(!strcmp(name,"unistr")){
1150 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1151 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1152 FPRINTF(eth_code, "\n");
1153 FPRINTF(eth_code, "static int\n");
1154 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);
1155 FPRINTF(eth_code, "{\n");
1156 FPRINTF(eth_code, " offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, 2, hf_index, FALSE, NULL);\n");
1157 FPRINTF(eth_code, " return offset;\n");
1158 FPRINTF(eth_code, "}\n");
1159 FPRINTF(eth_code, "\n");
1160 tmptype=register_new_type("unistr", dissectorname, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1161 } else if(!strcmp(name,"ascstr")){
1162 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1163 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1164 FPRINTF(eth_code, "\n");
1165 FPRINTF(eth_code, "static int\n");
1166 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);
1167 FPRINTF(eth_code, "{\n");
1168 FPRINTF(eth_code, " offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, 1, hf_index, FALSE, NULL);\n");
1169 FPRINTF(eth_code, " return offset;\n");
1170 FPRINTF(eth_code, "}\n");
1171 FPRINTF(eth_code, "\n");
1172 tmptype=register_new_type("ascstr", dissectorname, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1173 } else if(!strcmp(name,"GUID")
1174 ||!strcmp(name,"uuid_t")){
1175 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1176 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1177 FPRINTF(eth_code, "\n");
1178 FPRINTF(eth_code, "static int\n");
1179 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);
1180 FPRINTF(eth_code, "{\n");
1181 FPRINTF(eth_code, " offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1182 FPRINTF(eth_code, " return offset;\n");
1183 FPRINTF(eth_code, "}\n");
1184 FPRINTF(eth_code, "\n");
1185 tmptype=register_new_type(name, dissectorname, "FT_GUID", "BASE_NONE", "0", "NULL", 4);
1186 } else if(!strcmp(name,"policy_handle")){
1187 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1188 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1189 FPRINTF(eth_code, "\n");
1190 FPRINTF(eth_code, "static e_ctx_hnd policy_hnd;\n");
1191 FPRINTF(eth_code, "static proto_item *hnd_item;\n");
1192 FPRINTF(eth_code, "\n");
1193 FPRINTF(eth_code, "static int\n");
1194 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
1195 FPRINTF(eth_code, "{\n");
1196 FPRINTF(eth_code, " offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep,\n");
1197 FPRINTF(eth_code, " hf_index, &policy_hnd, &hnd_item,\n");
1198 FPRINTF(eth_code, " param&0x01, param&0x02);\n");
1200 FPRINTF(eth_code, " return offset;\n");
1201 FPRINTF(eth_code, "}\n");
1202 FPRINTF(eth_code, "\n");
1203 tmptype=register_new_type("policy_handle", dissectorname, "FT_BYTES", "BASE_NONE", "0", "NULL", 4);
1204 } else if(!strcmp(name,"NTTIME")){
1205 /* 8 bytes, aligned to 4 bytes */
1206 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1207 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1208 FPRINTF(eth_code, "\n");
1209 FPRINTF(eth_code, "static int\n");
1210 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);
1211 FPRINTF(eth_code, "{\n");
1212 FPRINTF(eth_code, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
1214 FPRINTF(eth_code, "\n");
1215 FPRINTF(eth_code, " return offset;\n");
1216 FPRINTF(eth_code, "}\n");
1217 FPRINTF(eth_code, "\n");
1218 tmptype=register_new_type("NTTIME", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
1219 } else if(!strcmp(name,"NTTIME_hyper")){
1220 /* 8 bytes, aligned to 8 bytes */
1221 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1222 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1223 FPRINTF(eth_code, "\n");
1224 FPRINTF(eth_code, "static int\n");
1225 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);
1226 FPRINTF(eth_code, "{\n");
1227 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1228 FPRINTF(eth_code, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
1230 FPRINTF(eth_code, "\n");
1231 FPRINTF(eth_code, " return offset;\n");
1232 FPRINTF(eth_code, "}\n");
1233 FPRINTF(eth_code, "\n");
1234 tmptype=register_new_type("NTTIME_hyper", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
1235 } else if(!strcmp(name,"NTTIME_1sec")){
1236 /* 8 bytes, aligned to 8 bytes */
1237 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1238 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1239 FPRINTF(eth_code, "\n");
1240 FPRINTF(eth_code, "static int\n");
1241 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);
1242 FPRINTF(eth_code, "{\n");
1243 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1244 FPRINTF(eth_code, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
1246 FPRINTF(eth_code, "\n");
1247 FPRINTF(eth_code, " return offset;\n");
1248 FPRINTF(eth_code, "}\n");
1249 FPRINTF(eth_code, "\n");
1250 tmptype=register_new_type("NTTIME_1sec", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
1251 } else if(!strcmp(name,"udlong")){
1252 /* 8 bytes, aligned to 4 bytes */
1253 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1254 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1255 FPRINTF(eth_code, "\n");
1256 FPRINTF(eth_code, "static int\n");
1257 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);
1258 FPRINTF(eth_code, "{\n");
1259 FPRINTF(eth_code, "\n");
1260 FPRINTF(eth_code, " offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1261 FPRINTF(eth_code, "\n");
1262 FPRINTF(eth_code, " return offset;\n");
1263 FPRINTF(eth_code, "}\n");
1264 FPRINTF(eth_code, "\n");
1265 tmptype=register_new_type("udlong", dissectorname, "FT_UINT64", "BASE_DEC", "0", "NULL", 4);
1266 } else if(!strcmp(name,"dlong")){
1267 /* 8 bytes, aligned to 4 bytes */
1268 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1269 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1270 FPRINTF(eth_code, "\n");
1271 FPRINTF(eth_code, "static int\n");
1272 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);
1273 FPRINTF(eth_code, "{\n");
1274 FPRINTF(eth_code, "\n");
1275 FPRINTF(eth_code, " offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1276 FPRINTF(eth_code, "\n");
1277 FPRINTF(eth_code, " return offset;\n");
1278 FPRINTF(eth_code, "}\n");
1279 FPRINTF(eth_code, "\n");
1280 tmptype=register_new_type("dlong", dissectorname, "FT_INT64", "BASE_DEC", "0", "NULL", 4);
1281 } else if(!strcmp(name,"uint64")){
1282 /* 8 bytes, aligned to 8 bytes */
1283 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1284 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1285 FPRINTF(eth_code, "\n");
1286 FPRINTF(eth_code, "static int\n");
1287 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);
1288 FPRINTF(eth_code, "{\n");
1289 FPRINTF(eth_code, " \n");
1290 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1291 FPRINTF(eth_code, " offset=dissect_ndr_uint64(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1292 FPRINTF(eth_code, "\n");
1293 FPRINTF(eth_code, " return offset;\n");
1294 FPRINTF(eth_code, "}\n");
1295 FPRINTF(eth_code, "\n");
1296 tmptype=register_new_type("uint64", dissectorname, "FT_UINT64", "BASE_DEC", "0", "NULL", 8);
1297 } else if(!strcmp(name,"time_t")){
1298 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1299 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1300 FPRINTF(eth_code, "\n");
1301 FPRINTF(eth_code, "static int\n");
1302 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);
1303 FPRINTF(eth_code, "{\n");
1304 FPRINTF(eth_code, " \n");
1305 FPRINTF(eth_code, " offset=dissect_ndr_time_t(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1306 FPRINTF(eth_code, "\n");
1307 FPRINTF(eth_code, " return offset;\n");
1308 FPRINTF(eth_code, "}\n");
1309 FPRINTF(eth_code, "\n");
1310 tmptype=register_new_type("time_t", dissectorname, "FT_ABSOLUTE_TIME", "BASE_NONE", "0", "NULL", 4);
1311 } else if(!strcmp(name,"SID")){
1312 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1313 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1314 FPRINTF(eth_code, "\n");
1315 FPRINTF(eth_code, "static int\n");
1316 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
1317 FPRINTF(eth_code, "{\n");
1318 FPRINTF(eth_code, " dcerpc_info *di = (dcerpc_info *)pinfo->private_data;\n");
1319 FPRINTF(eth_code, "\n");
1320 FPRINTF(eth_code, " di->hf_index=hf_index;\n");
1322 FPRINTF(eth_code, " offset=dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);\n");
1323 FPRINTF(eth_code, " return offset;\n");
1324 FPRINTF(eth_code, "}\n");
1325 FPRINTF(eth_code, "\n");
1326 tmptype=register_new_type("SID", dissectorname, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1327 } else if(!strcmp(name,"WERROR")){
1328 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1329 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1330 FPRINTF(eth_code, "\n");
1331 FPRINTF(eth_code, "static int\n");
1332 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);
1333 FPRINTF(eth_code, "{\n");
1334 FPRINTF(eth_code, " \n");
1335 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1336 FPRINTF(eth_code, "\n");
1337 FPRINTF(eth_code, " return offset;\n");
1338 FPRINTF(eth_code, "}\n");
1339 FPRINTF(eth_code, "\n");
1340 tmptype=register_new_type("WERROR", dissectorname, "FT_UINT32", "BASE_DEC", "0", "VALS(NT_errors)", 4);
1348 /* this function will skip past an entire declare ... ; statement */
1349 static void skipdeclare(void)
1353 /* first must be the keyword const */
1355 if(strcmp(ti->str, "declare")){
1356 fprintf(stderr, "ERROR: skipdeclare first token is not 'declare'\n");
1359 while(strcmp(ti->str, ";")){
1367 /* this function will parse a
1369 and generate the appropriate code
1370 const must be followed by a suitable keyword [uint16|uint32|...]
1371 the const will later be removed from the token list
1372 the function assumes that the const is the first object in the token_list
1374 static void parseconst(void)
1379 /* first must be the keyword const */
1381 if(strcmp(ti->str, "const")){
1382 fprintf(stderr, "ERROR: const first token is not 'const'\n");
1387 /* just skip second token */
1390 /* third is a variable and not a type */
1391 if(find_type(ti->str)){
1392 fprintf(stderr, "ERROR: const, not a variable name:%s\n", ti->str);
1399 if(strcmp(ti->str, "=")){
1400 fprintf(stderr, "ERROR: const fourth token is not '='\n");
1405 /* fifth is the value */
1410 if(strcmp(ti->str, ";")){
1411 fprintf(stderr, "ERROR: const sixth token is not ';'\n");
1416 FPRINTF(NULL,"\nCONST:%s\n-------\n",name);
1418 FPRINTF(eth_hdr, "#define %s %s\n", name, value);
1420 FPRINTF(NULL,"\n----------\nEND CONST:%s\n",name);
1425 /* this function will parse a
1427 construct and generate the appropriate code.
1428 the typedef will be removed from the token_list once it has been processed
1429 the function assumes that the typedef is the first object in the token_list
1430 the function will be called twice, once with pass=0 and once with pass=1
1431 which controls whether subdissectors are to be generated or whether the
1432 struct dissector itself is to be generated
1434 static void parsetypedefstruct(int pass)
1436 token_item_t *ti, *tmpti;
1438 char dissectorname[256];
1439 char tmpstr[256], *ptmpstr;
1440 int level, num_pointers;
1441 static int alignment;
1442 type_item_t *type_item;
1444 bracket_item_t *bi=NULL;
1448 int fixed_array_size;
1449 int is_array_of_pointers;
1452 if(strcmp(ti->str, "typedef")){
1453 fprintf(stderr, "ERROR: typedefstruct first token is not 'typedef'\n");
1458 if(!strcmp(ti->str, "[")){
1459 ti=parsebrackets(ti, &bi);
1461 /* check that we know how to handle the bracket thing */
1464 fprintf(stderr, "ERROR: typedefstruct unknown bracket flags encountered : 0x%08x\n",bi->flags);
1469 if(strcmp(ti->str, "struct")){
1470 fprintf(stderr, "ERROR: typedefstruct second token is not 'struct'\n");
1475 if(strcmp(ti->str, "{")){
1476 fprintf(stderr, "ERROR: typedefstruct third token is not '{'\n");
1481 /* search forward until the '}' so we can find the name of the struct */
1482 for(tmpti=ti,level=0;tmpti;tmpti=tmpti->next){
1483 if(!strcmp(tmpti->str, "{")){
1487 if(!strcmp(tmpti->str, "}")){
1495 if(!tmpti || !tmpti->next){
1496 fprintf(stderr, "ERROR: typedefstruct missing matching '}'\n");
1500 struct_name=tmpti->next->str;
1501 sprintf(dissectorname, "%s_dissect_%s", ifname, struct_name);
1503 FPRINTF(NULL,"\nSTRUCT:%s pass:%d\n-------\n",struct_name,pass);
1505 if(!check_if_to_emit(dissectorname)){
1506 FPRINTF(NULL,"NOEMIT Skipping this struct dissector.\n");
1508 goto typedef_struct_finished;
1511 /* this is pass 0 so reset alignment to zero and update as items are
1512 processed. we need alignment when pass 1 is run.
1513 set alignment initially to 1 so we dont fail for empty structs
1518 /* pass 1 generate header for the struct dissector */
1520 FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, struct_name);
1521 FPRINTF(eth_ettarr, " &ett_%s_%s,\n", ifname, struct_name);
1522 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);
1523 FPRINTF(eth_code, "\n");
1524 FPRINTF(eth_code, "int\n");
1525 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);
1526 FPRINTF(eth_code, "{\n");
1527 FPRINTF(eth_code, " proto_item *item=NULL;\n");
1528 FPRINTF(eth_code, " proto_tree *tree=NULL;\n");
1529 FPRINTF(eth_code, " int old_offset;\n");
1530 FPRINTF(eth_code, "\n");
1535 FPRINTF(eth_code, " ALIGN_TO_2_BYTES;\n");
1536 FPRINTF(eth_code, "\n");
1539 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
1540 FPRINTF(eth_code, "\n");
1543 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1544 FPRINTF(eth_code, "\n");
1547 fprintf(stderr, "ERROR: can not handle alignment:%d\n",alignment);
1550 FPRINTF(eth_code, " old_offset=offset;\n");
1551 FPRINTF(eth_code, " if(parent_tree){\n");
1552 FPRINTF(eth_code, " item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, TRUE);\n");
1553 FPRINTF(eth_code, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, struct_name);
1554 FPRINTF(eth_code, " }\n");
1555 FPRINTF(eth_code, "\n");
1558 /* scan the struct and create all subdissectors */
1561 if(!strcmp(ti->str, "{")){
1566 if(!strcmp(ti->str, "}")){
1574 if(!strcmp(ti->str, "[")){
1575 ti=parsebrackets(ti, &bi);
1579 /* check that we know how to handle the bracket thing */
1581 if(bi->flags&(~(BI_SIZE_IS|BI_LENGTH_IS|BI_POINTER))){
1582 fprintf(stderr, "ERROR: typedefstruct unknown bracket flags encountered : 0x%08x\n",bi->flags);
1587 /* handle the type, verify that we KNOW this type */
1588 type_item=find_type(ti->str);
1590 fprintf(stderr, "ERROR : typedefstruct unknown type %s\n",ti->str);
1594 /* count the levels of pointers */
1595 for(num_pointers=0;!strcmp(ti->str, "*");ti=ti->next){
1597 /* poitners are aligned at 4 byte boundaries */
1602 /* now that we know how many real pointers there were we must
1603 prepend default pointers to the list so it has the right
1606 pi=prepend_pointer_list(bi?bi->pointer_list:NULL, num_pointers);
1607 /* keep track of alignment */
1608 if(alignment<type_item->alignment){
1609 alignment=type_item->alignment;
1615 /* see if it is a fixed array */
1617 is_array_of_pointers=0;
1618 if(!strcmp(ti->str, "[")){
1621 /* this might be a fixed array */
1624 fixed_array_size=atoi(ti->str);
1625 sprintf(fss, "%d", fixed_array_size);
1627 if(!strcmp("]", ti->str)){
1628 /* this is just a normal [] array */
1630 } else if(!strcmp("*", ti->str)){
1631 pi=prepend_pointer_list(pi, num_pointers+1);
1633 is_array_of_pointers=1;
1635 } else if(strcmp(fss, ti->str)){
1636 fprintf(stderr, "ERROR: typedefstruct (%s) fixed array size looks different to calculated one %s!=%s\n", struct_name, fss, ti->str);
1643 if(strcmp(ti->str, "]")){
1644 fprintf(stderr, "ERROR: typedefstruct fixed array does not end with ']' it ended with %s\n",ti->str);
1650 sprintf(hf_index, "hf_%s_%s_%s", ifname, struct_name, field_name);
1651 /* pass 0 generate subdissectors */
1653 char filter_name[256];
1656 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, struct_name, field_name);
1657 ptmpstr=strdup(tmpstr);
1659 if(check_if_to_emit(tmpstr)){
1660 sprintf(filter_name, "%s.%s.%s", ifname, struct_name, field_name);
1661 hf=register_hf_field(hf_index, field_name, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
1662 FPRINTF(eth_code, "static int\n");
1663 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
1664 FPRINTF(eth_code, "{\n");
1665 FPRINTF(eth_code, " guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
1666 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
1667 FPRINTF(eth_code, " return offset;\n");
1668 FPRINTF(eth_code, "}\n");
1669 FPRINTF(eth_code, "\n");
1671 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1674 if(is_array_of_pointers){
1675 pointer_type=pi->type;
1677 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1678 if(check_if_to_emit(tmpstr)){
1679 FPRINTF(eth_code, "static int\n");
1680 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1681 FPRINTF(eth_code, "{\n");
1682 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);
1683 FPRINTF(eth_code, " return offset;\n");
1684 FPRINTF(eth_code, "}\n");
1685 FPRINTF(eth_code, "\n");
1687 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1690 ptmpstr=strdup(tmpstr);
1691 } else if(fixed_array_size){
1692 sprintf(tmpstr, "fixedarray_%s", ptmpstr);
1693 if(check_if_to_emit(tmpstr)){
1694 FPRINTF(eth_code, "static int\n");
1695 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1696 FPRINTF(eth_code, "{\n");
1697 FPRINTF(eth_code, " int count=%d;\n",fixed_array_size);
1698 FPRINTF(eth_code, " while(count--){\n");
1699 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
1700 FPRINTF(eth_code, " }\n");
1701 FPRINTF(eth_code, "\n");
1702 FPRINTF(eth_code, " return offset;\n");
1703 FPRINTF(eth_code, "}\n");
1704 FPRINTF(eth_code, "\n");
1706 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1708 ptmpstr=strdup(tmpstr);
1711 /* handle switch_is */
1713 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
1717 sprintf(tmpstr, "ucarray_%s", ptmpstr);
1718 if(check_if_to_emit(tmpstr)){
1719 FPRINTF(eth_code, "static int\n");
1720 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1721 FPRINTF(eth_code, "{\n");
1722 FPRINTF(eth_code, " offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
1723 FPRINTF(eth_code, " return offset;\n");
1724 FPRINTF(eth_code, "}\n");
1725 FPRINTF(eth_code, "\n");
1727 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1729 ptmpstr=strdup(tmpstr);
1732 sprintf(tmpstr, "uvarray_%s", ptmpstr);
1733 if(check_if_to_emit(tmpstr)){
1734 FPRINTF(eth_code, "static int\n");
1735 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1736 FPRINTF(eth_code, "{\n");
1737 FPRINTF(eth_code, " offset=dissect_ndr_uvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
1738 FPRINTF(eth_code, " return offset;\n");
1739 FPRINTF(eth_code, "}\n");
1740 FPRINTF(eth_code, "\n");
1742 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1744 ptmpstr=strdup(tmpstr);
1746 case BI_SIZE_IS|BI_LENGTH_IS:
1747 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
1748 if(check_if_to_emit(tmpstr)){
1749 FPRINTF(eth_code, "static int\n");
1750 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1751 FPRINTF(eth_code, "{\n");
1752 FPRINTF(eth_code, " offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
1753 FPRINTF(eth_code, " return offset;\n");
1754 FPRINTF(eth_code, "}\n");
1755 FPRINTF(eth_code, "\n");
1757 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1759 ptmpstr=strdup(tmpstr);
1762 fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
1767 /* handle pointers */
1768 while(num_pointers--){
1769 pointer_type=pi->type;
1771 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1772 if(check_if_to_emit(tmpstr)){
1773 FPRINTF(eth_code, "static int\n");
1774 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1775 FPRINTF(eth_code, "{\n");
1776 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);
1777 FPRINTF(eth_code, " return offset;\n");
1778 FPRINTF(eth_code, "}\n");
1779 FPRINTF(eth_code, "\n");
1781 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1784 ptmpstr=strdup(tmpstr);
1789 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, struct_name, field_name);
1790 ptmpstr=strdup(tmpstr);
1792 /* handle fixedsizearrays */
1793 if(is_array_of_pointers){
1794 pointer_type=pi->type;
1796 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1797 ptmpstr=strdup(tmpstr);
1798 } else if(fixed_array_size){
1799 sprintf(tmpstr, "fixedarray_%s", ptmpstr);
1800 ptmpstr=strdup(tmpstr);
1803 /* handle switch_is */
1805 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
1809 sprintf(tmpstr, "ucarray_%s", ptmpstr);
1810 ptmpstr=strdup(tmpstr);
1813 sprintf(tmpstr, "uvarray_%s", ptmpstr);
1814 ptmpstr=strdup(tmpstr);
1816 case BI_SIZE_IS|BI_LENGTH_IS:
1817 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
1818 ptmpstr=strdup(tmpstr);
1821 fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
1826 /* handle pointers */
1827 while(num_pointers--){
1828 pointer_type=pi->type;
1830 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1831 ptmpstr=strdup(tmpstr);
1834 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
1835 FPRINTF(eth_code, "\n");
1838 if(strcmp(ti->str,";")){
1839 fprintf(stderr, "ERROR: field does not en with ';'\n");
1843 bi=NULL; /* clear bi before we start on the next field */
1847 FPRINTF(eth_code, " proto_item_set_len(item, offset-old_offset);\n");
1848 FPRINTF(eth_code, "\n");
1849 FPRINTF(eth_code, " return offset;\n");
1850 FPRINTF(eth_code, "}\n");
1851 register_new_type(struct_name, dissectorname, "FT_NONE", "BASE_NONE", "0", "NULL", alignment);
1855 typedef_struct_finished:
1856 FPRINTF(NULL,"\nEND STRUCT:%s pass:%d\n-------\n",struct_name,pass);
1858 /* only advance token_list for pass==1
1859 ti now points to the '}' token
1862 if(!ti || strcmp(ti->str,"}")){
1863 fprintf(stderr, "ERROR: struct does not end with '}'\n");
1868 /* just skip the name */
1871 if(!ti || strcmp(ti->str,";")){
1872 fprintf(stderr, "ERROR: struct does not end with ';'\n");
1881 /* this function will parse a
1883 construct and generate the appropriate code.
1884 the typedef will be removed from the token_list once it has been processed
1885 the function assumes that the typedef is the first object in the token_list
1886 the function will be called twice, once with pass=0 and once with pass=1
1887 which controls whether subdissectors are to be generated or whether the
1888 bitmap dissector itself is to be generated
1890 bitmaps are by default 32 bits
1892 static void parsetypedefbitmap(int pass)
1894 token_item_t *ti, *tmpti;
1896 char dissectorname[256], hf_bitname[256];
1900 bracket_item_t *bi=NULL;
1903 if(strcmp(ti->str, "typedef")){
1904 fprintf(stderr, "ERROR: typedefbitmap first token is not 'typedef'\n");
1909 alignment=4; /* default size is 32 bits */
1911 if(!strcmp(ti->str, "[")){
1912 ti=parsebrackets(ti, &bi);
1914 /* check that we know how to handle the bracket thing */
1916 if(bi->flags&(~(BI_BITMAP32|BI_BITMAP8))){
1917 fprintf(stderr, "ERROR: typedefbitmap unknown bracket flags encountered : 0x%08x\n",bi->flags);
1920 if(bi->flags&BI_BITMAP32){
1923 if(bi->flags&BI_BITMAP8){
1929 if(strcmp(ti->str, "bitmap")){
1930 fprintf(stderr, "ERROR: typedefbitmap second token is not 'bitmap'\n");
1935 if(strcmp(ti->str, "{")){
1936 fprintf(stderr, "ERROR: typedefbitmap third token is not '{'\n");
1941 /* search forward until the '}' so we can find the name of the bitmap */
1942 for(tmpti=ti;tmpti;tmpti=tmpti->next){
1943 if(!strcmp(tmpti->str, "{")){
1944 fprintf(stderr, "ERROR: typedefbitmap '{' encountered inside bitmap\n");
1947 if(!strcmp(tmpti->str, "}")){
1951 if (!tmpti || !tmpti->next){
1952 fprintf(stderr, "ERROR: typedefbitmap missing matching '}'\n");
1955 bitmap_name=tmpti->next->str;
1956 sprintf(dissectorname, "%s_dissect_%s", ifname, bitmap_name);
1958 FPRINTF(NULL,"\nBITMAP:%s pass:%d\n-------\n",bitmap_name,pass);
1960 /* pass 1 generate header for the struct dissector */
1962 FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, bitmap_name);
1963 FPRINTF(eth_ettarr, " &ett_%s_%s,\n", ifname, bitmap_name);
1964 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);
1965 FPRINTF(eth_code, "\n");
1966 FPRINTF(eth_code, "int\n");
1967 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);
1968 FPRINTF(eth_code, "{\n");
1969 FPRINTF(eth_code, " proto_item *item=NULL;\n");
1970 FPRINTF(eth_code, " proto_tree *tree=NULL;\n");
1973 FPRINTF(eth_code, " guint8 flags;\n");
1974 FPRINTF(eth_code, "\n");
1977 FPRINTF(eth_code, " guint32 flags;\n");
1978 FPRINTF(eth_code, "\n");
1979 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
1982 fprintf(stderr, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment);
1985 FPRINTF(eth_code, "\n");
1986 FPRINTF(eth_code, " if(parent_tree){\n");
1987 FPRINTF(eth_code, " item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, %d, TRUE);\n", alignment);
1988 FPRINTF(eth_code, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, bitmap_name);
1989 FPRINTF(eth_code, " }\n");
1990 FPRINTF(eth_code, "\n");
1993 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, NULL, drep, -1, &flags);\n");
1994 FPRINTF(eth_code, "\n");
1997 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &flags);\n");
1998 FPRINTF(eth_code, "\n");
2001 fprintf(stderr, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment);
2004 FPRINTF(eth_code, "\n");
2007 /* scan the struct and create call for all bits */
2009 if(!strcmp(ti->str, "}")){
2012 if(!strcmp(ti->str, "[")){
2013 fprintf(stderr, "ERROR: typedefbitmap can not handle '[' yet\n");
2019 sprintf(hf_bitname, "hf_%s_%s_%s", ifname, bitmap_name, name);
2021 if(strcmp(ti->str, "=")){
2022 fprintf(stderr, "ERROR: typedefbitmap i expected a '=' here\n");
2030 if(!strncmp(value, "0x", 2)){
2031 sscanf(value, "0x%x", &val);
2033 fprintf(stderr, "ERROR: typedefbitmap can only handle hexadecimal constants\n");
2038 fprintf(stderr, "ERROR: typedefbitmap can only handle single bit fields\n");
2043 char filter_name[256], base_name[256], tfs_name[256];
2045 sprintf(filter_name, "%s.%s.%s", ifname, bitmap_name, name);
2046 sprintf(base_name, "%d", alignment*8);
2047 sprintf(tfs_name, "TFS(&%s_tfs)", name);
2048 register_hf_field(hf_bitname, name, filter_name, "FT_BOOLEAN", base_name, tfs_name, value, "");
2050 FPRINTF(eth_code, "static const true_false_string %s_tfs = {\n",name);
2051 FPRINTF(eth_code, " \"%s is SET\",\n", name);
2052 FPRINTF(eth_code, " \"%s is NOT set\"\n", name);
2053 FPRINTF(eth_code, "};\n");
2054 FPRINTF(eth_code, "\n");
2058 FPRINTF(eth_code, " proto_tree_add_boolean(tree, %s, tvb, offset-%d, %d, flags);\n", hf_bitname, alignment, alignment);
2059 FPRINTF(eth_code, " if(flags&%s){\n", value);
2060 FPRINTF(eth_code, " proto_item_append_text(item, \" %s\");\n", name);
2061 FPRINTF(eth_code, " }\n");
2062 FPRINTF(eth_code, " flags&=(~%s);\n", value);
2063 FPRINTF(eth_code, "\n");
2066 if(!strcmp(ti->str, ",")){
2073 FPRINTF(eth_code, " if(flags){\n");
2074 FPRINTF(eth_code, " proto_item_append_text(item, \"UNKNOWN-FLAGS\");\n");
2075 FPRINTF(eth_code, " }\n");
2076 FPRINTF(eth_code, "\n");
2077 FPRINTF(eth_code, " return offset;\n");
2078 FPRINTF(eth_code, "}\n");
2081 register_new_type(bitmap_name, dissectorname, "FT_UINT8", "BASE_HEX", "0", "NULL", alignment);
2084 register_new_type(bitmap_name, dissectorname, "FT_UINT32", "BASE_HEX", "0", "NULL", alignment);
2087 fprintf(stderr, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment);
2092 FPRINTF(NULL,"\nEND BITMAP:%s pass:%d\n-------\n",bitmap_name,pass);
2094 /* only advance token_list for pass==1
2095 ti now points to the '}' token
2098 if(!ti || strcmp(ti->str,"}")){
2099 fprintf(stderr, "ERROR: bitmap does not end with '}'\n");
2104 /* just skip the name */
2107 if(!ti || strcmp(ti->str,";")){
2108 fprintf(stderr, "ERROR: bitmap does not end with ';'\n");
2117 /* a case tag might be a negative number, i.e. contain a '-' sign which
2118 is not valid inside a symbol name in c.
2132 /* this function will parse a
2134 construct and generate the appropriate code.
2135 the typedef will be removed from the token_list once it has been processed
2136 the function assumes that the typedef is the first object in the token_list
2137 the function will be called twice, once with pass=0 and once with pass=1
2138 which controls whether subdissectors are to be generated or whether the
2139 union dissector itself is to be generated
2141 static void parsetypedefunion(int pass)
2144 token_item_t *ti, *tmpti;
2145 char dissectorname[256];
2146 bracket_item_t *bi=NULL;
2147 char tmpstr[256], *ptmpstr;
2148 int level, num_pointers;
2149 static int alignment;
2150 type_item_t *type_item;
2152 int tag_alignment, item_alignment;
2155 if(strcmp(ti->str, "typedef")){
2156 fprintf(stderr, "ERROR: typedefunion first token is not 'typedef'\n");
2161 if(!strcmp(ti->str, "[")){
2162 ti=parsebrackets(ti, &bi);
2164 /* check that we know how to handle the bracket thing */
2166 if(bi->flags&(~(BI_SWITCH_TYPE))){
2167 fprintf(stderr, "ERROR: typedefunion unknown bracket flags encountered : 0x%08x\n",bi->flags);
2172 if(strcmp(ti->str, "union")){
2173 fprintf(stderr, "ERROR: typedefunion second token is not 'union'\n");
2178 if(strcmp(ti->str, "{")){
2179 fprintf(stderr, "ERROR: typedefunion third token is not '{'\n");
2184 /* search forward until the '}' so we can find the name of the union */
2185 for(tmpti=ti,level=0;tmpti;tmpti=tmpti->next){
2186 if(!strcmp(tmpti->str, "{")){
2190 if(!strcmp(tmpti->str, "}")){
2199 if (!tmpti || !tmpti->next){
2200 fprintf(stderr, "ERROR: typedefunion missing matching '}'\n");
2203 union_name=tmpti->next->str;
2204 sprintf(dissectorname, "%s_dissect_union_%s", ifname, union_name);
2206 FPRINTF(NULL,"\nUNION:%s pass:%d\n-------\n",union_name,pass);
2208 if(bi && bi->flags&BI_SWITCH_TYPE){
2209 tag_alignment=bi->union_tag_size;
2211 tag_alignment=get_union_tag_size(union_name);
2214 /* this is pass 0 so reset alignment to the minimum possible value
2215 and update as items are processed.
2216 we need alignment when pass 1 is run
2219 alignment=tag_alignment;
2222 /* pass 1 generate header for the struct dissector */
2224 FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, union_name);
2225 FPRINTF(eth_ettarr, " &ett_%s_%s,\n", ifname, union_name);
2226 FPRINTF(eth_code, "\n");
2227 FPRINTF(eth_code, "static int\n");
2228 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);
2229 FPRINTF(eth_code, "{\n");
2230 FPRINTF(eth_code, " proto_item *item=NULL;\n");
2231 FPRINTF(eth_code, " proto_tree *tree=NULL;\n");
2232 FPRINTF(eth_code, " int old_offset;\n");
2233 /* we do alignment on the tag itself here so that
2234 we skip any alignment padding prior to where the tag
2235 itself starts, this makes the byterange in the hexpane
2236 for the union expansion start with the first byte of the tag
2238 switch(tag_alignment){
2242 FPRINTF(eth_code, " guint16 level;\n");
2243 FPRINTF(eth_code, "\n");
2244 FPRINTF(eth_code, " ALIGN_TO_2_BYTES;\n");
2245 FPRINTF(eth_code, "\n");
2248 FPRINTF(eth_code, " guint32 level;\n");
2249 FPRINTF(eth_code, "\n");
2250 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
2251 FPRINTF(eth_code, "\n");
2254 fprintf(stderr, "ERROR: typedefunion 1 can not handle alignment:%d\n",alignment);
2257 FPRINTF(eth_code, " old_offset=offset;\n");
2258 FPRINTF(eth_code, " if(parent_tree){\n");
2259 FPRINTF(eth_code, " item=proto_tree_add_text(parent_tree, tvb, offset, -1, \"%s\");\n", union_name);
2260 FPRINTF(eth_code, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, union_name);
2261 FPRINTF(eth_code, " }\n");
2262 FPRINTF(eth_code, "\n");
2263 switch(tag_alignment){
2267 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree,\n");
2268 FPRINTF(eth_code, " drep, hf_index, &level);\n");
2271 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree,\n");
2272 FPRINTF(eth_code, " drep, hf_index, &level);\n");
2275 fprintf(stderr, "ERROR: typedefunion 2 can not handle alignment:%d\n",alignment);
2278 FPRINTF(eth_code, "\n");
2279 FPRINTF(eth_code, " switch(level){\n");
2282 /* scan the struct and create all subdissectors */
2285 if(!strcmp(ti->str, "{")){
2290 if(!strcmp(ti->str, "}")){
2298 if(!strcmp(ti->str, "[")){
2299 ti=parsebrackets(ti, &bi);
2304 fprintf(stderr, "ERROR : typedefunion no brackets found for case\n");
2307 /* make sure we catch when we havent implemented everything
2309 we currently only know about CASE and CASE_DEFAULT flags
2311 if(bi->flags&(~(BI_CASE|BI_CASE_DEFAULT|BI_POINTER))){
2312 fprintf(stderr, "ERROR: typedefunion unknown bracket flags encountered : 0x%08x\n",bi->flags);
2315 if(!(bi->flags&BI_CASE)){
2316 fprintf(stderr, "ERROR : typedefunion no case found in brackets\n");
2320 /* only empty default cases for now */
2321 if(bi->flags&BI_CASE_DEFAULT){
2322 if(strcmp(ti->str,";")){
2323 fprintf(stderr, "ERROR: default tag is not empty\n");
2331 /* just skip all and any 'empty' arms */
2332 if(!strcmp(ti->str, ";")){
2337 /* handle the type, verify that we KNOW this type */
2338 type_item=find_type(ti->str);
2340 fprintf(stderr, "ERROR : typedefunion unknown type %s\n",ti->str);
2344 /* count the levels of pointers */
2345 for(num_pointers=0;!strcmp(ti->str, "*");ti=ti->next){
2349 /* keep track of alignment */
2353 item_alignment=type_item->alignment;
2355 if(alignment<item_alignment){
2356 alignment=item_alignment;
2359 sprintf(hf_index, "hf_%s_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
2360 /* pass 0 generate subdissectors */
2362 char filter_name[256];
2364 sprintf(tmpstr, "%s_dissect_union_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
2365 ptmpstr=strdup(tmpstr);
2367 sprintf(filter_name, "%s.%s.%s", ifname, union_name, ti->str);
2368 hf=register_hf_field(hf_index, ti->str, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
2370 FPRINTF(eth_code, "static int\n");
2371 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
2372 FPRINTF(eth_code, "{\n");
2373 FPRINTF(eth_code, " guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
2374 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
2375 FPRINTF(eth_code, " return offset;\n");
2376 FPRINTF(eth_code, "}\n");
2377 FPRINTF(eth_code, "\n");
2379 /* handle pointers */
2380 while(num_pointers--){
2381 sprintf(tmpstr, "%s_%s", ptmpstr, "unique");
2382 FPRINTF(eth_code, "static int\n");
2383 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2384 FPRINTF(eth_code, "{\n");
2385 FPRINTF(eth_code, " offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, drep, %s, NDR_POINTER_UNIQUE, \"%s\", -1);\n", ptmpstr, ti->str);
2386 FPRINTF(eth_code, " return offset;\n");
2387 FPRINTF(eth_code, "}\n");
2388 FPRINTF(eth_code, "\n");
2390 ptmpstr=strdup(tmpstr);
2396 /* handle pointers */
2397 sprintf(tmpstr, "%s_dissect_union_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
2398 ptmpstr=strdup(tmpstr);
2399 while(num_pointers--){
2400 sprintf(tmpstr, "%s_%s", ptmpstr, "unique");
2401 ptmpstr=strdup(tmpstr);
2404 if(bi->flags&BI_CASE_DEFAULT){
2405 FPRINTF(eth_code, " default:\n");
2407 FPRINTF(eth_code, " case %s:\n",bi->case_name);
2409 /* each arm itself is aligned independently */
2410 switch(item_alignment){
2414 FPRINTF(eth_code, " ALIGN_TO_2_BYTES;\n");
2417 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
2420 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
2423 fprintf(stderr, "ERROR: typedefunion 3 can not handle alignment:%d\n",item_alignment);
2426 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
2427 FPRINTF(eth_code, " break;\n");
2428 FPRINTF(eth_code, "\n");
2432 if(strcmp(ti->str,";")){
2433 fprintf(stderr, "ERROR: field does not end with ';'\n");
2440 FPRINTF(eth_code, " }\n");
2441 FPRINTF(eth_code, "\n");
2442 FPRINTF(eth_code, " proto_item_set_len(item, offset-old_offset);\n");
2443 FPRINTF(eth_code, "\n");
2444 FPRINTF(eth_code, " return offset;\n");
2445 FPRINTF(eth_code, "}\n");
2446 switch(tag_alignment){
2448 register_new_type(union_name, dissectorname, "FT_UINT16", "BASE_DEC", "0", "NULL", alignment);
2451 register_new_type(union_name, dissectorname, "FT_UINT32", "BASE_DEC", "0", "NULL", alignment);
2454 fprintf(stderr, "ERROR: typedefunion 4 can not handle alignment:%d\n",alignment);
2459 FPRINTF(NULL,"\nEND UNION:%s pass:%d\n-------\n",union_name,pass);
2461 /* only advance token_list for pass==1
2462 ti now points to the '}' token
2465 if(!ti || strcmp(ti->str,"}")){
2466 fprintf(stderr, "ERROR: union does not end with '}'\n");
2471 /* just skip the name */
2474 if(!ti || strcmp(ti->str,";")){
2475 fprintf(stderr, "ERROR: union does not end with ';'\n");
2485 /* this function will parse a
2487 construct and generate the appropriate code.
2488 the function will be removed from the token_list once it has been processed
2489 the function assumes that the function is the first object in the token_list
2490 the function will be called three times with
2491 pass=0 generate subdissectors and entries for the function table
2492 pass=1 generate code for the REQUEST
2493 pass=2 generate code for the REPLY
2495 static void parsefunction(int pass)
2497 char *function_name;
2498 static int funcno=0;
2500 bracket_item_t *bi=NULL;
2504 char tmpstr[256], *ptmpstr;
2505 int level, num_pointers;
2506 type_item_t *type_item;
2510 if(strcmp(ti->str, "WERROR")){
2511 fprintf(stderr, "ERROR: function first token is not 'WERROR'\n");
2516 function_name=ti->str;
2519 if(strcmp(ti->str, "(")){
2520 fprintf(stderr, "ERROR: function third token is not '('\n");
2525 FPRINTF(NULL,"\nFUNCTION:%s pass:%d\n-------\n",function_name,pass);
2528 FPRINTF(eth_ft, " { %d, \"%s\",\n",funcno,function_name);
2529 FPRINTF(eth_ft, " %s_dissect_%s_request,\n", ifname, function_name);
2530 FPRINTF(eth_ft, " %s_dissect_%s_response },\n", ifname, function_name);
2534 /* pass 1,2 generate header for the function dissector */
2535 if((pass==1)||(pass==2)){
2536 FPRINTF(eth_code, "\n");
2537 FPRINTF(eth_code, "static int\n");
2538 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");
2539 FPRINTF(eth_code, "{\n");
2542 /* scan the struct and create all subdissectors */
2545 if(!strcmp(ti->str, "(")){
2550 if(!strcmp(ti->str, ")")){
2558 if(!strcmp(ti->str, "[")){
2559 ti=parsebrackets(ti, &bi);
2564 fprintf(stderr, "ERROR : function no brackets found for case\n");
2568 /* make sure we catch when we havent implemented everything
2570 we currently only know about IN and OUT flags
2572 if(bi->flags&(~(BI_IN|BI_OUT|BI_POINTER|BI_SIZE_IS|BI_LENGTH_IS))){
2573 fprintf(stderr, "ERROR: function unknown bracket flags encountered : 0x%08x\n",bi->flags);
2576 if(!(bi->flags&(BI_IN|BI_OUT))){
2577 fprintf(stderr, "ERROR : function parameter is neither in nor out\n");
2581 /* handle the type, verify that we KNOW this type */
2582 type_item=find_type(ti->str);
2584 fprintf(stderr, "ERROR : function unknown type %s\n",ti->str);
2588 /* count the levels of pointers */
2589 for(num_pointers=0;!strcmp(ti->str, "*");ti=ti->next){
2593 /* now that we know how many real poitner there were we must
2594 prepend default pointers to the list so it has the right
2597 pi=prepend_pointer_list(bi->pointer_list, num_pointers);
2599 sprintf(hf_index, "hf_%s_%s_%s", ifname, function_name, ti->str);
2600 /* pass 0 generate subdissectors */
2602 char filter_name[256];
2605 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, function_name, ti->str);
2606 ptmpstr=strdup(tmpstr);
2609 sprintf(filter_name, "%s.%s.%s", ifname, function_name, ti->str);
2610 hf=register_hf_field(hf_index, ti->str, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
2612 FPRINTF(eth_code, "static int\n");
2613 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
2614 FPRINTF(eth_code, "{\n");
2615 FPRINTF(eth_code, " guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
2616 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
2617 FPRINTF(eth_code, " return offset;\n");
2618 FPRINTF(eth_code, "}\n");
2619 FPRINTF(eth_code, "\n");
2622 /* handle switch_is */
2624 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
2627 case BI_SIZE_IS|BI_LENGTH_IS:
2628 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
2629 FPRINTF(eth_code, "static int\n");
2630 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2631 FPRINTF(eth_code, "{\n");
2632 FPRINTF(eth_code, " offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
2633 FPRINTF(eth_code, " return offset;\n");
2634 FPRINTF(eth_code, "}\n");
2635 FPRINTF(eth_code, "\n");
2636 ptmpstr=strdup(tmpstr);
2639 sprintf(tmpstr, "ucarray_%s", ptmpstr);
2640 FPRINTF(eth_code, "static int\n");
2641 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2642 FPRINTF(eth_code, "{\n");
2643 FPRINTF(eth_code, " offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
2644 FPRINTF(eth_code, " return offset;\n");
2645 FPRINTF(eth_code, "}\n");
2646 FPRINTF(eth_code, "\n");
2647 ptmpstr=strdup(tmpstr);
2650 fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
2655 /* handle pointers */
2656 while(num_pointers--){
2657 pointer_type=pi->type;
2659 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
2660 FPRINTF(eth_code, "static int\n");
2661 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2662 FPRINTF(eth_code, "{\n");
2663 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);
2664 FPRINTF(eth_code, " return offset;\n");
2665 FPRINTF(eth_code, "}\n");
2666 FPRINTF(eth_code, "\n");
2668 ptmpstr=strdup(tmpstr);
2673 if((pass==1)||(pass==2)){
2674 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, function_name, ti->str);
2675 ptmpstr=strdup(tmpstr);
2678 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
2681 case BI_SIZE_IS|BI_LENGTH_IS:
2682 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
2683 ptmpstr=strdup(tmpstr);
2686 sprintf(tmpstr, "ucarray_%s", ptmpstr);
2687 ptmpstr=strdup(tmpstr);
2690 fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
2695 /* handle pointers */
2696 while(num_pointers--){
2697 pointer_type=pi->type;
2699 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
2700 ptmpstr=strdup(tmpstr);
2703 if((pass==1)&&(bi->flags&BI_IN)){
2704 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
2705 FPRINTF(eth_code, " offset=dissect_deferred_pointers(pinfo, tvb, offset, drep);\n");
2706 FPRINTF(eth_code, "\n");
2708 if((pass==2)&&(bi->flags&BI_OUT)){
2709 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
2710 FPRINTF(eth_code, " offset=dissect_deferred_pointers(pinfo, tvb, offset, drep);\n");
2711 FPRINTF(eth_code, "\n");
2717 if(!strcmp(ti->str,",")){
2723 if((pass==1)||(pass==2)){
2725 FPRINTF(eth_code, " offset=dissect_ntstatus(tvb, offset, pinfo, tree, drep, %s, NULL);\n", hf_status);
2726 FPRINTF(eth_code, "\n");
2728 FPRINTF(eth_code, "\n");
2729 FPRINTF(eth_code, " return offset;\n");
2730 FPRINTF(eth_code, "}\n");
2733 FPRINTF(NULL,"\nEND FUNCTION:%s pass:%d\n-------\n",function_name,pass);
2735 /* only advance token_list for pass==2
2736 ti now points to the ')' token
2739 if(!ti || strcmp(ti->str,")")){
2740 fprintf(stderr, "ERROR: function does not end with ')'\n");
2745 if(!ti || strcmp(ti->str,";")){
2746 fprintf(stderr, "ERROR: function does not end with ';'\n");
2756 /* this function will parse a
2759 typedef [ v1_enum ] enum {
2760 construct and generate the appropriate code.
2761 the typedef will be removed from the token_list once it has been processed
2762 the function assumes that the typedef is the first object in the token_list
2764 static void parsetypedefenum(void)
2767 enum_list_t *enum_list, *el, *lastel;
2769 char dissectorname[256], valsstring[256], hfvalsstring[256];
2774 if(strcmp(ti->str, "typedef")){
2775 fprintf(stderr, "ERROR: typedefenum first token is not 'typedef'\n");
2780 /* this could be a [ v1_enum ] */
2781 if(!strcmp(ti->str, "[")){
2784 if(strcmp(ti->str, "v1_enum")){
2785 fprintf(stderr, "ERROR: typedefenum not 'v1_enum' inside brackets\n");
2790 if(strcmp(ti->str, "]")){
2791 fprintf(stderr, "ERROR: typedefenum 'v1_enum' is not followed by ']'\n");
2800 if(strcmp(ti->str, "enum")){
2801 fprintf(stderr, "ERROR: typedefenum second token is not 'enum'\n");
2806 if(strcmp(ti->str, "{")){
2807 fprintf(stderr, "ERROR: typedefenum third token is not '{'\n");
2812 /* now parse all values until we find the "}" */
2818 if(!strcmp(ti->str,"}")){
2823 /* handle 4 types of entries:
2829 el=malloc(sizeof(enum_list_t));
2842 /* grab separator */
2843 if(!strcmp(ti->str,"=")){
2846 el->val=atoi(ti->str);
2854 if(!strcmp(ti->str,",")){
2860 if(!strcmp(ti->str,"}")){
2865 fprintf(stderr,"ERROR: typedefenum should not be reached\n");
2869 /* verify that it ends with a ';' */
2870 if(strcmp(ti->next->str,";")){
2871 fprintf(stderr,"ERROR enum terminator is not ';'\n");
2875 sprintf(valsstring, "%s_%s_vals", ifname, ti->str);
2876 sprintf(dissectorname, "%s_dissect_%s", ifname, ti->str);
2878 FPRINTF(NULL,"\nENUM:%s\n-------\n",ti->str);
2880 FPRINTF(eth_hdr, "\n");
2881 for(el=enum_list;el;el=el->next){
2882 FPRINTF(eth_hdr, "#define %s %d\n", el->name, el->val);
2885 FPRINTF(eth_hdr, "\n");
2886 FPRINTF(eth_hdr, "extern const value_string %s[];\n", valsstring);
2887 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);
2889 FPRINTF(eth_code, "\n");
2890 FPRINTF(eth_code, "const value_string %s[] = {\n", valsstring);
2892 for(el=enum_list;el;el=el->next){
2893 FPRINTF(eth_code, " { %d , \"%s\" },\n", el->val, el->name);
2895 FPRINTF(eth_code, " { 0 , NULL }\n");
2896 FPRINTF(eth_code, "};\n");
2898 FPRINTF(eth_code, "\n");
2899 FPRINTF(eth_code, "int\n");
2900 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);
2901 FPRINTF(eth_code, "{\n");
2904 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
2907 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
2910 fprintf(stderr,"ERROR enum unknown size\n");
2914 FPRINTF(eth_code, " return offset;\n");
2915 FPRINTF(eth_code, "}\n");
2916 FPRINTF(eth_code, "\n");
2919 sprintf(hfvalsstring, "VALS(%s)", valsstring);
2922 register_new_type(ti->str, dissectorname, "FT_INT16", "BASE_DEC", "0", hfvalsstring, 2);
2925 register_new_type(ti->str, dissectorname, "FT_INT32", "BASE_DEC", "0", hfvalsstring, 4);
2928 fprintf(stderr,"ERROR enum unknown size\n");
2932 FPRINTF(NULL,"\n----------\nEND ENUM:%s\n",ti->str);
2934 /* skip past the name and the ';' */
2935 token_list=ti->next->next;
2938 typedef struct _trimmed_prefixes_t {
2939 struct _trimmed_prefixes_t *next;
2941 } trimmed_prefixes_t;
2942 static trimmed_prefixes_t *prefixes_to_trim=NULL;
2944 static void preparetrimprefix(char *prefix_name)
2946 trimmed_prefixes_t *new_prefix;
2947 new_prefix=malloc(sizeof(trimmed_prefixes_t));
2948 new_prefix->next=prefixes_to_trim;
2949 prefixes_to_trim=new_prefix;
2950 new_prefix->name=strdup(prefix_name);
2957 trimmed_prefixes_t *pfx;
2960 for(pfx=prefixes_to_trim;pfx;pfx=pfx->next){
2961 len=strlen(pfx->name);
2962 for(ti=token_list;ti;ti=ti->next){
2963 if(!strncmp(ti->str, pfx->name, len)){
2970 static int Exit(int code)
2972 fprintf(stderr, "The tokens remaining when aborting:\n");
2978 static void usage(void)
2980 fprintf(stderr, "Usage: idl2wrs <interface>\n");
2984 mergefile(char *name, FILE *outfile)
2988 fprintf(outfile, "\n\n/* INCLUDED FILE : %s */\n", name);
2989 infile=fopen(name, "r");
2990 while(!feof(infile)){
2998 fprintf(outfile, "/* END OF INCLUDED FILE : %s */\n\n\n", name);
3004 str_read_string(char *str, char **name)
3006 char tmpstr[256], *strptr;
3016 *name=strdup(tmpstr);
3020 if( (*str==' ') || (*str=='\t') ){
3031 if( (*str==' ') || (*str=='\t') ){
3037 *name=strdup(tmpstr);
3040 if( (*str=='"') || (*str=='\n') ){
3042 *name=strdup(tmpstr);
3051 readcnffile(FILE *fh)
3055 FPRINTF(NULL, "Reading conformance file\n=======================\n");
3058 fgets(cnfline, 1023, fh);
3062 if(cnfline[0]=='#'){
3063 /* ignore all comments */
3064 } else if(!strncmp(cnfline, "NOEMIT", 6)){
3065 no_emit_item_t *nei;
3069 str=str_read_string(str, &name);
3070 nei=malloc(sizeof(no_emit_item_t));
3071 nei->next=no_emit_list;
3074 FPRINTF(NULL, "NOEMIT : %s\n", nei->name);
3075 } else if(!strncmp(cnfline, "TYPE", 4)){
3076 char *name, *dissectorname, *ft_type, *base_type;
3077 char *mask, *valsstring, *al;
3082 str=str_read_string(str, &name);
3083 str=str_read_string(str, &dissectorname);
3084 str=str_read_string(str, &ft_type);
3085 str=str_read_string(str, &base_type);
3086 str=str_read_string(str, &mask);
3087 str=str_read_string(str, &valsstring);
3088 str=str_read_string(str, &al);
3091 FPRINTF(NULL, "TYPE : X%s,%sX\n", name, dissectorname);
3092 register_new_type(name, dissectorname, ft_type, base_type, mask, valsstring, alignment);
3093 } else if(!strncmp(cnfline, "PARAM_VALUE", 11)){
3094 char *dissectorname, *value;
3098 str=str_read_string(str, &dissectorname);
3099 str=str_read_string(str, &value);
3101 FPRINTF(NULL, "PARAM_VALUE : %s=%s\n", dissectorname,value);
3102 register_dissector_param_value(dissectorname, value);
3103 } else if(!strncmp(cnfline, "HF_FIELD", 8)){
3104 char *hf_index, *title, *filter_name, *ft_type;
3105 char *base_type, *valsstring, *mask, *blurb;
3109 str=str_read_string(str, &hf_index);
3110 str=str_read_string(str, &title);
3111 str=str_read_string(str, &filter_name);
3112 str=str_read_string(str, &ft_type);
3113 str=str_read_string(str, &base_type);
3114 str=str_read_string(str, &valsstring);
3115 str=str_read_string(str, &mask);
3116 str=str_read_string(str, &blurb);
3117 FPRINTF(NULL, "HF_FIELD: %s \"%s\"\n", hf_index, title);
3118 register_hf_field(hf_index, title, filter_name, ft_type, base_type, valsstring, mask, blurb);
3119 } else if(!strncmp(cnfline, "HF_RENAME", 9)){
3120 char *old_name, *new_name;
3124 str=str_read_string(str, &old_name);
3125 str=str_read_string(str, &new_name);
3126 FPRINTF(NULL, "HF_RENAME: %s -> %s\n", old_name, new_name);
3127 register_hf_rename(old_name, new_name);
3128 } else if(!strncmp(cnfline, "UNION_TAG_SIZE", 14)){
3129 char *union_name, *union_tag;
3131 union_tag_size_item_t *utsi;
3135 str=str_read_string(str, &union_name);
3136 str=str_read_string(str, &union_tag);
3137 union_tag_size=atoi(union_tag);
3138 FPRINTF(NULL, "UNION_TAG_SIZE: %s == %d\n", union_name, union_tag_size);
3139 utsi=malloc(sizeof(union_tag_size_item_t));
3140 utsi->next=union_tag_size_list;
3141 union_tag_size_list=utsi;
3142 utsi->name=strdup(union_name);
3143 utsi->size=union_tag_size;
3144 } else if(!strncmp(cnfline, "STRIP_PREFIX", 12)){
3149 str=str_read_string(str, &prefix_name);
3150 FPRINTF(NULL, "STRIP_PREFIX: %s\n", prefix_name);
3151 preparetrimprefix(prefix_name);
3153 fprintf(stderr, "ERROR: could not parse cnf directive:%s\n",cnfline);
3159 int main(int argc, char *argv[])
3163 char prefix_str[256];
3172 eth_code=fopen("ETH_CODE", "w");
3173 eth_hdr=fopen("ETH_HDR", "w");
3174 eth_hfarr=fopen("ETH_HFARR", "w");
3175 eth_hf=fopen("ETH_HF", "w");
3176 eth_ettarr=fopen("ETH_ETTARR", "w");
3177 eth_ett=fopen("ETH_ETT", "w");
3178 eth_ft=fopen("ETH_FT", "w");
3179 eth_handoff=fopen("ETH_HANDOFF", "w");
3181 sprintf(idlfile, "%s.cnf", argv[1]);
3182 fh=fopen(idlfile,"r");
3188 sprintf(idlfile, "%s.idl", argv[1]);
3189 fh=fopen(idlfile,"r");
3191 fprintf(stderr, "ERROR: could not open idl-file:%s\n",idlfile);
3198 prune_keyword_parameters("size_is");
3199 prune_keyword_parameters("length_is");
3200 rename_tokens("NTSTATUS", "WERROR");
3201 rename_tokens("unistr_noterm", "unistr");
3202 rename_tokens("ascstr_noterm", "ascstr");
3203 rename_tokens("hyper", "uint64");
3204 FPRINTF(NULL,"\n\nParsing header:\n================\n");
3207 /* some idl files prepend a lot of symbols with <ifname>_
3208 search through the tokenlist and remove all such
3211 sprintf(prefix_str, "%s_", ifname);
3212 preparetrimprefix(prefix_str);
3215 /* this is the main loop, each iteration it tries to identify what
3216 kind of construct is the first entry in the token_list and call
3217 the appropriate handler
3220 /* just skip any [ ] that starts a new construct */
3221 if( !strcmp(token_list->str, "[") ){
3222 token_list=parsebrackets(token_list, &bi);
3226 /* typedef enum { */
3227 if( !strcmp(token_list->str,"typedef")
3228 &&!strcmp(token_list->next->str,"enum") ){
3233 /* typedef [ v1_enum ] enum { */
3234 if( !strcmp(token_list->str,"typedef")
3235 &&!strcmp(token_list->next->str,"[")
3236 &&!strcmp(token_list->next->next->str,"v1_enum")
3237 &&!strcmp(token_list->next->next->next->str,"]")
3238 &&!strcmp(token_list->next->next->next->next->str,"enum") ){
3244 if( !strcmp(token_list->str,"const") ){
3249 /* typedef struct { */
3250 if( !strcmp(token_list->str,"typedef") ){
3251 token_item_t *tmpti;
3253 tmpti=token_list->next;
3254 if( !strcmp(tmpti->str, "[") ){
3255 tmpti=parsebrackets(tmpti, &bi);
3256 /* do some sanity checks here of bi->flags */
3258 if( !strcmp(tmpti->str, "struct") ){
3259 parsetypedefstruct(0);
3260 parsetypedefstruct(1);
3265 /* typedef union { */
3266 if( !strcmp(token_list->str,"typedef") ){
3267 token_item_t *tmpti;
3269 tmpti=token_list->next;
3270 if( !strcmp(tmpti->str, "[") ){
3271 tmpti=parsebrackets(tmpti, &bi);
3272 /* do some sanity checks here of bi->flags */
3274 if( !strcmp(tmpti->str, "union") ){
3275 parsetypedefunion(0);
3276 parsetypedefunion(1);
3281 /* typedef bitmap { */
3282 if( !strcmp(token_list->str,"typedef") ){
3283 token_item_t *tmpti;
3285 tmpti=token_list->next;
3286 if( !strcmp(tmpti->str, "[") ){
3287 tmpti=parsebrackets(tmpti, &bi);
3288 /* do some sanity checks here of bi->flags */
3290 if( !strcmp(tmpti->str, "bitmap") ){
3291 parsetypedefbitmap(0);
3292 parsetypedefbitmap(1);
3297 /* functions: WERROR function '(' */
3298 if( !strcmp(token_list->str,"WERROR")
3299 &&!strcmp(token_list->next->next->str,"(") ){
3307 if( !strcmp(token_list->str,"declare") ){
3324 fclose(eth_handoff);
3326 /* unless the token_list now only contains a single token : '}'
3327 we have failed to compile the idl file properly
3329 if( strcmp(token_list->str, "}") || token_list->next){
3330 fprintf(stderr, "ERROR: we did not process all tokens. Compiler is incomplete.\n===========================================\n");
3335 check_hf_rename_refcount();
3337 /* merge code and template into dissector */
3338 sprintf(line, "packet-dcerpc-%s.c", ifname);
3339 fh=fopen(line, "w");
3340 sprintf(tmplfile, "packet-dcerpc-%s-template.c", argv[1]);
3341 tfh=fopen(tmplfile, "r");
3343 fprintf(stderr, "ERROR: could not find %s\n", tmplfile);
3348 fgets(line, 1024, tfh);
3349 if(!strncmp(line, "ETH_CODE", 8)){
3350 mergefile("ETH_CODE",fh);
3351 } else if(!strncmp(line, "ETH_HDR", 7)){
3352 mergefile("ETH_HDR",fh);
3353 } else if(!strncmp(line, "ETH_HFARR", 9)){
3354 mergefile("ETH_HFARR",fh);
3355 } else if(!strncmp(line, "ETH_HF", 6)){
3356 mergefile("ETH_HF",fh);
3357 } else if(!strncmp(line, "ETH_ETTARR", 10)){
3358 mergefile("ETH_ETTARR",fh);
3359 } else if(!strncmp(line, "ETH_ETT", 7)){
3360 mergefile("ETH_ETT",fh);
3361 } else if(!strncmp(line, "ETH_FT", 6)){
3362 mergefile("ETH_FT",fh);
3363 } else if(!strncmp(line, "ETH_HANDOFF", 11)){
3364 mergefile("ETH_HANDOFF",fh);
3372 sprintf(line, "packet-dcerpc-%s.h", ifname);
3373 fh=fopen(line, "w");
3374 sprintf(tmplfile, "packet-dcerpc-%s-template.h", argv[1]);
3375 tfh=fopen(tmplfile, "r");
3377 fprintf(stderr, "ERROR: could not find %s\n", tmplfile);
3382 fgets(line, 1024, tfh);
3383 if(!strncmp(line, "ETH_CODE", 8)){
3384 mergefile("ETH_CODE",fh);
3385 } else if(!strncmp(line, "ETH_HDR", 7)){
3386 mergefile("ETH_HDR",fh);
3387 } else if(!strncmp(line, "ETH_HFARR", 9)){
3388 mergefile("ETH_HFARR",fh);
3389 } else if(!strncmp(line, "ETH_HF", 6)){
3390 mergefile("ETH_HF",fh);
3391 } else if(!strncmp(line, "ETH_ETTARR", 10)){
3392 mergefile("ETH_ETTARR",fh);
3393 } else if(!strncmp(line, "ETH_ETT", 7)){
3394 mergefile("ETH_ETT",fh);
3395 } else if(!strncmp(line, "ETH_FT", 6)){
3396 mergefile("ETH_FT",fh);
3397 } else if(!strncmp(line, "ETH_HANDOFF", 11)){
3398 mergefile("ETH_HANDOFF",fh);
3404 printf("%s was successfully compiled\n", ifname);
3411 remove("ETH_HFARR");
3413 remove("ETH_ETTARR");
3416 remove("ETH_HANDOFF");