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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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, ...)
110 va_start(args, format);
111 vfprintf (stderr, format, args);
115 va_start(args, format);
116 vfprintf (fh, format, args);
121 typedef struct _pointer_item_t {
122 struct _pointer_item_t *next;
126 #define BI_CASE 0x00000001
127 #define BI_CASE_DEFAULT 0x00000002
128 #define BI_IN 0x00000004
129 #define BI_OUT 0x00000008
130 #define BI_SIZE_IS 0x00000010
131 #define BI_LENGTH_IS 0x00000020
132 #define BI_POINTER 0x00000040
133 #define BI_BITMAP8 0x00000100
134 #define BI_BITMAP32 0x00000200
135 #define BI_SWITCH_TYPE 0x00000400
136 typedef struct _bracket_item_t {
139 pointer_item_t *pointer_list;
143 typedef struct _no_emit_item_t {
144 struct _no_emit_item_t *next;
147 static no_emit_item_t *no_emit_list=NULL;
149 typedef struct _hf_rename_item_t {
150 struct _hf_rename_item_t *next;
151 int refcount; /* number of times this rename has been referenced */
155 static hf_rename_item_t *hf_rename_list=NULL;
157 typedef struct _enum_list_t {
158 struct _enum_list_t *next;
163 typedef struct _token_item_t {
164 struct _token_item_t *next;
167 static token_item_t *token_list=NULL;
168 static token_item_t *last_token_item=NULL;
170 typedef struct _type_item_t {
171 struct _type_item_t *next;
180 static type_item_t *type_list=NULL;
182 typedef struct _union_tag_size_item_t {
183 struct _union_tag_size_item_t *next;
186 } union_tag_size_item_t;
187 static union_tag_size_item_t *union_tag_size_list=NULL;
189 typedef struct _hf_field_item_t {
190 struct _hf_field_item_t *next;
194 static hf_field_item_t *hf_field_list=NULL;
196 typedef struct _dissector_param_value_t {
197 struct _dissector_param_value_t *next;
200 } dissector_param_value_t;
201 static dissector_param_value_t *dissector_param_list=NULL;
203 static type_item_t *find_type(char *name);
204 static int Exit(int code);
207 register_dissector_param_value(char *name, char *value)
209 dissector_param_value_t *dpv;
210 dpv=malloc(sizeof(dissector_param_value_t));
211 dpv->next=dissector_param_list;
212 dissector_param_list=dpv;
213 dpv->name=strdup(name);
214 dpv->value=strdup(value);
218 find_dissector_param_value(char *name)
220 dissector_param_value_t *dpv;
221 for(dpv=dissector_param_list;dpv;dpv=dpv->next){
222 if(!strcmp(name,dpv->name)){
229 static pointer_item_t *
230 prepend_pointer_list(pointer_item_t *ptrs, int num_pointers)
236 if(num_pointers)num_pointers--;
240 while(num_pointers--){
241 pi=malloc(sizeof(pointer_item_t));
243 pi->type=pointer_default;
252 ptr_to_define(char *pointer_type)
254 if(!strcmp(pointer_type, "unique")){
255 return "NDR_POINTER_UNIQUE";
256 } else if(!strcmp(pointer_type, "ref")){
257 return "NDR_POINTER_REF";
258 } else if(!strcmp(pointer_type, "ptr")){
259 return "NDR_POINTER_PTR";
262 fprintf(stderr, "prt_to_define, weirdo pointer :%s\n", pointer_type);
267 get_union_tag_size(char *name)
269 union_tag_size_item_t *utsi;
270 for(utsi=union_tag_size_list;utsi;utsi=utsi->next){
271 if(!strcmp(name, utsi->name)){
275 fprintf(stderr, "ERROR: size of tag for union:%s is not known\n", name);
276 fprintf(stderr, " use the UNION_TAG_SIZE directive to specify it in teh conformance file\n");
281 /* this function will add an entry to the hf_rename list */
283 register_hf_rename(char *old_name, char *new_name)
285 hf_rename_item_t *new_item;
286 new_item=malloc(sizeof(hf_rename_item_t));
287 new_item->next=hf_rename_list;
288 hf_rename_list=new_item;
289 new_item->refcount=0;
290 new_item->old_name=strdup(old_name);
291 new_item->new_name=strdup(new_name);
294 /* this function checks that all hf_rename fields have actually been referenced
295 if not out conformance file is stale
298 check_hf_rename_refcount(void)
300 hf_rename_item_t *hri;
302 /* dont generate code for renamed hf fields just return the new name*/
303 for(hri=hf_rename_list;hri;hri=hri->next){
305 fprintf(stderr, "ERROR: the hf_rename field:%s was never referenced. it is likely the conformance file is stale\n", hri->old_name);
311 static hf_field_item_t *
312 find_hf_field(char *name)
314 hf_field_item_t *hfi;
316 for(hfi=hf_field_list;hfi;hfi=hfi->next){
317 if(!strcmp(hfi->name, name)){
322 fprintf(stderr, "find_hf_field: unknown hf_field:%s\n",name);
330 /* this function will create the code required for a hf field.
331 it MIGHT rename the field so a user MUST use the name returned
333 for fields that are to be renamed no code is generated
336 register_hf_field(char *hf_name, char *title, char *filter_name, char *ft_type, char *base_type, char *valsstring, char *mask, char *blurb)
338 hf_field_item_t *hfi;
339 hf_rename_item_t *hri;
341 /* dont generate code for renamed hf fields just return the new name*/
342 for(hri=hf_rename_list;hri;hri=hri->next){
343 if(!strcmp(hf_name, hri->old_name)){
344 hfi=find_hf_field(hri->new_name);
345 if(strcmp(ft_type, hfi->ft_type)){
346 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);
350 return hri->new_name;
354 hfi=malloc(sizeof(hf_field_item_t));
355 hfi->next=hf_field_list;
357 hfi->name=strdup(hf_name);
358 hfi->ft_type=strdup(ft_type);
360 FPRINTF(eth_hf, "static int %s = -1;\n", hf_name);
361 FPRINTF(eth_hfarr, " { &%s,\n", hf_name);
362 FPRINTF(eth_hfarr, " { \"%s\", \"%s\", %s, %s,\n", title, filter_name, ft_type, base_type);
363 FPRINTF(eth_hfarr, " %s, %s,\n", valsstring, mask);
364 if (strlen(blurb) > 0)
365 FPRINTF(eth_hfarr, " \"%s\", HFILL }},\n", blurb);
367 FPRINTF(eth_hfarr, " NULL, HFILL }},\n");
368 FPRINTF(eth_hfarr, "\n");
373 /* this function will parse the no emit list and decide whether code should
374 be generated for this dissector or if we should only register the type.
377 check_if_to_emit(char *name)
381 for(nel=no_emit_list;nel;nel=nel->next){
382 if(!strcmp(name, nel->name)){
383 FPRINTF(NULL, "SKIPPED emitting of %s\n",name);
392 prune_keywords(char *name)
396 for(ti=token_list;ti;ti=ti->next){
400 if(!strcmp(ti->next->str, name)){
401 if(!strcmp(ti->next->next->str, ",")){
402 ti->next=ti->next->next->next;
404 ti->next=ti->next->next;
412 rename_tokens(char *old_name, char *new_name)
416 for(ti=token_list;ti;ti=ti->next){
417 if(!strcmp(ti->str, old_name)){
418 ti->str=strdup(new_name);
424 prune_keyword_parameters(char *name)
426 token_item_t *ti, *tmpti;
428 for(ti=token_list;ti;ti=ti->next){
429 if(!strcmp(ti->str, name)){
430 if(!strcmp(ti->next->str, "(")){
433 if(!strcmp(tmpti->str, ")")){
434 ti->next=tmpti->next;
444 /* this function will parse a bracket item
446 it will return the token of the next item following the ']'
448 static token_item_t *
449 parsebrackets(token_item_t *ti, bracket_item_t **bracket){
451 type_item_t *type_item;
453 if(strcmp(ti->str, "[")){
454 fprintf(stderr, "ERROR: parsebrackets first token is not '['\n");
459 br=malloc(sizeof(bracket_item_t));
463 br->pointer_list=NULL;
466 if( !strcmp(ti->str, "{")
467 ||!strcmp(ti->str, "}")){
468 fprintf(stderr, "ERROR: parsebrackets '{' '}' inside bracket item\n");
472 if(!strcmp(ti->str, "[")){
473 fprintf(stderr, "ERROR: parsebrackets '[' inside bracket item\n");
478 if(!strcmp(ti->str, "]")){
479 /* check for [ ... ] [ ...] */
482 if(!strcmp(ti->str, "[")){
489 /* just ignore all ',' */
490 if(!strcmp(ti->str, ",")){
495 /* case '(' tag ')' */
496 if(!strcmp(ti->str, "case")){
500 if(strcmp(ti->str, "(")){
501 fprintf(stderr, "ERROR: parsebrackets case not followed by '('\n");
507 br->case_name=ti->str;
510 if(strcmp(ti->str, ")")){
511 fprintf(stderr, "ERROR: parsebrackets case does not end with ')'\n");
519 if(!strcmp(ti->str, "default")){
521 br->flags|=BI_CASE_DEFAULT;
522 br->case_name="default";
529 if(!strcmp(ti->str, "in")){
536 if(!strcmp(ti->str, "out")){
542 /* public : we dont care about this one */
543 if(!strcmp(ti->str, "public")){
548 /* gensize : we dont care about this one */
549 if(!strcmp(ti->str, "gensize")){
555 if(!strcmp(ti->str, "switch_is")){
556 fprintf(stderr, "WARNING: parsebrackets can not handle switch_is properly yet so we can not verify the tag size\n");
558 if(!strcmp(ti->str, ")")){
568 if(!strcmp(ti->str, "subcontext")){
570 if(!strcmp(ti->str, ")")){
579 /* value we dont care about this one so just skip it */
580 if(!strcmp(ti->str, "value")){
583 if( strcmp(ti->str, "(") ){
584 fprintf(stderr, "WARNING: parsebrackets value was not followed by '('\n");
589 if(!strcmp(ti->str, "(")){
594 if(!strcmp(ti->str, ")")){
607 /* range we dont care about this one so just skip it */
608 if(!strcmp(ti->str, "range")){
611 if( strcmp(ti->str, "(") ){
612 fprintf(stderr, "WARNING: parsebrackets range was not followed by '('\n");
617 if(!strcmp(ti->str, "(")){
622 if(!strcmp(ti->str, ")")){
635 /* flag we dont care about this one so just skip it */
636 if(!strcmp(ti->str, "flag")){
639 if( strcmp(ti->str, "(") ){
640 fprintf(stderr, "WARNING: parsebrackets flag was not followed by '('\n");
645 if(!strcmp(ti->str, "(")){
650 if(!strcmp(ti->str, ")")){
664 if(!strcmp(ti->str, "switch_type")){
665 br->flags|=BI_SWITCH_TYPE;
668 if(strcmp(ti->str, "(")){
669 fprintf(stderr, "WARNING: parsebrackets switch_type was not followed by '('\n");
674 type_item=find_type(ti->str);
676 fprintf(stderr, "ERROR : parsebrackets switch_type unknown type %s\n",ti->str);
679 br->union_tag_size=type_item->alignment;
682 if(strcmp(ti->str, ")")){
683 fprintf(stderr, "WARNING: parsebrackets switch_type did not end with ')'\n");
692 if(!strcmp(ti->str, "size_is")){
693 br->flags|=BI_SIZE_IS;
699 if(!strcmp(ti->str, "length_is")){
700 br->flags|=BI_LENGTH_IS;
706 if(!strcmp(ti->str, "bitmap8bit")){
707 br->flags|=BI_BITMAP8;
713 if(!strcmp(ti->str, "bitmap32bit")){
714 br->flags|=BI_BITMAP32;
719 /* ref, unique or ptr */
720 if(!strcmp(ti->str, "ref")
721 || !strcmp(ti->str, "unique")
722 || !strcmp(ti->str, "ptr")){
723 pointer_item_t *newpi;
725 br->flags|=BI_POINTER;
726 newpi=malloc(sizeof(pointer_item_t));
729 newpi->next=br->pointer_list;
730 br->pointer_list=newpi;
735 fprintf(stderr, "ERROR: parsebrackets should not be reached unknown tag:%s\n", ti->str);
742 /* this function will register a new type learnt from the IDL file
745 register_new_type(char *name, char *dissectorname, char *ft_type, char *base_type, char *mask, char *valsstring, int alignment){
746 type_item_t *new_type;
748 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);
750 new_type=malloc(sizeof(type_item_t));
751 new_type->next=type_list;
752 new_type->name=strdup(name);
753 new_type->dissector=strdup(dissectorname);
754 new_type->ft_type=strdup(ft_type);
755 new_type->base_type=strdup(base_type);
756 new_type->mask=strdup(mask);
757 new_type->vals=strdup(valsstring);
758 new_type->alignment=alignment;
765 /* this function will print the remaining content of the token list
767 static void printtokenlist(int count)
770 fprintf(stderr, "TOKENLIST:\n");
771 for(ti=token_list;ti&&count;count--,ti=ti->next){
772 fprintf(stderr, "Token \"%s\"\n",ti->str);
775 fprintf(stderr, " ...\n");
780 /* this function will parse the header and pick up the fields
781 * we are interested in.
782 * the header is supposed to start at the very first token and look like
783 * [ <fields> ] inteface <ifname> {
785 * we are interested in the fields:
790 * this function will also remove the header from the token list
792 static void parseheader(void)
794 char filter_name[256];
801 fprintf(stderr, "ERROR: no tokens\n");
805 /* first token must be '[' */
806 if( strcmp(ti->str, "[") ){
807 fprintf(stderr, "ERROR: first token is not '['\n");
811 for(ti=token_list;ti;ti=ti->next){
812 if( !strcmp(ti->str, "[")){
816 if( !strcmp(ti->str, "]")){
824 if( !strcmp(ti->str, "uuid")){
825 uuid=ti->next->next->str;
826 FPRINTF(NULL,"UUID:%s\n",uuid);
828 if( !strcmp(ti->str, "version")){
829 version=ti->next->next->str;
830 FPRINTF(NULL,"VERSION:%s\n",version);
832 if( !strcmp(ti->str, "pointer_default")){
833 if(!strcmp(ti->next->next->str, "unique")){
834 pointer_default="unique";
835 } else if(!strcmp(ti->next->next->str, "ptr")){
836 pointer_default="ptr";
838 fprintf(stderr, "ERROR: unknown pointer type\n");
841 FPRINTF(NULL,"POINTER_DEFAULT:%s\n",pointer_default);
846 fprintf(stderr, "ERROR: ran outof tokens inside header\n");
850 if(strcmp(token_list->str, "interface")){
851 fprintf(stderr, "ERROR: interface not found\n");
854 token_list=token_list->next;
856 ifname=token_list->str;
857 token_list=token_list->next;
858 FPRINTF(NULL,"Interface:%s\n",ifname);
861 sprintf(hf_status, "hf_%s_opnum", ifname);
862 sprintf(filter_name, "%s.opnum", ifname);
863 register_hf_field(hf_status, "Operation", filter_name, "FT_UINT16", "BASE_DEC", "NULL", "0", "");
866 sprintf(hf_status, "hf_%s_rc", ifname);
867 sprintf(filter_name, "%s.rc", ifname);
868 register_hf_field(hf_status, "Return code", filter_name, "FT_UINT32", "BASE_HEX", "VALS(NT_errors)", "0", "");
870 FPRINTF(eth_ett, "static gint ett_%s = -1;\n", ifname);
871 FPRINTF(eth_ettarr, " &ett_%s,\n", ifname);
873 /* the body must start with { */
874 if(strcmp(token_list->str, "{")){
875 fprintf(stderr, "ERROR: body does not start with '{'\n");
879 /* skip the initial '{' */
880 token_list=token_list->next;
883 fprintf(stderr, "ERROR: no uuid found\n");
886 FPRINTF(eth_code,"static e_uuid_t uuid_dcerpc_%s = {\n", ifname);
887 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]);
888 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]);
889 FPRINTF(eth_code,"};\n");
890 FPRINTF(eth_code,"\n");
892 sscanf(version, "%d.%d", &major, &minor);
893 FPRINTF(eth_code,"static guint16 ver_%s = %d;\n", ifname, major);
894 FPRINTF(eth_code,"\n");
896 FPRINTF(eth_handoff, " dcerpc_init_uuid(proto_%s, ett_%s,\n", ifname, ifname);
897 FPRINTF(eth_handoff, " &uuid_dcerpc_%s, ver_%s,\n", ifname, ifname);
898 FPRINTF(eth_handoff, " function_dissectors, hf_%s_opnum);\n", ifname);
903 /* this helper function is called by the tokenizer and will just append the
904 current token to the linked list
906 static void pushtoken(char *token)
908 token_item_t *new_token_item;
909 new_token_item=malloc(sizeof(token_item_t));
910 new_token_item->next=NULL;
911 new_token_item->str=token;
913 token_list=new_token_item;
915 last_token_item->next=new_token_item;
917 last_token_item=new_token_item;
920 /* this function reads the idl file and translates it into tokens.
921 the tokens are stored in a linked list token_list of type token_item_t
923 static void tokenize(FILE *fh)
926 int fullinecomment=0;
938 /* full line comment */
940 if( (ch=='\n')||(ch=='\r') ){
946 if( (ch=='#')&&(linepos==0) ){
952 if(normalcomment==0){
981 pushtoken(strdup(qs));
984 qs[qspos++]=(char)ch;
1003 pushtoken(strdup(token));
1006 /*printf("line %d [%s]\n",lineno,line);*/
1015 pushtoken(strdup(token));
1029 pushtoken(strdup(token));
1033 pushtoken(strdup(token));
1040 token[tokenpos++]=(char)ch;
1041 line[linepos++]=(char)ch;
1049 static type_item_t *
1050 find_type(char *name)
1052 type_item_t *tmptype;
1053 for(tmptype=type_list;tmptype;tmptype=tmptype->next){
1054 if(!strcmp(tmptype->name, name)){
1058 /* autogenerate built in types */
1060 char dissectorname[256];
1061 if(!strcmp(name,"uint16")){
1062 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1063 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1064 FPRINTF(eth_code, "\n");
1065 FPRINTF(eth_code, "static int\n");
1066 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);
1067 FPRINTF(eth_code, "{\n");
1068 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1069 FPRINTF(eth_code, " return offset;\n");
1070 FPRINTF(eth_code, "}\n");
1071 FPRINTF(eth_code, "\n");
1072 tmptype=register_new_type("uint16", dissectorname, "FT_UINT16", "BASE_DEC", "0", "NULL", 2);
1073 } else if(!strcmp(name,"int16")){
1074 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1075 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1076 FPRINTF(eth_code, "\n");
1077 FPRINTF(eth_code, "static int\n");
1078 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);
1079 FPRINTF(eth_code, "{\n");
1080 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1081 FPRINTF(eth_code, " return offset;\n");
1082 FPRINTF(eth_code, "}\n");
1083 FPRINTF(eth_code, "\n");
1084 tmptype=register_new_type("int16", dissectorname, "FT_INT16", "BASE_DEC", "0", "NULL", 2);
1085 } else if(!strcmp(name,"uint32")){
1086 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1087 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1088 FPRINTF(eth_code, "\n");
1089 FPRINTF(eth_code, "static int\n");
1090 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);
1091 FPRINTF(eth_code, "{\n");
1092 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1093 FPRINTF(eth_code, " return offset;\n");
1094 FPRINTF(eth_code, "}\n");
1095 FPRINTF(eth_code, "\n");
1096 tmptype=register_new_type("uint32", dissectorname, "FT_UINT32", "BASE_DEC", "0", "NULL", 4);
1097 } else if( (!strcmp(name,"int32"))
1098 || (!strcmp(name,"long")) ){
1099 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1100 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1101 FPRINTF(eth_code, "\n");
1102 FPRINTF(eth_code, "static int\n");
1103 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);
1104 FPRINTF(eth_code, "{\n");
1105 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1106 FPRINTF(eth_code, " return offset;\n");
1107 FPRINTF(eth_code, "}\n");
1108 FPRINTF(eth_code, "\n");
1109 if (!strcmp(name,"int32"))
1110 tmptype=register_new_type("int32", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
1112 tmptype=register_new_type("long", dissectorname, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
1113 } else if( (!strcmp(name,"uint8")) ){
1114 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1115 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1116 FPRINTF(eth_code, "\n");
1117 FPRINTF(eth_code, "static int\n");
1118 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);
1119 FPRINTF(eth_code, "{\n");
1120 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1121 FPRINTF(eth_code, " return offset;\n");
1122 FPRINTF(eth_code, "}\n");
1123 FPRINTF(eth_code, "\n");
1124 tmptype=register_new_type("uint8", dissectorname, "FT_UINT8", "BASE_DEC", "0", "NULL", 1);
1125 } else if( (!strcmp(name,"int8"))
1126 || (!strcmp(name, "char")) ){
1127 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1128 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1129 FPRINTF(eth_code, "\n");
1130 FPRINTF(eth_code, "static int\n");
1131 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);
1132 FPRINTF(eth_code, "{\n");
1133 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1134 FPRINTF(eth_code, " return offset;\n");
1135 FPRINTF(eth_code, "}\n");
1136 FPRINTF(eth_code, "\n");
1137 if (!strcmp(name,"int8"))
1138 tmptype=register_new_type("int8", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1140 tmptype=register_new_type("char", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1141 } else if(!strcmp(name,"bool8")){
1142 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1143 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1144 FPRINTF(eth_code, "\n");
1145 FPRINTF(eth_code, "static int\n");
1146 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);
1147 FPRINTF(eth_code, "{\n");
1148 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1149 FPRINTF(eth_code, " return offset;\n");
1150 FPRINTF(eth_code, "}\n");
1151 FPRINTF(eth_code, "\n");
1152 tmptype=register_new_type("bool8", dissectorname, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1153 } else if(!strcmp(name,"unistr")){
1154 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1155 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1156 FPRINTF(eth_code, "\n");
1157 FPRINTF(eth_code, "static int\n");
1158 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);
1159 FPRINTF(eth_code, "{\n");
1160 FPRINTF(eth_code, " offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, 2, hf_index, FALSE, NULL);\n");
1161 FPRINTF(eth_code, " return offset;\n");
1162 FPRINTF(eth_code, "}\n");
1163 FPRINTF(eth_code, "\n");
1164 tmptype=register_new_type("unistr", dissectorname, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1165 } else if(!strcmp(name,"ascstr")){
1166 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1167 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1168 FPRINTF(eth_code, "\n");
1169 FPRINTF(eth_code, "static int\n");
1170 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);
1171 FPRINTF(eth_code, "{\n");
1172 FPRINTF(eth_code, " offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, drep, 1, hf_index, FALSE, NULL);\n");
1173 FPRINTF(eth_code, " return offset;\n");
1174 FPRINTF(eth_code, "}\n");
1175 FPRINTF(eth_code, "\n");
1176 tmptype=register_new_type("ascstr", dissectorname, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1177 } else if(!strcmp(name,"GUID")
1178 ||!strcmp(name,"uuid_t")){
1179 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1180 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1181 FPRINTF(eth_code, "\n");
1182 FPRINTF(eth_code, "static int\n");
1183 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);
1184 FPRINTF(eth_code, "{\n");
1185 FPRINTF(eth_code, " offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1186 FPRINTF(eth_code, " return offset;\n");
1187 FPRINTF(eth_code, "}\n");
1188 FPRINTF(eth_code, "\n");
1189 tmptype=register_new_type(name, dissectorname, "FT_GUID", "BASE_NONE", "0", "NULL", 4);
1190 } else if(!strcmp(name,"policy_handle")){
1191 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1192 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1193 FPRINTF(eth_code, "\n");
1194 FPRINTF(eth_code, "static e_ctx_hnd policy_hnd;\n");
1195 FPRINTF(eth_code, "static proto_item *hnd_item;\n");
1196 FPRINTF(eth_code, "\n");
1197 FPRINTF(eth_code, "static int\n");
1198 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
1199 FPRINTF(eth_code, "{\n");
1200 FPRINTF(eth_code, " offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, drep,\n");
1201 FPRINTF(eth_code, " hf_index, &policy_hnd, &hnd_item,\n");
1202 FPRINTF(eth_code, " param&0x01, param&0x02);\n");
1204 FPRINTF(eth_code, " return offset;\n");
1205 FPRINTF(eth_code, "}\n");
1206 FPRINTF(eth_code, "\n");
1207 tmptype=register_new_type("policy_handle", dissectorname, "FT_BYTES", "BASE_NONE", "0", "NULL", 4);
1208 } else if(!strcmp(name,"NTTIME")){
1209 /* 8 bytes, aligned to 4 bytes */
1210 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1211 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1212 FPRINTF(eth_code, "\n");
1213 FPRINTF(eth_code, "static int\n");
1214 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);
1215 FPRINTF(eth_code, "{\n");
1216 FPRINTF(eth_code, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
1218 FPRINTF(eth_code, "\n");
1219 FPRINTF(eth_code, " return offset;\n");
1220 FPRINTF(eth_code, "}\n");
1221 FPRINTF(eth_code, "\n");
1222 tmptype=register_new_type("NTTIME", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1223 } else if(!strcmp(name,"NTTIME_hyper")){
1224 /* 8 bytes, aligned to 8 bytes */
1225 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1226 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1227 FPRINTF(eth_code, "\n");
1228 FPRINTF(eth_code, "static int\n");
1229 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);
1230 FPRINTF(eth_code, "{\n");
1231 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1232 FPRINTF(eth_code, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
1234 FPRINTF(eth_code, "\n");
1235 FPRINTF(eth_code, " return offset;\n");
1236 FPRINTF(eth_code, "}\n");
1237 FPRINTF(eth_code, "\n");
1238 tmptype=register_new_type("NTTIME_hyper", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1239 } else if(!strcmp(name,"NTTIME_1sec")){
1240 /* 8 bytes, aligned to 8 bytes */
1241 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1242 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1243 FPRINTF(eth_code, "\n");
1244 FPRINTF(eth_code, "static int\n");
1245 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);
1246 FPRINTF(eth_code, "{\n");
1247 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1248 FPRINTF(eth_code, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, drep, hf_index);\n");
1250 FPRINTF(eth_code, "\n");
1251 FPRINTF(eth_code, " return offset;\n");
1252 FPRINTF(eth_code, "}\n");
1253 FPRINTF(eth_code, "\n");
1254 tmptype=register_new_type("NTTIME_1sec", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1255 } else if(!strcmp(name,"udlong")){
1256 /* 8 bytes, aligned to 4 bytes */
1257 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1258 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1259 FPRINTF(eth_code, "\n");
1260 FPRINTF(eth_code, "static int\n");
1261 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);
1262 FPRINTF(eth_code, "{\n");
1263 FPRINTF(eth_code, "\n");
1264 FPRINTF(eth_code, " offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1265 FPRINTF(eth_code, "\n");
1266 FPRINTF(eth_code, " return offset;\n");
1267 FPRINTF(eth_code, "}\n");
1268 FPRINTF(eth_code, "\n");
1269 tmptype=register_new_type("udlong", dissectorname, "FT_UINT64", "BASE_DEC", "0", "NULL", 4);
1270 } else if(!strcmp(name,"dlong")){
1271 /* 8 bytes, aligned to 4 bytes */
1272 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1273 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1274 FPRINTF(eth_code, "\n");
1275 FPRINTF(eth_code, "static int\n");
1276 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);
1277 FPRINTF(eth_code, "{\n");
1278 FPRINTF(eth_code, "\n");
1279 FPRINTF(eth_code, " offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1280 FPRINTF(eth_code, "\n");
1281 FPRINTF(eth_code, " return offset;\n");
1282 FPRINTF(eth_code, "}\n");
1283 FPRINTF(eth_code, "\n");
1284 tmptype=register_new_type("dlong", dissectorname, "FT_INT64", "BASE_DEC", "0", "NULL", 4);
1285 } else if(!strcmp(name,"uint64")){
1286 /* 8 bytes, aligned to 8 bytes */
1287 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1288 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1289 FPRINTF(eth_code, "\n");
1290 FPRINTF(eth_code, "static int\n");
1291 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);
1292 FPRINTF(eth_code, "{\n");
1293 FPRINTF(eth_code, " \n");
1294 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1295 FPRINTF(eth_code, " offset=dissect_ndr_uint64(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1296 FPRINTF(eth_code, "\n");
1297 FPRINTF(eth_code, " return offset;\n");
1298 FPRINTF(eth_code, "}\n");
1299 FPRINTF(eth_code, "\n");
1300 tmptype=register_new_type("uint64", dissectorname, "FT_UINT64", "BASE_DEC", "0", "NULL", 8);
1301 } else if(!strcmp(name,"time_t")){
1302 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1303 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1304 FPRINTF(eth_code, "\n");
1305 FPRINTF(eth_code, "static int\n");
1306 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);
1307 FPRINTF(eth_code, "{\n");
1308 FPRINTF(eth_code, " \n");
1309 FPRINTF(eth_code, " offset=dissect_ndr_time_t(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1310 FPRINTF(eth_code, "\n");
1311 FPRINTF(eth_code, " return offset;\n");
1312 FPRINTF(eth_code, "}\n");
1313 FPRINTF(eth_code, "\n");
1314 tmptype=register_new_type("time_t", dissectorname, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1315 } else if(!strcmp(name,"SID")){
1316 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1317 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1318 FPRINTF(eth_code, "\n");
1319 FPRINTF(eth_code, "static int\n");
1320 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep, int hf_index, guint32 param)\n", dissectorname);
1321 FPRINTF(eth_code, "{\n");
1322 FPRINTF(eth_code, " dcerpc_info *di = (dcerpc_info *)pinfo->private_data;\n");
1323 FPRINTF(eth_code, "\n");
1324 FPRINTF(eth_code, " di->hf_index=hf_index;\n");
1326 FPRINTF(eth_code, " offset=dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, drep, param);\n");
1327 FPRINTF(eth_code, " return offset;\n");
1328 FPRINTF(eth_code, "}\n");
1329 FPRINTF(eth_code, "\n");
1330 tmptype=register_new_type("SID", dissectorname, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1331 } else if(!strcmp(name,"WERROR")){
1332 sprintf(dissectorname, "%s_dissect_%s", ifname, name);
1333 FPRINTF(NULL,"\nAutogenerating built-in type:%s\n------------\n",name);
1334 FPRINTF(eth_code, "\n");
1335 FPRINTF(eth_code, "static int\n");
1336 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);
1337 FPRINTF(eth_code, "{\n");
1338 FPRINTF(eth_code, " \n");
1339 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
1340 FPRINTF(eth_code, "\n");
1341 FPRINTF(eth_code, " return offset;\n");
1342 FPRINTF(eth_code, "}\n");
1343 FPRINTF(eth_code, "\n");
1344 tmptype=register_new_type("WERROR", dissectorname, "FT_UINT32", "BASE_DEC", "0", "VALS(NT_errors)", 4);
1352 /* this function will skip past an entire declare ... ; statement */
1353 static void skipdeclare(void)
1357 /* first must be the keyword const */
1359 if(strcmp(ti->str, "declare")){
1360 fprintf(stderr, "ERROR: skipdeclare first token is not 'declare'\n");
1363 while(strcmp(ti->str, ";")){
1371 /* this function will parse a
1373 and generate the appropriate code
1374 const must be followed by a suitable keyword [uint16|uint32|...]
1375 the const will later be removed from the token list
1376 the function assumes that the const is the first object in the token_list
1378 static void parseconst(void)
1383 /* first must be the keyword const */
1385 if(strcmp(ti->str, "const")){
1386 fprintf(stderr, "ERROR: const first token is not 'const'\n");
1391 /* just skip second token */
1394 /* third is a variable and not a type */
1395 if(find_type(ti->str)){
1396 fprintf(stderr, "ERROR: const, not a variable name:%s\n", ti->str);
1403 if(strcmp(ti->str, "=")){
1404 fprintf(stderr, "ERROR: const fourth token is not '='\n");
1409 /* fifth is the value */
1414 if(strcmp(ti->str, ";")){
1415 fprintf(stderr, "ERROR: const sixth token is not ';'\n");
1420 FPRINTF(NULL,"\nCONST:%s\n-------\n",name);
1422 FPRINTF(eth_hdr, "#define %s %s\n", name, value);
1424 FPRINTF(NULL,"\n----------\nEND CONST:%s\n",name);
1429 /* this function will parse a
1431 construct and generate the appropriate code.
1432 the typedef will be removed from the token_list once it has been processed
1433 the function assumes that the typedef is the first object in the token_list
1434 the function will be called twice, once with pass=0 and once with pass=1
1435 which controls whether subdissectors are to be generated or whether the
1436 struct dissector itself is to be generated
1438 static void parsetypedefstruct(int pass)
1440 token_item_t *ti, *tmpti;
1442 char dissectorname[256];
1443 char tmpstr[256], *ptmpstr;
1444 int level, num_pointers;
1445 static int alignment;
1446 type_item_t *type_item;
1448 bracket_item_t *bi=NULL;
1452 int fixed_array_size;
1453 int is_array_of_pointers;
1456 if(strcmp(ti->str, "typedef")){
1457 fprintf(stderr, "ERROR: typedefstruct first token is not 'typedef'\n");
1462 if(!strcmp(ti->str, "[")){
1463 ti=parsebrackets(ti, &bi);
1465 /* check that we know how to handle the bracket thing */
1468 fprintf(stderr, "ERROR: typedefstruct unknown bracket flags encountered : 0x%08x\n",bi->flags);
1473 if(strcmp(ti->str, "struct")){
1474 fprintf(stderr, "ERROR: typedefstruct second token is not 'struct'\n");
1479 if(strcmp(ti->str, "{")){
1480 fprintf(stderr, "ERROR: typedefstruct third token is not '{'\n");
1485 /* search forward until the '}' so we can find the name of the struct */
1486 for(tmpti=ti,level=0;tmpti;tmpti=tmpti->next){
1487 if(!strcmp(tmpti->str, "{")){
1491 if(!strcmp(tmpti->str, "}")){
1499 if(!tmpti || !tmpti->next){
1500 fprintf(stderr, "ERROR: typedefstruct missing matching '}'\n");
1504 struct_name=tmpti->next->str;
1505 sprintf(dissectorname, "%s_dissect_%s", ifname, struct_name);
1507 FPRINTF(NULL,"\nSTRUCT:%s pass:%d\n-------\n",struct_name,pass);
1509 if(!check_if_to_emit(dissectorname)){
1510 FPRINTF(NULL,"NOEMIT Skipping this struct dissector.\n");
1512 goto typedef_struct_finished;
1515 /* this is pass 0 so reset alignment to zero and update as items are
1516 processed. we need alignment when pass 1 is run.
1517 set alignment initially to 1 so we dont fail for empty structs
1522 /* pass 1 generate header for the struct dissector */
1524 FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, struct_name);
1525 FPRINTF(eth_ettarr, " &ett_%s_%s,\n", ifname, struct_name);
1526 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);
1527 FPRINTF(eth_code, "\n");
1528 FPRINTF(eth_code, "int\n");
1529 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);
1530 FPRINTF(eth_code, "{\n");
1531 FPRINTF(eth_code, " proto_item *item=NULL;\n");
1532 FPRINTF(eth_code, " proto_tree *tree=NULL;\n");
1533 FPRINTF(eth_code, " int old_offset;\n");
1534 FPRINTF(eth_code, "\n");
1539 FPRINTF(eth_code, " ALIGN_TO_2_BYTES;\n");
1540 FPRINTF(eth_code, "\n");
1543 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
1544 FPRINTF(eth_code, "\n");
1547 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
1548 FPRINTF(eth_code, "\n");
1551 fprintf(stderr, "ERROR: can not handle alignment:%d\n",alignment);
1554 FPRINTF(eth_code, " old_offset=offset;\n");
1555 FPRINTF(eth_code, " if(parent_tree){\n");
1556 FPRINTF(eth_code, " item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);\n");
1557 FPRINTF(eth_code, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, struct_name);
1558 FPRINTF(eth_code, " }\n");
1559 FPRINTF(eth_code, "\n");
1562 /* scan the struct and create all subdissectors */
1565 if(!strcmp(ti->str, "{")){
1570 if(!strcmp(ti->str, "}")){
1578 if(!strcmp(ti->str, "[")){
1579 ti=parsebrackets(ti, &bi);
1583 /* check that we know how to handle the bracket thing */
1585 if(bi->flags&(~(BI_SIZE_IS|BI_LENGTH_IS|BI_POINTER))){
1586 fprintf(stderr, "ERROR: typedefstruct unknown bracket flags encountered : 0x%08x\n",bi->flags);
1591 /* handle the type, verify that we KNOW this type */
1592 type_item=find_type(ti->str);
1594 fprintf(stderr, "ERROR : typedefstruct unknown type %s\n",ti->str);
1598 /* count the levels of pointers */
1599 for(num_pointers=0;!strcmp(ti->str, "*");ti=ti->next){
1601 /* poitners are aligned at 4 byte boundaries */
1606 /* now that we know how many real pointers there were we must
1607 prepend default pointers to the list so it has the right
1610 pi=prepend_pointer_list(bi?bi->pointer_list:NULL, num_pointers);
1611 /* keep track of alignment */
1612 if(alignment<type_item->alignment){
1613 alignment=type_item->alignment;
1619 /* see if it is a fixed array */
1621 is_array_of_pointers=0;
1622 if(!strcmp(ti->str, "[")){
1625 /* this might be a fixed array */
1628 fixed_array_size=atoi(ti->str);
1629 sprintf(fss, "%d", fixed_array_size);
1631 if(!strcmp("]", ti->str)){
1632 /* this is just a normal [] array */
1634 } else if(!strcmp("*", ti->str)){
1635 pi=prepend_pointer_list(pi, num_pointers+1);
1637 is_array_of_pointers=1;
1639 } else if(strcmp(fss, ti->str)){
1640 fprintf(stderr, "ERROR: typedefstruct (%s) fixed array size looks different to calculated one %s!=%s\n", struct_name, fss, ti->str);
1647 if(strcmp(ti->str, "]")){
1648 fprintf(stderr, "ERROR: typedefstruct fixed array does not end with ']' it ended with %s\n",ti->str);
1654 sprintf(hf_index, "hf_%s_%s_%s", ifname, struct_name, field_name);
1655 /* pass 0 generate subdissectors */
1657 char filter_name[256];
1660 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, struct_name, field_name);
1661 ptmpstr=strdup(tmpstr);
1663 if(check_if_to_emit(tmpstr)){
1664 sprintf(filter_name, "%s.%s.%s", ifname, struct_name, field_name);
1665 hf=register_hf_field(hf_index, field_name, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
1666 FPRINTF(eth_code, "static int\n");
1667 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
1668 FPRINTF(eth_code, "{\n");
1669 FPRINTF(eth_code, " guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
1670 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
1671 FPRINTF(eth_code, " return offset;\n");
1672 FPRINTF(eth_code, "}\n");
1673 FPRINTF(eth_code, "\n");
1675 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1678 if(is_array_of_pointers){
1679 pointer_type=pi->type;
1681 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1682 if(check_if_to_emit(tmpstr)){
1683 FPRINTF(eth_code, "static int\n");
1684 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1685 FPRINTF(eth_code, "{\n");
1686 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);
1687 FPRINTF(eth_code, " return offset;\n");
1688 FPRINTF(eth_code, "}\n");
1689 FPRINTF(eth_code, "\n");
1691 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1694 ptmpstr=strdup(tmpstr);
1695 } else if(fixed_array_size){
1696 sprintf(tmpstr, "fixedarray_%s", ptmpstr);
1697 if(check_if_to_emit(tmpstr)){
1698 FPRINTF(eth_code, "static int\n");
1699 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1700 FPRINTF(eth_code, "{\n");
1701 FPRINTF(eth_code, " int count=%d;\n",fixed_array_size);
1702 FPRINTF(eth_code, " while(count--){\n");
1703 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
1704 FPRINTF(eth_code, " }\n");
1705 FPRINTF(eth_code, "\n");
1706 FPRINTF(eth_code, " return offset;\n");
1707 FPRINTF(eth_code, "}\n");
1708 FPRINTF(eth_code, "\n");
1710 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1712 ptmpstr=strdup(tmpstr);
1715 /* handle switch_is */
1717 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
1721 sprintf(tmpstr, "ucarray_%s", ptmpstr);
1722 if(check_if_to_emit(tmpstr)){
1723 FPRINTF(eth_code, "static int\n");
1724 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1725 FPRINTF(eth_code, "{\n");
1726 FPRINTF(eth_code, " offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
1727 FPRINTF(eth_code, " return offset;\n");
1728 FPRINTF(eth_code, "}\n");
1729 FPRINTF(eth_code, "\n");
1731 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1733 ptmpstr=strdup(tmpstr);
1736 sprintf(tmpstr, "uvarray_%s", ptmpstr);
1737 if(check_if_to_emit(tmpstr)){
1738 FPRINTF(eth_code, "static int\n");
1739 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1740 FPRINTF(eth_code, "{\n");
1741 FPRINTF(eth_code, " offset=dissect_ndr_uvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
1742 FPRINTF(eth_code, " return offset;\n");
1743 FPRINTF(eth_code, "}\n");
1744 FPRINTF(eth_code, "\n");
1746 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1748 ptmpstr=strdup(tmpstr);
1750 case BI_SIZE_IS|BI_LENGTH_IS:
1751 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
1752 if(check_if_to_emit(tmpstr)){
1753 FPRINTF(eth_code, "static int\n");
1754 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1755 FPRINTF(eth_code, "{\n");
1756 FPRINTF(eth_code, " offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
1757 FPRINTF(eth_code, " return offset;\n");
1758 FPRINTF(eth_code, "}\n");
1759 FPRINTF(eth_code, "\n");
1761 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1763 ptmpstr=strdup(tmpstr);
1766 fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
1771 /* handle pointers */
1772 while(num_pointers--){
1773 pointer_type=pi->type;
1775 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1776 if(check_if_to_emit(tmpstr)){
1777 FPRINTF(eth_code, "static int\n");
1778 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
1779 FPRINTF(eth_code, "{\n");
1780 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);
1781 FPRINTF(eth_code, " return offset;\n");
1782 FPRINTF(eth_code, "}\n");
1783 FPRINTF(eth_code, "\n");
1785 FPRINTF(NULL,"NOEMIT Skipping this struct item :%s\n",tmpstr);
1788 ptmpstr=strdup(tmpstr);
1793 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, struct_name, field_name);
1794 ptmpstr=strdup(tmpstr);
1796 /* handle fixedsizearrays */
1797 if(is_array_of_pointers){
1798 pointer_type=pi->type;
1800 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1801 ptmpstr=strdup(tmpstr);
1802 } else if(fixed_array_size){
1803 sprintf(tmpstr, "fixedarray_%s", ptmpstr);
1804 ptmpstr=strdup(tmpstr);
1807 /* handle switch_is */
1809 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
1813 sprintf(tmpstr, "ucarray_%s", ptmpstr);
1814 ptmpstr=strdup(tmpstr);
1817 sprintf(tmpstr, "uvarray_%s", ptmpstr);
1818 ptmpstr=strdup(tmpstr);
1820 case BI_SIZE_IS|BI_LENGTH_IS:
1821 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
1822 ptmpstr=strdup(tmpstr);
1825 fprintf(stderr, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
1830 /* handle pointers */
1831 while(num_pointers--){
1832 pointer_type=pi->type;
1834 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
1835 ptmpstr=strdup(tmpstr);
1838 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
1839 FPRINTF(eth_code, "\n");
1842 if(strcmp(ti->str,";")){
1843 fprintf(stderr, "ERROR: field does not en with ';'\n");
1847 bi=NULL; /* clear bi before we start on the next field */
1851 FPRINTF(eth_code, " proto_item_set_len(item, offset-old_offset);\n");
1852 FPRINTF(eth_code, "\n");
1853 FPRINTF(eth_code, " return offset;\n");
1854 FPRINTF(eth_code, "}\n");
1855 register_new_type(struct_name, dissectorname, "FT_NONE", "BASE_NONE", "0", "NULL", alignment);
1859 typedef_struct_finished:
1860 FPRINTF(NULL,"\nEND STRUCT:%s pass:%d\n-------\n",struct_name,pass);
1862 /* only advance token_list for pass==1
1863 ti now points to the '}' token
1866 if(!ti || strcmp(ti->str,"}")){
1867 fprintf(stderr, "ERROR: struct does not end with '}'\n");
1872 /* just skip the name */
1875 if(!ti || strcmp(ti->str,";")){
1876 fprintf(stderr, "ERROR: struct does not end with ';'\n");
1885 /* this function will parse a
1887 construct and generate the appropriate code.
1888 the typedef will be removed from the token_list once it has been processed
1889 the function assumes that the typedef is the first object in the token_list
1890 the function will be called twice, once with pass=0 and once with pass=1
1891 which controls whether subdissectors are to be generated or whether the
1892 bitmap dissector itself is to be generated
1894 bitmaps are by default 32 bits
1896 static void parsetypedefbitmap(int pass)
1898 token_item_t *ti, *tmpti;
1900 char dissectorname[256], hf_bitname[256];
1904 bracket_item_t *bi=NULL;
1907 if(strcmp(ti->str, "typedef")){
1908 fprintf(stderr, "ERROR: typedefbitmap first token is not 'typedef'\n");
1913 alignment=4; /* default size is 32 bits */
1915 if(!strcmp(ti->str, "[")){
1916 ti=parsebrackets(ti, &bi);
1918 /* check that we know how to handle the bracket thing */
1920 if(bi->flags&(~(BI_BITMAP32|BI_BITMAP8))){
1921 fprintf(stderr, "ERROR: typedefbitmap unknown bracket flags encountered : 0x%08x\n",bi->flags);
1924 if(bi->flags&BI_BITMAP32){
1927 if(bi->flags&BI_BITMAP8){
1933 if(strcmp(ti->str, "bitmap")){
1934 fprintf(stderr, "ERROR: typedefbitmap second token is not 'bitmap'\n");
1939 if(strcmp(ti->str, "{")){
1940 fprintf(stderr, "ERROR: typedefbitmap third token is not '{'\n");
1945 /* search forward until the '}' so we can find the name of the bitmap */
1946 for(tmpti=ti;tmpti;tmpti=tmpti->next){
1947 if(!strcmp(tmpti->str, "{")){
1948 fprintf(stderr, "ERROR: typedefbitmap '{' encountered inside bitmap\n");
1951 if(!strcmp(tmpti->str, "}")){
1955 if (!tmpti || !tmpti->next){
1956 fprintf(stderr, "ERROR: typedefbitmap missing matching '}'\n");
1959 bitmap_name=tmpti->next->str;
1960 sprintf(dissectorname, "%s_dissect_%s", ifname, bitmap_name);
1962 FPRINTF(NULL,"\nBITMAP:%s pass:%d\n-------\n",bitmap_name,pass);
1964 /* pass 1 generate header for the struct dissector */
1966 FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, bitmap_name);
1967 FPRINTF(eth_ettarr, " &ett_%s_%s,\n", ifname, bitmap_name);
1968 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);
1969 FPRINTF(eth_code, "\n");
1970 FPRINTF(eth_code, "int\n");
1971 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);
1972 FPRINTF(eth_code, "{\n");
1973 FPRINTF(eth_code, " proto_item *item=NULL;\n");
1974 FPRINTF(eth_code, " proto_tree *tree=NULL;\n");
1977 FPRINTF(eth_code, " guint8 flags;\n");
1978 FPRINTF(eth_code, "\n");
1981 FPRINTF(eth_code, " guint32 flags;\n");
1982 FPRINTF(eth_code, "\n");
1983 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
1986 fprintf(stderr, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment);
1989 FPRINTF(eth_code, "\n");
1990 FPRINTF(eth_code, " if(parent_tree){\n");
1991 FPRINTF(eth_code, " item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, %d, ENC_LITTLE_ENDIAN);\n", alignment);
1992 FPRINTF(eth_code, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, bitmap_name);
1993 FPRINTF(eth_code, " }\n");
1994 FPRINTF(eth_code, "\n");
1997 FPRINTF(eth_code, " offset=dissect_ndr_uint8(tvb, offset, pinfo, NULL, drep, -1, &flags);\n");
1998 FPRINTF(eth_code, "\n");
2001 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, NULL, drep, -1, &flags);\n");
2002 FPRINTF(eth_code, "\n");
2005 fprintf(stderr, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment);
2008 FPRINTF(eth_code, "\n");
2011 /* scan the struct and create call for all bits */
2013 if(!strcmp(ti->str, "}")){
2016 if(!strcmp(ti->str, "[")){
2017 fprintf(stderr, "ERROR: typedefbitmap can not handle '[' yet\n");
2023 sprintf(hf_bitname, "hf_%s_%s_%s", ifname, bitmap_name, name);
2025 if(strcmp(ti->str, "=")){
2026 fprintf(stderr, "ERROR: typedefbitmap i expected a '=' here\n");
2034 if(!strncmp(value, "0x", 2)){
2035 sscanf(value, "0x%x", &val);
2037 fprintf(stderr, "ERROR: typedefbitmap can only handle hexadecimal constants\n");
2042 fprintf(stderr, "ERROR: typedefbitmap can only handle single bit fields\n");
2047 char filter_name[256], base_name[256], tfs_name[256];
2049 sprintf(filter_name, "%s.%s.%s", ifname, bitmap_name, name);
2050 sprintf(base_name, "%d", alignment*8);
2051 sprintf(tfs_name, "TFS(&%s_tfs)", name);
2052 register_hf_field(hf_bitname, name, filter_name, "FT_BOOLEAN", base_name, tfs_name, value, "");
2054 FPRINTF(eth_code, "static const true_false_string %s_tfs = {\n",name);
2055 FPRINTF(eth_code, " \"%s is SET\",\n", name);
2056 FPRINTF(eth_code, " \"%s is NOT set\"\n", name);
2057 FPRINTF(eth_code, "};\n");
2058 FPRINTF(eth_code, "\n");
2062 FPRINTF(eth_code, " proto_tree_add_boolean(tree, %s, tvb, offset-%d, %d, flags);\n", hf_bitname, alignment, alignment);
2063 FPRINTF(eth_code, " if(flags&%s){\n", value);
2064 FPRINTF(eth_code, " proto_item_append_text(item, \" %s\");\n", name);
2065 FPRINTF(eth_code, " }\n");
2066 FPRINTF(eth_code, " flags&=(~%s);\n", value);
2067 FPRINTF(eth_code, "\n");
2070 if(!strcmp(ti->str, ",")){
2077 FPRINTF(eth_code, " if(flags){\n");
2078 FPRINTF(eth_code, " proto_item_append_text(item, \"UNKNOWN-FLAGS\");\n");
2079 FPRINTF(eth_code, " }\n");
2080 FPRINTF(eth_code, "\n");
2081 FPRINTF(eth_code, " return offset;\n");
2082 FPRINTF(eth_code, "}\n");
2085 register_new_type(bitmap_name, dissectorname, "FT_UINT8", "BASE_HEX", "0", "NULL", alignment);
2088 register_new_type(bitmap_name, dissectorname, "FT_UINT32", "BASE_HEX", "0", "NULL", alignment);
2091 fprintf(stderr, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment);
2096 FPRINTF(NULL,"\nEND BITMAP:%s pass:%d\n-------\n",bitmap_name,pass);
2098 /* only advance token_list for pass==1
2099 ti now points to the '}' token
2102 if(!ti || strcmp(ti->str,"}")){
2103 fprintf(stderr, "ERROR: bitmap does not end with '}'\n");
2108 /* just skip the name */
2111 if(!ti || strcmp(ti->str,";")){
2112 fprintf(stderr, "ERROR: bitmap does not end with ';'\n");
2121 /* a case tag might be a negative number, i.e. contain a '-' sign which
2122 is not valid inside a symbol name in c.
2136 /* this function will parse a
2138 construct and generate the appropriate code.
2139 the typedef will be removed from the token_list once it has been processed
2140 the function assumes that the typedef is the first object in the token_list
2141 the function will be called twice, once with pass=0 and once with pass=1
2142 which controls whether subdissectors are to be generated or whether the
2143 union dissector itself is to be generated
2145 static void parsetypedefunion(int pass)
2148 token_item_t *ti, *tmpti;
2149 char dissectorname[256];
2150 bracket_item_t *bi=NULL;
2151 char tmpstr[256], *ptmpstr;
2152 int level, num_pointers;
2153 static int alignment;
2154 type_item_t *type_item;
2156 int tag_alignment, item_alignment;
2159 if(strcmp(ti->str, "typedef")){
2160 fprintf(stderr, "ERROR: typedefunion first token is not 'typedef'\n");
2165 if(!strcmp(ti->str, "[")){
2166 ti=parsebrackets(ti, &bi);
2168 /* check that we know how to handle the bracket thing */
2170 if(bi->flags&(~(BI_SWITCH_TYPE))){
2171 fprintf(stderr, "ERROR: typedefunion unknown bracket flags encountered : 0x%08x\n",bi->flags);
2176 if(strcmp(ti->str, "union")){
2177 fprintf(stderr, "ERROR: typedefunion second token is not 'union'\n");
2182 if(strcmp(ti->str, "{")){
2183 fprintf(stderr, "ERROR: typedefunion third token is not '{'\n");
2188 /* search forward until the '}' so we can find the name of the union */
2189 for(tmpti=ti,level=0;tmpti;tmpti=tmpti->next){
2190 if(!strcmp(tmpti->str, "{")){
2194 if(!strcmp(tmpti->str, "}")){
2203 if (!tmpti || !tmpti->next){
2204 fprintf(stderr, "ERROR: typedefunion missing matching '}'\n");
2207 union_name=tmpti->next->str;
2208 sprintf(dissectorname, "%s_dissect_union_%s", ifname, union_name);
2210 FPRINTF(NULL,"\nUNION:%s pass:%d\n-------\n",union_name,pass);
2212 if(bi && bi->flags&BI_SWITCH_TYPE){
2213 tag_alignment=bi->union_tag_size;
2215 tag_alignment=get_union_tag_size(union_name);
2218 /* this is pass 0 so reset alignment to the minimum possible value
2219 and update as items are processed.
2220 we need alignment when pass 1 is run
2223 alignment=tag_alignment;
2226 /* pass 1 generate header for the struct dissector */
2228 FPRINTF(eth_ett, "static gint ett_%s_%s = -1;\n", ifname, union_name);
2229 FPRINTF(eth_ettarr, " &ett_%s_%s,\n", ifname, union_name);
2230 FPRINTF(eth_code, "\n");
2231 FPRINTF(eth_code, "static int\n");
2232 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);
2233 FPRINTF(eth_code, "{\n");
2234 FPRINTF(eth_code, " proto_item *item=NULL;\n");
2235 FPRINTF(eth_code, " proto_tree *tree=NULL;\n");
2236 FPRINTF(eth_code, " int old_offset;\n");
2237 /* we do alignment on the tag itself here so that
2238 we skip any alignment padding prior to where the tag
2239 itself starts, this makes the byterange in the hexpane
2240 for the union expansion start with the first byte of the tag
2242 switch(tag_alignment){
2246 FPRINTF(eth_code, " guint16 level;\n");
2247 FPRINTF(eth_code, "\n");
2248 FPRINTF(eth_code, " ALIGN_TO_2_BYTES;\n");
2249 FPRINTF(eth_code, "\n");
2252 FPRINTF(eth_code, " guint32 level = 0;\n");
2253 FPRINTF(eth_code, "\n");
2254 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
2255 FPRINTF(eth_code, "\n");
2258 fprintf(stderr, "ERROR: typedefunion 1 can not handle alignment:%d\n",alignment);
2261 FPRINTF(eth_code, " old_offset=offset;\n");
2262 FPRINTF(eth_code, " if(parent_tree){\n");
2263 FPRINTF(eth_code, " item=proto_tree_add_text(parent_tree, tvb, offset, -1, \"%s\");\n", union_name);
2264 FPRINTF(eth_code, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname, union_name);
2265 FPRINTF(eth_code, " }\n");
2266 FPRINTF(eth_code, "\n");
2267 switch(tag_alignment){
2271 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree,\n");
2272 FPRINTF(eth_code, " drep, hf_index, &level);\n");
2275 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree,\n");
2276 FPRINTF(eth_code, " drep, hf_index, &level);\n");
2279 fprintf(stderr, "ERROR: typedefunion 2 can not handle alignment:%d\n",alignment);
2282 FPRINTF(eth_code, "\n");
2283 FPRINTF(eth_code, " switch(level){\n");
2286 /* scan the struct and create all subdissectors */
2289 if(!strcmp(ti->str, "{")){
2294 if(!strcmp(ti->str, "}")){
2302 if(!strcmp(ti->str, "[")){
2303 ti=parsebrackets(ti, &bi);
2308 fprintf(stderr, "ERROR : typedefunion no brackets found for case\n");
2311 /* make sure we catch when we havent implemented everything
2313 we currently only know about CASE and CASE_DEFAULT flags
2315 if(bi->flags&(~(BI_CASE|BI_CASE_DEFAULT|BI_POINTER))){
2316 fprintf(stderr, "ERROR: typedefunion unknown bracket flags encountered : 0x%08x\n",bi->flags);
2319 if(!(bi->flags&BI_CASE)){
2320 fprintf(stderr, "ERROR : typedefunion no case found in brackets\n");
2324 /* only empty default cases for now */
2325 if(bi->flags&BI_CASE_DEFAULT){
2326 if(strcmp(ti->str,";")){
2327 fprintf(stderr, "ERROR: default tag is not empty\n");
2335 /* just skip all and any 'empty' arms */
2336 if(!strcmp(ti->str, ";")){
2341 /* handle the type, verify that we KNOW this type */
2342 type_item=find_type(ti->str);
2344 fprintf(stderr, "ERROR : typedefunion unknown type %s\n",ti->str);
2348 /* count the levels of pointers */
2349 for(num_pointers=0;!strcmp(ti->str, "*");ti=ti->next){
2353 /* keep track of alignment */
2357 item_alignment=type_item->alignment;
2359 if(alignment<item_alignment){
2360 alignment=item_alignment;
2363 sprintf(hf_index, "hf_%s_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
2364 /* pass 0 generate subdissectors */
2366 char filter_name[256];
2368 sprintf(tmpstr, "%s_dissect_union_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
2369 ptmpstr=strdup(tmpstr);
2371 sprintf(filter_name, "%s.%s.%s", ifname, union_name, ti->str);
2372 hf=register_hf_field(hf_index, ti->str, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
2374 FPRINTF(eth_code, "static int\n");
2375 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
2376 FPRINTF(eth_code, "{\n");
2377 FPRINTF(eth_code, " guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
2378 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
2379 FPRINTF(eth_code, " return offset;\n");
2380 FPRINTF(eth_code, "}\n");
2381 FPRINTF(eth_code, "\n");
2383 /* handle pointers */
2384 while(num_pointers--){
2385 sprintf(tmpstr, "%s_%s", ptmpstr, "unique");
2386 FPRINTF(eth_code, "static int\n");
2387 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2388 FPRINTF(eth_code, "{\n");
2389 FPRINTF(eth_code, " offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, drep, %s, NDR_POINTER_UNIQUE, \"%s\", -1);\n", ptmpstr, ti->str);
2390 FPRINTF(eth_code, " return offset;\n");
2391 FPRINTF(eth_code, "}\n");
2392 FPRINTF(eth_code, "\n");
2394 ptmpstr=strdup(tmpstr);
2400 /* handle pointers */
2401 sprintf(tmpstr, "%s_dissect_union_%s_%s_%s", ifname, union_name, case2str(bi->case_name), ti->str);
2402 ptmpstr=strdup(tmpstr);
2403 while(num_pointers--){
2404 sprintf(tmpstr, "%s_%s", ptmpstr, "unique");
2405 ptmpstr=strdup(tmpstr);
2408 if(bi->flags&BI_CASE_DEFAULT){
2409 FPRINTF(eth_code, " default:\n");
2411 FPRINTF(eth_code, " case %s:\n",bi->case_name);
2413 /* each arm itself is aligned independently */
2414 switch(item_alignment){
2418 FPRINTF(eth_code, " ALIGN_TO_2_BYTES;\n");
2421 FPRINTF(eth_code, " ALIGN_TO_4_BYTES;\n");
2424 FPRINTF(eth_code, " ALIGN_TO_8_BYTES;\n");
2427 fprintf(stderr, "ERROR: typedefunion 3 can not handle alignment:%d\n",item_alignment);
2430 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
2431 FPRINTF(eth_code, " break;\n");
2432 FPRINTF(eth_code, "\n");
2436 if(strcmp(ti->str,";")){
2437 fprintf(stderr, "ERROR: field does not end with ';'\n");
2444 FPRINTF(eth_code, " }\n");
2445 FPRINTF(eth_code, "\n");
2446 FPRINTF(eth_code, " proto_item_set_len(item, offset-old_offset);\n");
2447 FPRINTF(eth_code, "\n");
2448 FPRINTF(eth_code, " return offset;\n");
2449 FPRINTF(eth_code, "}\n");
2450 switch(tag_alignment){
2452 register_new_type(union_name, dissectorname, "FT_UINT16", "BASE_DEC", "0", "NULL", alignment);
2455 register_new_type(union_name, dissectorname, "FT_UINT32", "BASE_DEC", "0", "NULL", alignment);
2458 fprintf(stderr, "ERROR: typedefunion 4 can not handle alignment:%d\n",alignment);
2463 FPRINTF(NULL,"\nEND UNION:%s pass:%d\n-------\n",union_name,pass);
2465 /* only advance token_list for pass==1
2466 ti now points to the '}' token
2469 if(!ti || strcmp(ti->str,"}")){
2470 fprintf(stderr, "ERROR: union does not end with '}'\n");
2475 /* just skip the name */
2478 if(!ti || strcmp(ti->str,";")){
2479 fprintf(stderr, "ERROR: union does not end with ';'\n");
2489 /* this function will parse a
2491 construct and generate the appropriate code.
2492 the function will be removed from the token_list once it has been processed
2493 the function assumes that the function is the first object in the token_list
2494 the function will be called three times with
2495 pass=0 generate subdissectors and entries for the function table
2496 pass=1 generate code for the REQUEST
2497 pass=2 generate code for the REPLY
2499 static void parsefunction(int pass)
2501 char *function_name;
2502 static int funcno=0;
2504 bracket_item_t *bi=NULL;
2508 char tmpstr[256], *ptmpstr;
2509 int level, num_pointers;
2510 type_item_t *type_item;
2514 if(strcmp(ti->str, "WERROR")){
2515 fprintf(stderr, "ERROR: function first token is not 'WERROR'\n");
2520 function_name=ti->str;
2523 if(strcmp(ti->str, "(")){
2524 fprintf(stderr, "ERROR: function third token is not '('\n");
2529 FPRINTF(NULL,"\nFUNCTION:%s pass:%d\n-------\n",function_name,pass);
2532 FPRINTF(eth_ft, " { %d, \"%s\",\n",funcno,function_name);
2533 FPRINTF(eth_ft, " %s_dissect_%s_request,\n", ifname, function_name);
2534 FPRINTF(eth_ft, " %s_dissect_%s_response },\n", ifname, function_name);
2538 /* pass 1,2 generate header for the function dissector */
2539 if((pass==1)||(pass==2)){
2540 FPRINTF(eth_code, "\n");
2541 FPRINTF(eth_code, "static int\n");
2542 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");
2543 FPRINTF(eth_code, "{\n");
2546 /* scan the struct and create all subdissectors */
2549 if(!strcmp(ti->str, "(")){
2554 if(!strcmp(ti->str, ")")){
2562 if(!strcmp(ti->str, "[")){
2563 ti=parsebrackets(ti, &bi);
2568 fprintf(stderr, "ERROR : function no brackets found for case\n");
2572 /* make sure we catch when we havent implemented everything
2574 we currently only know about IN and OUT flags
2576 if(bi->flags&(~(BI_IN|BI_OUT|BI_POINTER|BI_SIZE_IS|BI_LENGTH_IS))){
2577 fprintf(stderr, "ERROR: function unknown bracket flags encountered : 0x%08x\n",bi->flags);
2580 if(!(bi->flags&(BI_IN|BI_OUT))){
2581 fprintf(stderr, "ERROR : function parameter is neither in nor out\n");
2585 /* handle the type, verify that we KNOW this type */
2586 type_item=find_type(ti->str);
2588 fprintf(stderr, "ERROR : function unknown type %s\n",ti->str);
2592 /* count the levels of pointers */
2593 for(num_pointers=0;!strcmp(ti->str, "*");ti=ti->next){
2597 /* now that we know how many real poitner there were we must
2598 prepend default pointers to the list so it has the right
2601 pi=prepend_pointer_list(bi->pointer_list, num_pointers);
2603 sprintf(hf_index, "hf_%s_%s_%s", ifname, function_name, ti->str);
2604 /* pass 0 generate subdissectors */
2606 char filter_name[256];
2609 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, function_name, ti->str);
2610 ptmpstr=strdup(tmpstr);
2613 sprintf(filter_name, "%s.%s.%s", ifname, function_name, ti->str);
2614 hf=register_hf_field(hf_index, ti->str, filter_name, type_item->ft_type, type_item->base_type, type_item->vals, type_item->mask, "");
2616 FPRINTF(eth_code, "static int\n");
2617 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", ptmpstr);
2618 FPRINTF(eth_code, "{\n");
2619 FPRINTF(eth_code, " guint32 param=%s;\n",find_dissector_param_value(ptmpstr));
2620 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep, %s, param);\n", type_item->dissector, hf);
2621 FPRINTF(eth_code, " return offset;\n");
2622 FPRINTF(eth_code, "}\n");
2623 FPRINTF(eth_code, "\n");
2626 /* handle switch_is */
2628 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
2631 case BI_SIZE_IS|BI_LENGTH_IS:
2632 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
2633 FPRINTF(eth_code, "static int\n");
2634 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2635 FPRINTF(eth_code, "{\n");
2636 FPRINTF(eth_code, " offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
2637 FPRINTF(eth_code, " return offset;\n");
2638 FPRINTF(eth_code, "}\n");
2639 FPRINTF(eth_code, "\n");
2640 ptmpstr=strdup(tmpstr);
2643 sprintf(tmpstr, "ucarray_%s", ptmpstr);
2644 FPRINTF(eth_code, "static int\n");
2645 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2646 FPRINTF(eth_code, "{\n");
2647 FPRINTF(eth_code, " offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, drep, %s);\n", ptmpstr);
2648 FPRINTF(eth_code, " return offset;\n");
2649 FPRINTF(eth_code, "}\n");
2650 FPRINTF(eth_code, "\n");
2651 ptmpstr=strdup(tmpstr);
2654 fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
2659 /* handle pointers */
2660 while(num_pointers--){
2661 pointer_type=pi->type;
2663 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
2664 FPRINTF(eth_code, "static int\n");
2665 FPRINTF(eth_code, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, guint8 *drep)\n", tmpstr);
2666 FPRINTF(eth_code, "{\n");
2667 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);
2668 FPRINTF(eth_code, " return offset;\n");
2669 FPRINTF(eth_code, "}\n");
2670 FPRINTF(eth_code, "\n");
2672 ptmpstr=strdup(tmpstr);
2677 if((pass==1)||(pass==2)){
2678 sprintf(tmpstr, "%s_dissect_%s_%s", ifname, function_name, ti->str);
2679 ptmpstr=strdup(tmpstr);
2682 switch(bi->flags&(BI_SIZE_IS|BI_LENGTH_IS)){
2685 case BI_SIZE_IS|BI_LENGTH_IS:
2686 sprintf(tmpstr, "ucvarray_%s", ptmpstr);
2687 ptmpstr=strdup(tmpstr);
2690 sprintf(tmpstr, "ucarray_%s", ptmpstr);
2691 ptmpstr=strdup(tmpstr);
2694 fprintf(stderr, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
2699 /* handle pointers */
2700 while(num_pointers--){
2701 pointer_type=pi->type;
2703 sprintf(tmpstr, "%s_%s", pointer_type, ptmpstr);
2704 ptmpstr=strdup(tmpstr);
2707 if((pass==1)&&(bi->flags&BI_IN)){
2708 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
2709 FPRINTF(eth_code, " offset=dissect_deferred_pointers(pinfo, tvb, offset, drep);\n");
2710 FPRINTF(eth_code, "\n");
2712 if((pass==2)&&(bi->flags&BI_OUT)){
2713 FPRINTF(eth_code, " offset=%s(tvb, offset, pinfo, tree, drep);\n", ptmpstr);
2714 FPRINTF(eth_code, " offset=dissect_deferred_pointers(pinfo, tvb, offset, drep);\n");
2715 FPRINTF(eth_code, "\n");
2721 if(!strcmp(ti->str,",")){
2727 if((pass==1)||(pass==2)){
2729 FPRINTF(eth_code, " offset=dissect_ntstatus(tvb, offset, pinfo, tree, drep, %s, NULL);\n", hf_status);
2730 FPRINTF(eth_code, "\n");
2732 FPRINTF(eth_code, "\n");
2733 FPRINTF(eth_code, " return offset;\n");
2734 FPRINTF(eth_code, "}\n");
2737 FPRINTF(NULL,"\nEND FUNCTION:%s pass:%d\n-------\n",function_name,pass);
2739 /* only advance token_list for pass==2
2740 ti now points to the ')' token
2743 if(!ti || strcmp(ti->str,")")){
2744 fprintf(stderr, "ERROR: function does not end with ')'\n");
2749 if(!ti || strcmp(ti->str,";")){
2750 fprintf(stderr, "ERROR: function does not end with ';'\n");
2760 /* this function will parse a
2763 typedef [ v1_enum ] enum {
2764 construct and generate the appropriate code.
2765 the typedef will be removed from the token_list once it has been processed
2766 the function assumes that the typedef is the first object in the token_list
2768 static void parsetypedefenum(void)
2771 enum_list_t *enum_list, *el, *lastel;
2775 char dissectorname[256], valsstring[256], hfvalsstring[256];
2780 if(strcmp(ti->str, "typedef")){
2781 fprintf(stderr, "ERROR: typedefenum first token is not 'typedef'\n");
2786 /* this could be a [ v1_enum ] */
2787 if(!strcmp(ti->str, "[")){
2790 if(strcmp(ti->str, "v1_enum")){
2791 fprintf(stderr, "ERROR: typedefenum not 'v1_enum' inside brackets\n");
2796 if(strcmp(ti->str, "]")){
2797 fprintf(stderr, "ERROR: typedefenum 'v1_enum' is not followed by ']'\n");
2806 if(strcmp(ti->str, "enum")){
2807 fprintf(stderr, "ERROR: typedefenum second token is not 'enum'\n");
2812 if(strcmp(ti->str, "{")){
2813 fprintf(stderr, "ERROR: typedefenum third token is not '{'\n");
2818 /* now parse all values until we find the "}" */
2824 if(!strcmp(ti->str,"}")){
2829 /* handle 4 types of entries:
2835 el=malloc(sizeof(enum_list_t));
2848 /* grab separator */
2849 if(!strcmp(ti->str,"=")){
2852 val=strtol(ti->str,&p,0);
2853 if (p==ti->str||*p) {
2854 fprintf(stderr, "ERROR: typedefenum value is not a number\n");
2865 if(!strcmp(ti->str,",")){
2871 if(!strcmp(ti->str,"}")){
2876 fprintf(stderr,"ERROR: typedefenum should not be reached\n");
2880 /* verify that it ends with a ';' */
2881 if(strcmp(ti->next->str,";")){
2882 fprintf(stderr,"ERROR enum terminator is not ';'\n");
2886 sprintf(valsstring, "%s_%s_vals", ifname, ti->str);
2887 sprintf(dissectorname, "%s_dissect_%s", ifname, ti->str);
2889 FPRINTF(NULL,"\nENUM:%s\n-------\n",ti->str);
2891 FPRINTF(eth_hdr, "\n");
2892 for(el=enum_list;el;el=el->next){
2893 FPRINTF(eth_hdr, "#define %s %d\n", el->name, el->val);
2896 FPRINTF(eth_hdr, "\n");
2897 FPRINTF(eth_hdr, "extern const value_string %s[];\n", valsstring);
2898 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);
2900 FPRINTF(eth_code, "\n");
2901 FPRINTF(eth_code, "const value_string %s[] = {\n", valsstring);
2903 for(el=enum_list;el;el=el->next){
2904 FPRINTF(eth_code, " { %d , \"%s\" },\n", el->val, el->name);
2906 FPRINTF(eth_code, " { 0 , NULL }\n");
2907 FPRINTF(eth_code, "};\n");
2909 FPRINTF(eth_code, "\n");
2910 FPRINTF(eth_code, "int\n");
2911 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);
2912 FPRINTF(eth_code, "{\n");
2915 FPRINTF(eth_code, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
2918 FPRINTF(eth_code, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, drep, hf_index, NULL);\n");
2921 fprintf(stderr,"ERROR enum unknown size\n");
2925 FPRINTF(eth_code, " return offset;\n");
2926 FPRINTF(eth_code, "}\n");
2927 FPRINTF(eth_code, "\n");
2930 sprintf(hfvalsstring, "VALS(%s)", valsstring);
2933 register_new_type(ti->str, dissectorname, "FT_INT16", "BASE_DEC", "0", hfvalsstring, 2);
2936 register_new_type(ti->str, dissectorname, "FT_INT32", "BASE_DEC", "0", hfvalsstring, 4);
2939 fprintf(stderr,"ERROR enum unknown size\n");
2943 FPRINTF(NULL,"\n----------\nEND ENUM:%s\n",ti->str);
2945 /* skip past the name and the ';' */
2946 token_list=ti->next->next;
2949 typedef struct _trimmed_prefixes_t {
2950 struct _trimmed_prefixes_t *next;
2952 } trimmed_prefixes_t;
2953 static trimmed_prefixes_t *prefixes_to_trim=NULL;
2955 static void preparetrimprefix(char *prefix_name)
2957 trimmed_prefixes_t *new_prefix;
2958 new_prefix=malloc(sizeof(trimmed_prefixes_t));
2959 new_prefix->next=prefixes_to_trim;
2960 prefixes_to_trim=new_prefix;
2961 new_prefix->name=strdup(prefix_name);
2968 trimmed_prefixes_t *pfx;
2971 for(pfx=prefixes_to_trim;pfx;pfx=pfx->next){
2972 len=strlen(pfx->name);
2973 for(ti=token_list;ti;ti=ti->next){
2974 if(!strncmp(ti->str, pfx->name, len)){
2981 static int Exit(int code)
2983 fprintf(stderr, "The tokens remaining when aborting:\n");
2989 static void usage(void)
2991 fprintf(stderr, "Usage: idl2wrs <interface>\n");
2995 mergefile(char *name, FILE *outfile)
2999 fprintf(outfile, "\n\n/* INCLUDED FILE : %s */\n", name);
3000 infile=fopen(name, "r");
3001 while(!feof(infile)){
3009 fprintf(outfile, "/* END OF INCLUDED FILE : %s */\n\n\n", name);
3015 str_read_string(char *str, char **name)
3017 char tmpstr[256], *strptr;
3027 *name=strdup(tmpstr);
3031 if( (*str==' ') || (*str=='\t') ){
3042 if( (*str==' ') || (*str=='\t') ){
3048 *name=strdup(tmpstr);
3051 if( (*str=='"') || (*str=='\n') ){
3053 *name=strdup(tmpstr);
3062 readcnffile(FILE *fh)
3066 FPRINTF(NULL, "Reading conformance file\n=======================\n");
3069 if(!fgets(cnfline, 1023, fh) || !cnfline[0]){
3072 if(cnfline[0]=='#'){
3073 /* ignore all comments */
3074 } else if(!strncmp(cnfline, "NOEMIT", 6)){
3075 no_emit_item_t *nei;
3079 str=str_read_string(str, &name);
3080 nei=malloc(sizeof(no_emit_item_t));
3081 nei->next=no_emit_list;
3084 FPRINTF(NULL, "NOEMIT : %s\n", nei->name);
3085 } else if(!strncmp(cnfline, "TYPE", 4)){
3086 char *name, *dissectorname, *ft_type, *base_type;
3087 char *mask, *valsstring, *al;
3092 str=str_read_string(str, &name);
3093 str=str_read_string(str, &dissectorname);
3094 str=str_read_string(str, &ft_type);
3095 str=str_read_string(str, &base_type);
3096 str=str_read_string(str, &mask);
3097 str=str_read_string(str, &valsstring);
3098 str=str_read_string(str, &al);
3101 FPRINTF(NULL, "TYPE : X%s,%sX\n", name, dissectorname);
3102 register_new_type(name, dissectorname, ft_type, base_type, mask, valsstring, alignment);
3103 } else if(!strncmp(cnfline, "PARAM_VALUE", 11)){
3104 char *dissectorname, *value;
3108 str=str_read_string(str, &dissectorname);
3109 str=str_read_string(str, &value);
3111 FPRINTF(NULL, "PARAM_VALUE : %s=%s\n", dissectorname,value);
3112 register_dissector_param_value(dissectorname, value);
3113 } else if(!strncmp(cnfline, "HF_FIELD", 8)){
3114 char *hf_index, *title, *filter_name, *ft_type;
3115 char *base_type, *valsstring, *mask, *blurb;
3119 str=str_read_string(str, &hf_index);
3120 str=str_read_string(str, &title);
3121 str=str_read_string(str, &filter_name);
3122 str=str_read_string(str, &ft_type);
3123 str=str_read_string(str, &base_type);
3124 str=str_read_string(str, &valsstring);
3125 str=str_read_string(str, &mask);
3126 str=str_read_string(str, &blurb);
3127 FPRINTF(NULL, "HF_FIELD: %s \"%s\"\n", hf_index, title);
3128 register_hf_field(hf_index, title, filter_name, ft_type, base_type, valsstring, mask, blurb);
3129 } else if(!strncmp(cnfline, "HF_RENAME", 9)){
3130 char *old_name, *new_name;
3134 str=str_read_string(str, &old_name);
3135 str=str_read_string(str, &new_name);
3136 FPRINTF(NULL, "HF_RENAME: %s -> %s\n", old_name, new_name);
3137 register_hf_rename(old_name, new_name);
3138 } else if(!strncmp(cnfline, "UNION_TAG_SIZE", 14)){
3139 char *union_name, *union_tag;
3141 union_tag_size_item_t *utsi;
3145 str=str_read_string(str, &union_name);
3146 str=str_read_string(str, &union_tag);
3147 union_tag_size=atoi(union_tag);
3148 FPRINTF(NULL, "UNION_TAG_SIZE: %s == %d\n", union_name, union_tag_size);
3149 utsi=malloc(sizeof(union_tag_size_item_t));
3150 utsi->next=union_tag_size_list;
3151 union_tag_size_list=utsi;
3152 utsi->name=strdup(union_name);
3153 utsi->size=union_tag_size;
3154 } else if(!strncmp(cnfline, "STRIP_PREFIX", 12)){
3159 str=str_read_string(str, &prefix_name);
3160 FPRINTF(NULL, "STRIP_PREFIX: %s\n", prefix_name);
3161 preparetrimprefix(prefix_name);
3163 fprintf(stderr, "ERROR: could not parse cnf directive:%s\n",cnfline);
3169 int main(int argc, char *argv[])
3173 char prefix_str[256];
3182 eth_code=fopen("ETH_CODE", "w");
3183 eth_hdr=fopen("ETH_HDR", "w");
3184 eth_hfarr=fopen("ETH_HFARR", "w");
3185 eth_hf=fopen("ETH_HF", "w");
3186 eth_ettarr=fopen("ETH_ETTARR", "w");
3187 eth_ett=fopen("ETH_ETT", "w");
3188 eth_ft=fopen("ETH_FT", "w");
3189 eth_handoff=fopen("ETH_HANDOFF", "w");
3191 sprintf(idlfile, "%s.cnf", argv[1]);
3192 fh=fopen(idlfile,"r");
3198 sprintf(idlfile, "%s.idl", argv[1]);
3199 fh=fopen(idlfile,"r");
3201 fprintf(stderr, "ERROR: could not open idl-file:%s\n",idlfile);
3208 prune_keyword_parameters("size_is");
3209 prune_keyword_parameters("length_is");
3210 rename_tokens("NTSTATUS", "WERROR");
3211 rename_tokens("unistr_noterm", "unistr");
3212 rename_tokens("ascstr_noterm", "ascstr");
3213 rename_tokens("hyper", "uint64");
3214 FPRINTF(NULL,"\n\nParsing header:\n================\n");
3217 /* some idl files prepend a lot of symbols with <ifname>_
3218 search through the tokenlist and remove all such
3221 sprintf(prefix_str, "%s_", ifname);
3222 preparetrimprefix(prefix_str);
3225 /* this is the main loop, each iteration it tries to identify what
3226 kind of construct is the first entry in the token_list and call
3227 the appropriate handler
3230 /* just skip any [ ] that starts a new construct */
3231 if( !strcmp(token_list->str, "[") ){
3232 token_list=parsebrackets(token_list, &bi);
3236 /* typedef enum { */
3237 if( !strcmp(token_list->str,"typedef")
3238 &&!strcmp(token_list->next->str,"enum") ){
3243 /* typedef [ v1_enum ] enum { */
3244 if( !strcmp(token_list->str,"typedef")
3245 &&!strcmp(token_list->next->str,"[")
3246 &&!strcmp(token_list->next->next->str,"v1_enum")
3247 &&!strcmp(token_list->next->next->next->str,"]")
3248 &&!strcmp(token_list->next->next->next->next->str,"enum") ){
3254 if( !strcmp(token_list->str,"const") ){
3259 /* typedef struct { */
3260 if( !strcmp(token_list->str,"typedef") ){
3261 token_item_t *tmpti;
3263 tmpti=token_list->next;
3264 if( !strcmp(tmpti->str, "[") ){
3265 tmpti=parsebrackets(tmpti, &bi);
3266 /* do some sanity checks here of bi->flags */
3268 if( !strcmp(tmpti->str, "struct") ){
3269 parsetypedefstruct(0);
3270 parsetypedefstruct(1);
3275 /* typedef union { */
3276 if( !strcmp(token_list->str,"typedef") ){
3277 token_item_t *tmpti;
3279 tmpti=token_list->next;
3280 if( !strcmp(tmpti->str, "[") ){
3281 tmpti=parsebrackets(tmpti, &bi);
3282 /* do some sanity checks here of bi->flags */
3284 if( !strcmp(tmpti->str, "union") ){
3285 parsetypedefunion(0);
3286 parsetypedefunion(1);
3291 /* typedef bitmap { */
3292 if( !strcmp(token_list->str,"typedef") ){
3293 token_item_t *tmpti;
3295 tmpti=token_list->next;
3296 if( !strcmp(tmpti->str, "[") ){
3297 tmpti=parsebrackets(tmpti, &bi);
3298 /* do some sanity checks here of bi->flags */
3300 if( !strcmp(tmpti->str, "bitmap") ){
3301 parsetypedefbitmap(0);
3302 parsetypedefbitmap(1);
3307 /* functions: WERROR function '(' */
3308 if( !strcmp(token_list->str,"WERROR")
3309 &&!strcmp(token_list->next->next->str,"(") ){
3317 if( !strcmp(token_list->str,"declare") ){
3334 fclose(eth_handoff);
3336 /* unless the token_list now only contains a single token : '}'
3337 we have failed to compile the idl file properly
3339 if( strcmp(token_list->str, "}") || token_list->next){
3340 fprintf(stderr, "ERROR: we did not process all tokens. Compiler is incomplete.\n===========================================\n");
3345 check_hf_rename_refcount();
3347 /* merge code and template into dissector */
3348 sprintf(line, "packet-dcerpc-%s.c", ifname);
3349 fh=fopen(line, "w");
3350 sprintf(tmplfile, "packet-dcerpc-%s-template.c", argv[1]);
3351 tfh=fopen(tmplfile, "r");
3353 fprintf(stderr, "ERROR: could not find %s\n", tmplfile);
3358 if(!fgets(line, 1024, tfh) || !line[0]){
3361 if(!strncmp(line, "ETH_CODE", 8)){
3362 mergefile("ETH_CODE",fh);
3363 } else if(!strncmp(line, "ETH_HDR", 7)){
3364 mergefile("ETH_HDR",fh);
3365 } else if(!strncmp(line, "ETH_HFARR", 9)){
3366 mergefile("ETH_HFARR",fh);
3367 } else if(!strncmp(line, "ETH_HF", 6)){
3368 mergefile("ETH_HF",fh);
3369 } else if(!strncmp(line, "ETH_ETTARR", 10)){
3370 mergefile("ETH_ETTARR",fh);
3371 } else if(!strncmp(line, "ETH_ETT", 7)){
3372 mergefile("ETH_ETT",fh);
3373 } else if(!strncmp(line, "ETH_FT", 6)){
3374 mergefile("ETH_FT",fh);
3375 } else if(!strncmp(line, "ETH_HANDOFF", 11)){
3376 mergefile("ETH_HANDOFF",fh);
3384 sprintf(line, "packet-dcerpc-%s.h", ifname);
3385 fh=fopen(line, "w");
3386 sprintf(tmplfile, "packet-dcerpc-%s-template.h", argv[1]);
3387 tfh=fopen(tmplfile, "r");
3389 fprintf(stderr, "ERROR: could not find %s\n", tmplfile);
3394 if(!fgets(line, 1024, tfh) || !line[0]){
3397 if(!strncmp(line, "ETH_CODE", 8)){
3398 mergefile("ETH_CODE",fh);
3399 } else if(!strncmp(line, "ETH_HDR", 7)){
3400 mergefile("ETH_HDR",fh);
3401 } else if(!strncmp(line, "ETH_HFARR", 9)){
3402 mergefile("ETH_HFARR",fh);
3403 } else if(!strncmp(line, "ETH_HF", 6)){
3404 mergefile("ETH_HF",fh);
3405 } else if(!strncmp(line, "ETH_ETTARR", 10)){
3406 mergefile("ETH_ETTARR",fh);
3407 } else if(!strncmp(line, "ETH_ETT", 7)){
3408 mergefile("ETH_ETT",fh);
3409 } else if(!strncmp(line, "ETH_FT", 6)){
3410 mergefile("ETH_FT",fh);
3411 } else if(!strncmp(line, "ETH_HANDOFF", 11)){
3412 mergefile("ETH_HANDOFF",fh);
3418 printf("%s was successfully compiled\n", ifname);
3425 remove("ETH_HFARR");
3427 remove("ETH_ETTARR");
3430 remove("ETH_HANDOFF");