2 * DCE RPC IDL to Wireshark dissector compiler
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
13 check that every cnf defined type,hffield,rename,... has been referenced
14 at least once and if not, abort with an error
16 need to distinguish between NTTIME (absolute time) and relative time
18 prune_xxx should only act inside of '[' ']'
20 add support for bool8,16,32,64 with tfs strings
22 add the remaining array type (uvarray)
24 add code to verify that union tag length is correct
26 /* List of built in types :
27 WERROR A 32 bit integer holding a DCE/NT status code.
32 uint16 A 16 bit integer
35 uint32 A 32 bit integer
38 uint64 A 64 bit integer
40 udlong A 64 bit integer aligned on 4 byte boundary
43 time_t A 32 bit integer holding a unix style time_t
45 NTTIME_hyper A 64 bit integer representing a NTTIME
48 unistr A conformant and varying unicode string
50 ascstr A conformant and varying ascii string
55 uuid_t A 16 byte FT_GUID blob.
66 /* All field dissectors that call a normal type
67 (i.e. not a pointer, not an array)
68 has a local variable unsigned param declared which is passed on to the
70 The default value is 0 but the PARAM_VALUE conformance tag can be used to
72 This is only meaningful if the called type dissector actually does anything
79 #include <glib/gstdio.h>
83 #include <wsutil/strtoi.h>
87 #define DISSECTORNAME_MAXLEN 256
89 #define BASE_BUFFER_SIZE 256
91 static FILE *tfh
, *eth_code
, *eth_hdr
, *eth_hf
, *eth_hfarr
, *eth_ett
, *eth_ettarr
, *eth_ft
, *eth_handoff
;
92 static char *uuid
=NULL
;
93 static char *version
=NULL
;
94 static const char *pointer_default
=NULL
;
95 static char *ifname
=NULL
;
96 static char hf_status
[BASE_BUFFER_SIZE
];
97 static int lineno
,linepos
;
98 static char line
[4 * BASE_BUFFER_SIZE
];
100 static void FPRINTF(FILE *fh
, const char *format
, ...)
105 va_start(args
, format
);
106 vfprintf (stderr
, format
, args
);
110 va_start(args
, format
);
111 vfprintf (fh
, format
, args
);
116 typedef struct _pointer_item_t
{
117 struct _pointer_item_t
*next
;
121 #define BI_CASE 0x00000001
122 #define BI_CASE_DEFAULT 0x00000002
123 #define BI_IN 0x00000004
124 #define BI_OUT 0x00000008
125 #define BI_SIZE_IS 0x00000010
126 #define BI_LENGTH_IS 0x00000020
127 #define BI_POINTER 0x00000040
128 #define BI_BITMAP8 0x00000100
129 #define BI_BITMAP32 0x00000200
130 #define BI_SWITCH_TYPE 0x00000400
131 typedef struct _bracket_item_t
{
133 const char *case_name
;
134 pointer_item_t
*pointer_list
;
138 typedef struct _no_emit_item_t
{
139 struct _no_emit_item_t
*next
;
142 static no_emit_item_t
*no_emit_list
=NULL
;
144 typedef struct _hf_rename_item_t
{
145 struct _hf_rename_item_t
*next
;
146 int refcount
; /* number of times this rename has been referenced */
150 static hf_rename_item_t
*hf_rename_list
=NULL
;
152 typedef struct _enum_list_t
{
153 struct _enum_list_t
*next
;
158 typedef struct _token_item_t
{
159 struct _token_item_t
*next
;
162 static token_item_t
*token_list
=NULL
;
163 static token_item_t
*last_token_item
=NULL
;
165 typedef struct _type_item_t
{
166 struct _type_item_t
*next
;
175 static type_item_t
*type_list
=NULL
;
177 typedef struct _union_tag_size_item_t
{
178 struct _union_tag_size_item_t
*next
;
181 } union_tag_size_item_t
;
182 static union_tag_size_item_t
*union_tag_size_list
=NULL
;
184 typedef struct _hf_field_item_t
{
185 struct _hf_field_item_t
*next
;
189 static hf_field_item_t
*hf_field_list
=NULL
;
191 typedef struct _dissector_param_value_t
{
192 struct _dissector_param_value_t
*next
;
195 } dissector_param_value_t
;
196 static dissector_param_value_t
*dissector_param_list
=NULL
;
198 static type_item_t
*find_type(char *name
);
199 static int Exit(int code
);
202 register_dissector_param_value(const char *name
, const char *value
)
204 dissector_param_value_t
*dpv
;
205 dpv
=g_new0(dissector_param_value_t
, 1);
207 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
210 dpv
->next
=dissector_param_list
;
211 dissector_param_list
=dpv
;
212 dpv
->name
=g_strdup(name
);
213 dpv
->value
=g_strdup(value
);
217 find_dissector_param_value(char *name
)
219 dissector_param_value_t
*dpv
;
220 for(dpv
=dissector_param_list
;dpv
;dpv
=dpv
->next
){
221 if(!g_strcmp0(name
,dpv
->name
)){
228 static pointer_item_t
*
229 prepend_pointer_list(pointer_item_t
*ptrs
, int num_pointers
)
235 if(num_pointers
)num_pointers
--;
239 while(num_pointers
--){
240 pi
=g_new0(pointer_item_t
, 1);
242 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
246 pi
->type
=pointer_default
;
255 ptr_to_define(const char *pointer_type
)
257 if(!g_strcmp0(pointer_type
, "unique")){
258 return "NDR_POINTER_UNIQUE";
259 } else if(!g_strcmp0(pointer_type
, "ref")){
260 return "NDR_POINTER_REF";
261 } else if(!g_strcmp0(pointer_type
, "ptr")){
262 return "NDR_POINTER_PTR";
265 FPRINTF(stderr
, "prt_to_define, weirdo pointer :%s\n", pointer_type
);
270 get_union_tag_size(char *name
)
272 union_tag_size_item_t
*utsi
;
273 for(utsi
=union_tag_size_list
;utsi
;utsi
=utsi
->next
){
274 if(!g_strcmp0(name
, utsi
->name
)){
278 FPRINTF(stderr
, "ERROR: size of tag for union:%s is not known\n", name
);
279 FPRINTF(stderr
, " use the UNION_TAG_SIZE directive to specify it in the conformance file\n");
284 /* this function will add an entry to the hf_rename list */
286 register_hf_rename(const char *old_name
, const char *new_name
)
288 hf_rename_item_t
*new_item
;
289 new_item
=g_new0(hf_rename_item_t
, 1);
291 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
294 new_item
->next
=hf_rename_list
;
295 hf_rename_list
=new_item
;
296 new_item
->refcount
=0;
297 new_item
->old_name
=g_strdup(old_name
);
298 new_item
->new_name
=g_strdup(new_name
);
301 /* this function checks that all hf_rename fields have actually been referenced
302 if not out conformance file is stale
305 check_hf_rename_refcount(void)
307 hf_rename_item_t
*hri
;
309 /* don't generate code for renamed hf fields just return the new name*/
310 for(hri
=hf_rename_list
;hri
;hri
=hri
->next
){
312 FPRINTF(stderr
, "ERROR: the hf_rename field:%s was never referenced. it is likely the conformance file is stale\n", hri
->old_name
);
318 static hf_field_item_t
*
319 find_hf_field(char *name
)
321 hf_field_item_t
*hfi
;
323 for(hfi
=hf_field_list
;hfi
;hfi
=hfi
->next
){
324 if(!g_strcmp0(hfi
->name
, name
)){
329 FPRINTF(stderr
, "find_hf_field: unknown hf_field:%s\n",name
);
337 /* this function will create the code required for a hf field.
338 it MIGHT rename the field so a user MUST use the name returned
340 for fields that are to be renamed no code is generated
343 register_hf_field(const char *hf_name
, const char *title
, const char *filter_name
, const char *ft_type
, const char *base_type
, const char *valsstring
, const char *mask
, const char *blurb
)
345 hf_field_item_t
*hfi
;
346 hf_rename_item_t
*hri
;
348 /* don't generate code for renamed hf fields just return the new name*/
349 for(hri
=hf_rename_list
;hri
;hri
=hri
->next
){
350 if(!strncmp(hf_name
, hri
->old_name
, strlen(hf_name
))){
351 hfi
=find_hf_field(hri
->new_name
);
352 if(g_strcmp0(ft_type
, hfi
->ft_type
)){
353 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
);
357 return hri
->new_name
;
361 hfi
=g_new0(hf_field_item_t
, 1);
363 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
366 hfi
->next
=hf_field_list
;
368 hfi
->name
=g_strdup(hf_name
);
369 hfi
->ft_type
=g_strdup(ft_type
);
371 FPRINTF(eth_hf
, "static int %s;\n", hf_name
);
372 FPRINTF(eth_hfarr
, " { &%s,\n", hf_name
);
373 FPRINTF(eth_hfarr
, " { \"%s\", \"%s\", %s, %s,\n", title
, filter_name
, ft_type
, base_type
);
374 FPRINTF(eth_hfarr
, " %s, %s,\n", valsstring
, mask
);
375 if (strlen(blurb
) > 0)
376 FPRINTF(eth_hfarr
, " \"%s\", HFILL }},\n", blurb
);
378 FPRINTF(eth_hfarr
, " NULL, HFILL }},\n");
379 FPRINTF(eth_hfarr
, "\n");
384 /* this function will parse the no emit list and decide whether code should
385 be generated for this dissector or if we should only register the type.
388 check_if_to_emit(char *name
)
392 for(nel
=no_emit_list
;nel
;nel
=nel
->next
){
393 if(!g_strcmp0(name
, nel
->name
)){
394 FPRINTF(NULL
, "SKIPPED emitting of %s\n",name
);
403 prune_keywords(char *name
)
407 for(ti
=token_list
;ti
;ti
=ti
->next
){
411 if(!g_strcmp0(ti
->next
->str
, name
)){
412 if(!g_strcmp0(ti
->next
->next
->str
, ",")){
413 ti
->next
=ti
->next
->next
->next
;
415 ti
->next
=ti
->next
->next
;
423 rename_tokens(const char *old_name
, const char *new_name
)
427 for(ti
=token_list
;ti
;ti
=ti
->next
){
428 if(!g_strcmp0(ti
->str
, old_name
)){
429 ti
->str
=g_strdup(new_name
);
435 prune_keyword_parameters(const char *name
)
437 token_item_t
*ti
, *tmpti
;
439 for(ti
=token_list
;ti
;ti
=ti
->next
){
440 if(!g_strcmp0(ti
->str
, name
)){
441 if(!g_strcmp0(ti
->next
->str
, "(")){
444 if(!g_strcmp0(tmpti
->str
, ")")){
445 ti
->next
=tmpti
->next
;
455 /* this function will parse a bracket item
457 it will return the token of the next item following the ']'
459 static token_item_t
*
460 parsebrackets(token_item_t
*ti
, bracket_item_t
**bracket
){
462 const type_item_t
*type_item
;
464 if(g_strcmp0(ti
->str
, "[")){
465 FPRINTF(stderr
, "ERROR: parsebrackets first token is not '['\n");
470 br
=g_new0(bracket_item_t
, 1);
472 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
478 br
->pointer_list
=NULL
;
481 if( !g_strcmp0(ti
->str
, "{")
482 ||!g_strcmp0(ti
->str
, "}")){
483 FPRINTF(stderr
, "ERROR: parsebrackets '{' '}' inside bracket item\n");
487 if(!g_strcmp0(ti
->str
, "[")){
488 FPRINTF(stderr
, "ERROR: parsebrackets '[' inside bracket item\n");
493 if(!g_strcmp0(ti
->str
, "]")){
494 /* check for [ ... ] [ ...] */
497 if(!g_strcmp0(ti
->str
, "[")){
504 /* just ignore all ',' */
505 if(!g_strcmp0(ti
->str
, ",")){
510 /* case '(' tag ')' */
511 if(!g_strcmp0(ti
->str
, "case")){
515 if(g_strcmp0(ti
->str
, "(")){
516 FPRINTF(stderr
, "ERROR: parsebrackets case not followed by '('\n");
522 br
->case_name
=ti
->str
;
525 if(g_strcmp0(ti
->str
, ")")){
526 FPRINTF(stderr
, "ERROR: parsebrackets case does not end with ')'\n");
534 if(!g_strcmp0(ti
->str
, "default")){
536 br
->flags
|=BI_CASE_DEFAULT
;
537 br
->case_name
="default";
544 if(!g_strcmp0(ti
->str
, "in")){
551 if(!g_strcmp0(ti
->str
, "out")){
557 /* public : we don't care about this one */
558 if(!g_strcmp0(ti
->str
, "public")){
563 /* gensize : we don't care about this one */
564 if(!g_strcmp0(ti
->str
, "gensize")){
570 if(!g_strcmp0(ti
->str
, "switch_is")){
571 FPRINTF(stderr
, "WARNING: parsebrackets can not handle switch_is properly yet so we can not verify the tag size\n");
573 if(!g_strcmp0(ti
->str
, ")")){
583 if(!g_strcmp0(ti
->str
, "subcontext")){
585 if(!g_strcmp0(ti
->str
, ")")){
594 /* value we don't care about this one so just skip it */
595 if(!g_strcmp0(ti
->str
, "value")){
598 if( g_strcmp0(ti
->str
, "(") ){
599 FPRINTF(stderr
, "WARNING: parsebrackets value was not followed by '('\n");
604 if(!g_strcmp0(ti
->str
, "(")){
609 if(!g_strcmp0(ti
->str
, ")")){
622 /* range we don't care about this one so just skip it */
623 if(!g_strcmp0(ti
->str
, "range")){
626 if( g_strcmp0(ti
->str
, "(") ){
627 FPRINTF(stderr
, "WARNING: parsebrackets range was not followed by '('\n");
632 if(!g_strcmp0(ti
->str
, "(")){
637 if(!g_strcmp0(ti
->str
, ")")){
650 /* flag we don't care about this one so just skip it */
651 if(!g_strcmp0(ti
->str
, "flag")){
654 if( g_strcmp0(ti
->str
, "(") ){
655 FPRINTF(stderr
, "WARNING: parsebrackets flag was not followed by '('\n");
660 if(!g_strcmp0(ti
->str
, "(")){
665 if(!g_strcmp0(ti
->str
, ")")){
679 if(!g_strcmp0(ti
->str
, "switch_type")){
680 br
->flags
|=BI_SWITCH_TYPE
;
683 if(g_strcmp0(ti
->str
, "(")){
684 FPRINTF(stderr
, "WARNING: parsebrackets switch_type was not followed by '('\n");
689 type_item
=find_type(ti
->str
);
691 FPRINTF(stderr
, "ERROR : parsebrackets switch_type unknown type %s\n",ti
->str
);
694 br
->union_tag_size
=type_item
->alignment
;
697 if(g_strcmp0(ti
->str
, ")")){
698 FPRINTF(stderr
, "WARNING: parsebrackets switch_type did not end with ')'\n");
707 if(!g_strcmp0(ti
->str
, "size_is")){
708 br
->flags
|=BI_SIZE_IS
;
714 if(!g_strcmp0(ti
->str
, "length_is")){
715 br
->flags
|=BI_LENGTH_IS
;
721 if(!g_strcmp0(ti
->str
, "bitmap8bit")){
722 br
->flags
|=BI_BITMAP8
;
728 if(!g_strcmp0(ti
->str
, "bitmap32bit")){
729 br
->flags
|=BI_BITMAP32
;
734 /* ref, unique or ptr */
735 if(!g_strcmp0(ti
->str
, "ref")
736 || !g_strcmp0(ti
->str
, "unique")
737 || !g_strcmp0(ti
->str
, "ptr")){
738 pointer_item_t
*newpi
;
740 br
->flags
|=BI_POINTER
;
741 newpi
=g_new0(pointer_item_t
, 1);
743 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
748 newpi
->next
=br
->pointer_list
;
749 br
->pointer_list
=newpi
;
754 FPRINTF(stderr
, "ERROR: parsebrackets should not be reached unknown tag:%s\n", ti
->str
);
762 /* this function will register a new type learnt from the IDL file
765 register_new_type(const char *name
, const char *dissectorname
, const char *ft_type
, const char *base_type
, const char *mask
, const char *valsstring
, int alignment
){
766 type_item_t
*new_type
;
768 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
);
770 new_type
=g_new0(type_item_t
, 1);
772 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
775 new_type
->next
=type_list
;
776 new_type
->name
=g_strdup(name
);
777 new_type
->dissector
=g_strdup(dissectorname
);
778 new_type
->ft_type
=g_strdup(ft_type
);
779 new_type
->base_type
=g_strdup(base_type
);
780 new_type
->mask
=g_strdup(mask
);
781 new_type
->vals
=g_strdup(valsstring
);
782 new_type
->alignment
=alignment
;
789 /* this function will print the remaining content of the token list
791 static void printtokenlist(int count
)
794 FPRINTF(stderr
, "TOKENLIST:\n");
795 for(ti
=token_list
;ti
&&count
;count
--,ti
=ti
->next
){
796 FPRINTF(stderr
, "Token \"%s\"\n",ti
->str
);
799 FPRINTF(stderr
, " ...\n");
804 /* this function will parse the header and pick up the fields
805 * we are interested in.
806 * the header is supposed to start at the very first token and look like
807 * [ <fields> ] inteface <ifname> {
809 * we are interested in the fields:
814 * this function will also g_remove the header from the token list
816 static void parseheader(void)
818 char filter_name
[BASE_BUFFER_SIZE
];
825 FPRINTF(stderr
, "ERROR: no tokens\n");
829 /* first token must be '[' */
830 if( g_strcmp0(ti
->str
, "[") ){
831 FPRINTF(stderr
, "ERROR: first token is not '['\n");
835 for(ti
=token_list
;ti
;ti
=ti
->next
){
836 if( !g_strcmp0(ti
->str
, "[")){
840 if( !g_strcmp0(ti
->str
, "]")){
848 if( !g_strcmp0(ti
->str
, "uuid")){
849 uuid
=ti
->next
->next
->str
;
850 FPRINTF(NULL
,"UUID:%s\n",uuid
);
852 if( !g_strcmp0(ti
->str
, "version")){
853 version
=ti
->next
->next
->str
;
854 FPRINTF(NULL
,"VERSION:%s\n",version
);
856 if( !g_strcmp0(ti
->str
, "pointer_default")){
857 if(!g_strcmp0(ti
->next
->next
->str
, "unique")){
858 pointer_default
="unique";
859 } else if(!g_strcmp0(ti
->next
->next
->str
, "ptr")){
860 pointer_default
="ptr";
862 FPRINTF(stderr
, "ERROR: unknown pointer type\n");
865 FPRINTF(NULL
,"POINTER_DEFAULT:%s\n",pointer_default
);
870 FPRINTF(stderr
, "ERROR: ran out of tokens inside header\n");
874 if(g_strcmp0(token_list
->str
, "interface")){
875 FPRINTF(stderr
, "ERROR: interface not found\n");
878 token_list
=token_list
->next
;
880 FPRINTF(stderr
, "ERROR: ran out of tokens\n");
884 ifname
=token_list
->str
;
885 token_list
=token_list
->next
;
886 FPRINTF(NULL
,"Interface:%s\n",ifname
);
889 snprintf(hf_status
, BASE_BUFFER_SIZE
, "hf_%s_opnum", ifname
);
890 snprintf(filter_name
, BASE_BUFFER_SIZE
, "%s.opnum", ifname
);
891 register_hf_field(hf_status
, "Operation", filter_name
, "FT_UINT16", "BASE_DEC", "NULL", "0", "");
894 snprintf(hf_status
, BASE_BUFFER_SIZE
, "hf_%s_rc", ifname
);
895 snprintf(filter_name
, BASE_BUFFER_SIZE
, "%s.rc", ifname
);
896 register_hf_field(hf_status
, "Return code", filter_name
, "FT_UINT32", "BASE_HEX|BASE_EXT_STRING", "&NT_errors_ext", "0", "");
898 FPRINTF(eth_ett
, "static int ett_%s;\n", ifname
);
899 FPRINTF(eth_ettarr
, " &ett_%s,\n", ifname
);
901 /* the body must start with { */
902 if(g_strcmp0(token_list
->str
, "{")){
903 FPRINTF(stderr
, "ERROR: body does not start with '{'\n");
907 /* skip the initial '{' */
908 token_list
=token_list
->next
;
911 FPRINTF(stderr
, "ERROR: no uuid found\n");
914 FPRINTF(eth_code
,"static e_guid_t uuid_dcerpc_%s = {\n", ifname
);
915 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]);
916 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]);
917 FPRINTF(eth_code
,"};\n");
918 FPRINTF(eth_code
,"\n");
920 sscanf(version
, "%d.%d", &major
, &minor
);
921 FPRINTF(eth_code
,"static uint16_t ver_%s = %d;\n", ifname
, major
);
922 FPRINTF(eth_code
,"\n");
924 FPRINTF(eth_handoff
, " dcerpc_init_uuid(proto_%s, ett_%s,\n", ifname
, ifname
);
925 FPRINTF(eth_handoff
, " &uuid_dcerpc_%s, ver_%s,\n", ifname
, ifname
);
926 FPRINTF(eth_handoff
, " function_dissectors, hf_%s_opnum);\n", ifname
);
931 /* this helper function is called by the tokenizer and will just append the
932 current token to the linked list
934 static void pushtoken(char *token
)
936 token_item_t
*new_token_item
;
937 new_token_item
=g_new0(token_item_t
, 1);
938 if (!new_token_item
) {
939 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
942 new_token_item
->next
=NULL
;
943 new_token_item
->str
=token
;
945 token_list
=new_token_item
;
947 last_token_item
->next
=new_token_item
;
949 last_token_item
=new_token_item
;
952 /* this function reads the idl file and translates it into tokens.
953 the tokens are stored in a linked list token_list of type token_item_t
955 static void tokenize(FILE *fh
)
958 int fullinecomment
=0;
961 char qs
[4 * BASE_BUFFER_SIZE
];
964 char token
[4 * BASE_BUFFER_SIZE
];
970 /* full line comment */
972 if( (ch
=='\n')||(ch
=='\r') ){
978 if( (ch
=='#')&&(linepos
==0) ){
984 if(normalcomment
==0){
1013 pushtoken(g_strdup(qs
));
1016 qs
[qspos
++]=(char)ch
;
1035 pushtoken(g_strdup(token
));
1047 pushtoken(g_strdup(token
));
1061 pushtoken(g_strdup(token
));
1065 pushtoken(g_strdup(token
));
1072 token
[tokenpos
++]=(char)ch
;
1073 line
[linepos
++]=(char)ch
;
1081 static type_item_t
*
1082 find_type(char *name
)
1084 type_item_t
*tmptype
;
1085 for(tmptype
=type_list
;tmptype
;tmptype
=tmptype
->next
){
1086 if(!g_strcmp0(tmptype
->name
, name
)){
1090 /* autogenerate built in types */
1092 char dissectorname
[DISSECTORNAME_MAXLEN
];
1093 if(!g_strcmp0(name
,"uint16")){
1094 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1095 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1096 FPRINTF(eth_code
, "\n");
1097 FPRINTF(eth_code
, "static int\n");
1098 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1099 FPRINTF(eth_code
, "{\n");
1100 FPRINTF(eth_code
, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1101 FPRINTF(eth_code
, " return offset;\n");
1102 FPRINTF(eth_code
, "}\n");
1103 FPRINTF(eth_code
, "\n");
1104 tmptype
=register_new_type("uint16", dissectorname
, "FT_UINT16", "BASE_DEC", "0", "NULL", 2);
1105 } else if(!g_strcmp0(name
,"int16")){
1106 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1107 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1108 FPRINTF(eth_code
, "\n");
1109 FPRINTF(eth_code
, "static int\n");
1110 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1111 FPRINTF(eth_code
, "{\n");
1112 FPRINTF(eth_code
, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1113 FPRINTF(eth_code
, " return offset;\n");
1114 FPRINTF(eth_code
, "}\n");
1115 FPRINTF(eth_code
, "\n");
1116 tmptype
=register_new_type("int16", dissectorname
, "FT_INT16", "BASE_DEC", "0", "NULL", 2);
1117 } else if(!g_strcmp0(name
,"uint32")){
1118 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1119 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1120 FPRINTF(eth_code
, "\n");
1121 FPRINTF(eth_code
, "static int\n");
1122 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1123 FPRINTF(eth_code
, "{\n");
1124 FPRINTF(eth_code
, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1125 FPRINTF(eth_code
, " return offset;\n");
1126 FPRINTF(eth_code
, "}\n");
1127 FPRINTF(eth_code
, "\n");
1128 tmptype
=register_new_type("uint32", dissectorname
, "FT_UINT32", "BASE_DEC", "0", "NULL", 4);
1129 } else if( (!g_strcmp0(name
,"int32"))
1130 || (!g_strcmp0(name
,"long")) ){
1131 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1132 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1133 FPRINTF(eth_code
, "\n");
1134 FPRINTF(eth_code
, "static int\n");
1135 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1136 FPRINTF(eth_code
, "{\n");
1137 FPRINTF(eth_code
, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1138 FPRINTF(eth_code
, " return offset;\n");
1139 FPRINTF(eth_code
, "}\n");
1140 FPRINTF(eth_code
, "\n");
1141 if (!g_strcmp0(name
,"int32"))
1142 tmptype
=register_new_type("int32", dissectorname
, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
1144 tmptype
=register_new_type("long", dissectorname
, "FT_INT32", "BASE_DEC", "0", "NULL", 4);
1145 } else if( (!g_strcmp0(name
,"uint8")) ){
1146 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1147 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1148 FPRINTF(eth_code
, "\n");
1149 FPRINTF(eth_code
, "static int\n");
1150 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1151 FPRINTF(eth_code
, "{\n");
1152 FPRINTF(eth_code
, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1153 FPRINTF(eth_code
, " return offset;\n");
1154 FPRINTF(eth_code
, "}\n");
1155 FPRINTF(eth_code
, "\n");
1156 tmptype
=register_new_type("uint8", dissectorname
, "FT_UINT8", "BASE_DEC", "0", "NULL", 1);
1157 } else if( (!g_strcmp0(name
,"int8"))
1158 || (!g_strcmp0(name
, "char")) ){
1159 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1160 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1161 FPRINTF(eth_code
, "\n");
1162 FPRINTF(eth_code
, "static int\n");
1163 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1164 FPRINTF(eth_code
, "{\n");
1165 FPRINTF(eth_code
, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1166 FPRINTF(eth_code
, " return offset;\n");
1167 FPRINTF(eth_code
, "}\n");
1168 FPRINTF(eth_code
, "\n");
1169 if (!g_strcmp0(name
,"int8"))
1170 tmptype
=register_new_type("int8", dissectorname
, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1172 tmptype
=register_new_type("char", dissectorname
, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1173 } else if(!g_strcmp0(name
,"bool8")){
1174 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1175 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1176 FPRINTF(eth_code
, "\n");
1177 FPRINTF(eth_code
, "static int\n");
1178 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1179 FPRINTF(eth_code
, "{\n");
1180 FPRINTF(eth_code
, " offset=dissect_ndr_uint8(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1181 FPRINTF(eth_code
, " return offset;\n");
1182 FPRINTF(eth_code
, "}\n");
1183 FPRINTF(eth_code
, "\n");
1184 tmptype
=register_new_type("bool8", dissectorname
, "FT_INT8", "BASE_DEC", "0", "NULL", 1);
1185 } else if(!g_strcmp0(name
,"unistr")){
1186 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1187 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1188 FPRINTF(eth_code
, "\n");
1189 FPRINTF(eth_code
, "static int\n");
1190 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1191 FPRINTF(eth_code
, "{\n");
1192 FPRINTF(eth_code
, " offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, di, drep, 2, hf_index, false, NULL);\n");
1193 FPRINTF(eth_code
, " return offset;\n");
1194 FPRINTF(eth_code
, "}\n");
1195 FPRINTF(eth_code
, "\n");
1196 tmptype
=register_new_type("unistr", dissectorname
, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1197 } else if(!g_strcmp0(name
,"ascstr")){
1198 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1199 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1200 FPRINTF(eth_code
, "\n");
1201 FPRINTF(eth_code
, "static int\n");
1202 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1203 FPRINTF(eth_code
, "{\n");
1204 FPRINTF(eth_code
, " offset=dissect_ndr_cvstring(tvb, offset, pinfo, tree, di, drep, 1, hf_index, false, NULL);\n");
1205 FPRINTF(eth_code
, " return offset;\n");
1206 FPRINTF(eth_code
, "}\n");
1207 FPRINTF(eth_code
, "\n");
1208 tmptype
=register_new_type("ascstr", dissectorname
, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1209 } else if(!g_strcmp0(name
,"GUID")
1210 ||!g_strcmp0(name
,"uuid_t")){
1211 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1212 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1213 FPRINTF(eth_code
, "\n");
1214 FPRINTF(eth_code
, "static int\n");
1215 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1216 FPRINTF(eth_code
, "{\n");
1217 FPRINTF(eth_code
, " offset=dissect_ndr_uuid_t(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1218 FPRINTF(eth_code
, " return offset;\n");
1219 FPRINTF(eth_code
, "}\n");
1220 FPRINTF(eth_code
, "\n");
1221 tmptype
=register_new_type(name
, dissectorname
, "FT_GUID", "BASE_NONE", "0", "NULL", 4);
1222 } else if(!g_strcmp0(name
,"policy_handle")){
1223 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1224 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1225 FPRINTF(eth_code
, "\n");
1226 FPRINTF(eth_code
, "static e_ctx_hnd policy_hnd;\n");
1227 FPRINTF(eth_code
, "static proto_item *hnd_item;\n");
1228 FPRINTF(eth_code
, "\n");
1229 FPRINTF(eth_code
, "static int\n");
1230 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param)\n", dissectorname
);
1231 FPRINTF(eth_code
, "{\n");
1232 FPRINTF(eth_code
, " offset = dissect_nt_policy_hnd(tvb, offset, pinfo, tree, di, drep,\n");
1233 FPRINTF(eth_code
, " hf_index, &policy_hnd, &hnd_item,\n");
1234 FPRINTF(eth_code
, " param);\n");
1236 FPRINTF(eth_code
, " return offset;\n");
1237 FPRINTF(eth_code
, "}\n");
1238 FPRINTF(eth_code
, "\n");
1239 tmptype
=register_new_type("policy_handle", dissectorname
, "FT_BYTES", "BASE_NONE", "0", "NULL", 4);
1240 } else if(!g_strcmp0(name
,"NTTIME")){
1241 /* 8 bytes, aligned to 4 bytes */
1242 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1243 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1244 FPRINTF(eth_code
, "\n");
1245 FPRINTF(eth_code
, "static int\n");
1246 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1247 FPRINTF(eth_code
, "{\n");
1248 FPRINTF(eth_code
, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, 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", dissectorname
, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1255 } else if(!g_strcmp0(name
,"NTTIME_hyper")){
1256 /* 8 bytes, aligned to 8 bytes */
1257 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%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, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1262 FPRINTF(eth_code
, "{\n");
1263 FPRINTF(eth_code
, " ALIGN_TO_8_BYTES;\n");
1264 FPRINTF(eth_code
, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, hf_index);\n");
1266 FPRINTF(eth_code
, "\n");
1267 FPRINTF(eth_code
, " return offset;\n");
1268 FPRINTF(eth_code
, "}\n");
1269 FPRINTF(eth_code
, "\n");
1270 tmptype
=register_new_type("NTTIME_hyper", dissectorname
, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1271 } else if(!g_strcmp0(name
,"NTTIME_1sec")){
1272 /* 8 bytes, aligned to 8 bytes */
1273 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1274 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1275 FPRINTF(eth_code
, "\n");
1276 FPRINTF(eth_code
, "static int\n");
1277 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1278 FPRINTF(eth_code
, "{\n");
1279 FPRINTF(eth_code
, " ALIGN_TO_8_BYTES;\n");
1280 FPRINTF(eth_code
, " offset = dissect_ndr_nt_NTTIME(tvb, offset, pinfo, tree, di, drep, hf_index);\n");
1282 FPRINTF(eth_code
, "\n");
1283 FPRINTF(eth_code
, " return offset;\n");
1284 FPRINTF(eth_code
, "}\n");
1285 FPRINTF(eth_code
, "\n");
1286 tmptype
=register_new_type("NTTIME_1sec", dissectorname
, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1287 } else if(!g_strcmp0(name
,"udlong")){
1288 /* 8 bytes, aligned to 4 bytes */
1289 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1290 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1291 FPRINTF(eth_code
, "\n");
1292 FPRINTF(eth_code
, "static int\n");
1293 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1294 FPRINTF(eth_code
, "{\n");
1295 FPRINTF(eth_code
, "\n");
1296 FPRINTF(eth_code
, " offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1297 FPRINTF(eth_code
, "\n");
1298 FPRINTF(eth_code
, " return offset;\n");
1299 FPRINTF(eth_code
, "}\n");
1300 FPRINTF(eth_code
, "\n");
1301 tmptype
=register_new_type("udlong", dissectorname
, "FT_UINT64", "BASE_DEC", "0", "NULL", 4);
1302 } else if(!g_strcmp0(name
,"dlong")){
1303 /* 8 bytes, aligned to 4 bytes */
1304 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1305 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1306 FPRINTF(eth_code
, "\n");
1307 FPRINTF(eth_code
, "static int\n");
1308 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1309 FPRINTF(eth_code
, "{\n");
1310 FPRINTF(eth_code
, "\n");
1311 FPRINTF(eth_code
, " offset=dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1312 FPRINTF(eth_code
, "\n");
1313 FPRINTF(eth_code
, " return offset;\n");
1314 FPRINTF(eth_code
, "}\n");
1315 FPRINTF(eth_code
, "\n");
1316 tmptype
=register_new_type("dlong", dissectorname
, "FT_INT64", "BASE_DEC", "0", "NULL", 4);
1317 } else if(!g_strcmp0(name
,"uint64")){
1318 /* 8 bytes, aligned to 8 bytes */
1319 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1320 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1321 FPRINTF(eth_code
, "\n");
1322 FPRINTF(eth_code
, "static int\n");
1323 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1324 FPRINTF(eth_code
, "{\n");
1325 FPRINTF(eth_code
, " \n");
1326 FPRINTF(eth_code
, " ALIGN_TO_8_BYTES;\n");
1327 FPRINTF(eth_code
, " offset=dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1328 FPRINTF(eth_code
, "\n");
1329 FPRINTF(eth_code
, " return offset;\n");
1330 FPRINTF(eth_code
, "}\n");
1331 FPRINTF(eth_code
, "\n");
1332 tmptype
=register_new_type("uint64", dissectorname
, "FT_UINT64", "BASE_DEC", "0", "NULL", 8);
1333 } else if(!g_strcmp0(name
,"time_t")){
1334 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1335 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1336 FPRINTF(eth_code
, "\n");
1337 FPRINTF(eth_code
, "static int\n");
1338 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1339 FPRINTF(eth_code
, "{\n");
1340 FPRINTF(eth_code
, "\n");
1341 FPRINTF(eth_code
, " offset=dissect_ndr_time_t(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1342 FPRINTF(eth_code
, "\n");
1343 FPRINTF(eth_code
, " return offset;\n");
1344 FPRINTF(eth_code
, "}\n");
1345 FPRINTF(eth_code
, "\n");
1346 tmptype
=register_new_type("time_t", dissectorname
, "FT_ABSOLUTE_TIME", "ABSOLUTE_TIME_LOCAL", "0", "NULL", 4);
1347 } else if(!g_strcmp0(name
,"SID")){
1348 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1349 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1350 FPRINTF(eth_code
, "\n");
1351 FPRINTF(eth_code
, "static int\n");
1352 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param)\n", dissectorname
);
1353 FPRINTF(eth_code
, "{\n");
1354 FPRINTF(eth_code
, " offset=dissect_ndr_nt_SID_with_options(tvb, offset, pinfo, tree, di, drep, param, hf_index);\n");
1355 FPRINTF(eth_code
, " return offset;\n");
1356 FPRINTF(eth_code
, "}\n");
1357 FPRINTF(eth_code
, "\n");
1358 tmptype
=register_new_type("SID", dissectorname
, "FT_STRING", "BASE_NONE", "0", "NULL", 4);
1359 } else if(!g_strcmp0(name
,"WERROR")){
1360 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, name
);
1361 FPRINTF(NULL
,"\nAutogenerating built-in type:%s\n------------\n",name
);
1362 FPRINTF(eth_code
, "\n");
1363 FPRINTF(eth_code
, "static int\n");
1364 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
1365 FPRINTF(eth_code
, "{\n");
1366 FPRINTF(eth_code
, " \n");
1367 FPRINTF(eth_code
, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
1368 FPRINTF(eth_code
, "\n");
1369 FPRINTF(eth_code
, " return offset;\n");
1370 FPRINTF(eth_code
, "}\n");
1371 FPRINTF(eth_code
, "\n");
1372 tmptype
=register_new_type("WERROR", dissectorname
, "FT_UINT32", "BASE_DEC|BASE_EXT_STRING", "0", "&WERR_errors_ext", 4);
1380 /* this function will skip past an entire declare ... ; statement */
1381 static void skipdeclare(void)
1385 /* first must be the keyword const */
1387 if(strncmp(ti
->str
, "declare", 7)){
1388 FPRINTF(stderr
, "ERROR: skipdeclare first token is not 'declare'\n");
1391 while(ti
->str
[0] != ';'){
1399 /* this function will parse a
1401 and generate the appropriate code
1402 const must be followed by a suitable keyword [uint16|uint32|...]
1403 the const will later be g_removed from the token list
1404 the function assumes that the const is the first object in the token_list
1406 static void parseconst(void)
1411 /* first must be the keyword const */
1413 if(strncmp(ti
->str
, "const", 5)){
1414 FPRINTF(stderr
, "ERROR: const first token is not 'const'\n");
1419 /* just skip second token */
1422 /* third is a variable and not a type */
1423 if(find_type(ti
->str
)){
1424 FPRINTF(stderr
, "ERROR: const, not a variable name:%s\n", ti
->str
);
1431 if(ti
->str
[0] != '='){
1432 FPRINTF(stderr
, "ERROR: const fourth token is not '='\n");
1437 /* fifth is the value */
1442 if(ti
->str
[0] != ';'){
1443 FPRINTF(stderr
, "ERROR: const sixth token is not ';'\n");
1448 FPRINTF(NULL
,"\nCONST:%s\n-------\n",name
);
1450 FPRINTF(eth_hdr
, "#define %s %s\n", name
, value
);
1452 FPRINTF(NULL
,"\n----------\nEND CONST:%s\n",name
);
1457 /* this function will parse a
1459 construct and generate the appropriate code.
1460 the typedef will be g_removed from the token_list once it has been processed
1461 the function assumes that the typedef is the first object in the token_list
1462 the function will be called twice, once with pass=0 and once with pass=1
1463 which controls whether subdissectors are to be generated or whether the
1464 struct dissector itself is to be generated
1466 static void parsetypedefstruct(int pass
)
1468 token_item_t
*ti
, *tmpti
;
1470 char dissectorname
[DISSECTORNAME_MAXLEN
];
1471 char tmpstr
[BASE_BUFFER_SIZE
], *ptmpstr
;
1472 int level
, num_pointers
;
1473 static int alignment
;
1474 type_item_t
*type_item
;
1475 char hf_index
[BASE_BUFFER_SIZE
];
1476 bracket_item_t
*bi
=NULL
;
1478 const char *pointer_type
;
1480 uint32_t fixed_array_size
;
1481 int is_array_of_pointers
;
1482 int empty_struct
= 0;
1485 if(g_strcmp0(ti
->str
, "typedef")){
1486 FPRINTF(stderr
, "ERROR: typedefstruct first token is not 'typedef'\n");
1491 if(!g_strcmp0(ti
->str
, "[")){
1492 ti
=parsebrackets(ti
, &bi
);
1494 /* check that we know how to handle the bracket thing */
1497 FPRINTF(stderr
, "ERROR: typedefstruct unknown bracket flags encountered : 0x%08x\n",bi
->flags
);
1502 if(g_strcmp0(ti
->str
, "struct")){
1503 FPRINTF(stderr
, "ERROR: typedefstruct second token is not 'struct'\n");
1508 if(g_strcmp0(ti
->str
, "{")){
1509 FPRINTF(stderr
, "ERROR: typedefstruct third token is not '{'\n");
1514 /* Check if the struct is empty (search if there is no end bracket) */
1515 if(g_strcmp0(ti
->str
, "}") == 0){
1519 /* search forward until the '}' so we can find the name of the struct */
1520 for(tmpti
=ti
,level
=0;tmpti
;tmpti
=tmpti
->next
){
1521 if(!g_strcmp0(tmpti
->str
, "{")){
1525 if(!g_strcmp0(tmpti
->str
, "}")){
1533 if(!tmpti
|| !tmpti
->next
){
1534 FPRINTF(stderr
, "ERROR: typedefstruct missing matching '}'\n");
1538 struct_name
=tmpti
->next
->str
;
1539 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, struct_name
);
1541 FPRINTF(NULL
,"\nSTRUCT:%s pass:%d\n-------\n",struct_name
,pass
);
1543 if(!check_if_to_emit(dissectorname
)){
1544 FPRINTF(NULL
,"NOEMIT Skipping this struct dissector.\n");
1546 goto typedef_struct_finished
;
1549 /* this is pass 0 so reset alignment to zero and update as items are
1550 processed. we need alignment when pass 1 is run.
1551 set alignment initially to 1 so we don't fail for empty structs
1556 /* pass 1 generate header for the struct dissector */
1558 FPRINTF(eth_ett
, "static int ett_%s_%s;\n", ifname
, struct_name
);
1559 FPRINTF(eth_ettarr
, " &ett_%s_%s,\n", ifname
, struct_name
);
1560 FPRINTF(eth_hdr
, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param);\n", dissectorname
);
1561 FPRINTF(eth_code
, "\n");
1562 FPRINTF(eth_code
, "int\n");
1563 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *parent_tree, dcerpc_info *di _U_, uint8_t *drep _U_, int hf_index, uint32_t param _U_)\n", dissectorname
);
1564 FPRINTF(eth_code
, "{\n");
1565 FPRINTF(eth_code
, " proto_item *item=NULL;\n");
1567 FPRINTF(eth_code
, " proto_tree *tree=NULL;\n");
1569 FPRINTF(eth_code
, " int old_offset;\n");
1570 FPRINTF(eth_code
, "\n");
1575 FPRINTF(eth_code
, " ALIGN_TO_2_BYTES;\n");
1576 FPRINTF(eth_code
, "\n");
1579 FPRINTF(eth_code
, " ALIGN_TO_4_BYTES;\n");
1580 FPRINTF(eth_code
, "\n");
1583 FPRINTF(eth_code
, " ALIGN_TO_8_BYTES;\n");
1584 FPRINTF(eth_code
, "\n");
1587 FPRINTF(stderr
, "ERROR: can not handle alignment:%d\n",alignment
);
1590 FPRINTF(eth_code
, " old_offset=offset;\n");
1591 FPRINTF(eth_code
, " if(parent_tree){\n");
1592 FPRINTF(eth_code
, " item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, -1, ENC_NA);\n");
1594 FPRINTF(eth_code
, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname
, struct_name
);
1596 FPRINTF(eth_code
, " }\n");
1597 FPRINTF(eth_code
, "\n");
1600 /* scan the struct and create all subdissectors */
1603 if(!g_strcmp0(ti
->str
, "{")){
1608 if(!g_strcmp0(ti
->str
, "}")){
1616 if(!g_strcmp0(ti
->str
, "[")){
1617 ti
=parsebrackets(ti
, &bi
);
1621 /* check that we know how to handle the bracket thing */
1623 if(bi
->flags
&(~(BI_SIZE_IS
|BI_LENGTH_IS
|BI_POINTER
))){
1624 FPRINTF(stderr
, "ERROR: typedefstruct unknown bracket flags encountered : 0x%08x\n",bi
->flags
);
1629 /* handle the type, verify that we KNOW this type */
1630 type_item
=find_type(ti
->str
);
1632 FPRINTF(stderr
, "ERROR : typedefstruct unknown type %s\n",ti
->str
);
1636 /* count the levels of pointers */
1637 for(num_pointers
=0;!g_strcmp0(ti
->str
, "*");ti
=ti
->next
){
1639 /* pointers are aligned at 4 byte boundaries */
1644 /* now that we know how many real pointers there were we must
1645 prepend default pointers to the list so it has the right
1648 pi
=prepend_pointer_list(bi
?bi
->pointer_list
:NULL
, num_pointers
);
1649 /* keep track of alignment */
1650 if(alignment
<type_item
->alignment
){
1651 alignment
=type_item
->alignment
;
1657 /* see if it is a fixed array */
1659 is_array_of_pointers
=0;
1660 if(!g_strcmp0(ti
->str
, "[")){
1661 /* this might be a fixed array */
1664 if(!g_strcmp0("]", ti
->str
)){
1665 /* this is just a normal [] array */
1667 } else if(!g_strcmp0("*", ti
->str
)){
1668 pi
=prepend_pointer_list(pi
, num_pointers
+1);
1670 is_array_of_pointers
=1;
1672 } else if (!ws_strtou32(ti
->str
, NULL
, &fixed_array_size
)) {
1673 FPRINTF(stderr
, "ERROR: invalid integer: %s\n", ti
->str
);
1679 if(g_strcmp0(ti
->str
, "]")){
1680 FPRINTF(stderr
, "ERROR: typedefstruct fixed array does not end with ']' it ended with %s\n",ti
->str
);
1686 snprintf(hf_index
, BASE_BUFFER_SIZE
, "hf_%s_%s_%s", ifname
, struct_name
, field_name
);
1687 /* pass 0 generate subdissectors */
1689 char filter_name
[BASE_BUFFER_SIZE
];
1692 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_dissect_%s_%s", ifname
, struct_name
, field_name
);
1693 ptmpstr
=g_strdup(tmpstr
);
1695 if(check_if_to_emit(tmpstr
)){
1696 snprintf(filter_name
, BASE_BUFFER_SIZE
, "%s.%s.%s", ifname
, struct_name
, field_name
);
1697 hf
=register_hf_field(hf_index
, field_name
, filter_name
, type_item
->ft_type
, type_item
->base_type
, type_item
->vals
, type_item
->mask
, "");
1698 FPRINTF(eth_code
, "static int\n");
1699 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", ptmpstr
);
1700 FPRINTF(eth_code
, "{\n");
1701 FPRINTF(eth_code
, " uint32_t param=%s;\n",find_dissector_param_value(ptmpstr
));
1702 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep, %s, param);\n", type_item
->dissector
, hf
);
1703 FPRINTF(eth_code
, " return offset;\n");
1704 FPRINTF(eth_code
, "}\n");
1705 FPRINTF(eth_code
, "\n");
1707 FPRINTF(NULL
,"NOEMIT Skipping this struct item :%s\n",tmpstr
);
1710 if(is_array_of_pointers
){
1711 pointer_type
=pi
->type
;
1713 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", pointer_type
, ptmpstr
);
1714 if(check_if_to_emit(tmpstr
)){
1715 FPRINTF(eth_code
, "static int\n");
1716 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
1717 FPRINTF(eth_code
, "{\n");
1718 FPRINTF(eth_code
, " offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, di, drep, %s, %s, \"%s\", -1);\n", ptmpstr
, ptr_to_define(pointer_type
), field_name
);
1719 FPRINTF(eth_code
, " return offset;\n");
1720 FPRINTF(eth_code
, "}\n");
1721 FPRINTF(eth_code
, "\n");
1723 FPRINTF(NULL
,"NOEMIT Skipping this struct item :%s\n",tmpstr
);
1726 ptmpstr
=g_strdup(tmpstr
);
1727 } else if(fixed_array_size
){
1728 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "fixedarray_%s", ptmpstr
);
1729 if(check_if_to_emit(tmpstr
)){
1730 FPRINTF(eth_code
, "static int\n");
1731 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
1732 FPRINTF(eth_code
, "{\n");
1733 FPRINTF(eth_code
, " int count=%d;\n",fixed_array_size
);
1734 FPRINTF(eth_code
, " while(count--){\n");
1735 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr
);
1736 FPRINTF(eth_code
, " }\n");
1737 FPRINTF(eth_code
, "\n");
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
=g_strdup(tmpstr
);
1747 /* handle switch_is */
1749 switch(bi
->flags
&(BI_SIZE_IS
|BI_LENGTH_IS
)){
1753 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucarray_%s", ptmpstr
);
1754 if(check_if_to_emit(tmpstr
)){
1755 FPRINTF(eth_code
, "static int\n");
1756 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
1757 FPRINTF(eth_code
, "{\n");
1758 FPRINTF(eth_code
, " offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr
);
1759 FPRINTF(eth_code
, " return offset;\n");
1760 FPRINTF(eth_code
, "}\n");
1761 FPRINTF(eth_code
, "\n");
1763 FPRINTF(NULL
,"NOEMIT Skipping this struct item :%s\n",tmpstr
);
1765 ptmpstr
=g_strdup(tmpstr
);
1768 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "uvarray_%s", ptmpstr
);
1769 if(check_if_to_emit(tmpstr
)){
1770 FPRINTF(eth_code
, "static int\n");
1771 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
1772 FPRINTF(eth_code
, "{\n");
1773 FPRINTF(eth_code
, " offset=dissect_ndr_uvarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr
);
1774 FPRINTF(eth_code
, " return offset;\n");
1775 FPRINTF(eth_code
, "}\n");
1776 FPRINTF(eth_code
, "\n");
1778 FPRINTF(NULL
,"NOEMIT Skipping this struct item :%s\n",tmpstr
);
1780 ptmpstr
=g_strdup(tmpstr
);
1782 case BI_SIZE_IS
|BI_LENGTH_IS
:
1783 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucvarray_%s", ptmpstr
);
1784 if(check_if_to_emit(tmpstr
)){
1785 FPRINTF(eth_code
, "static int\n");
1786 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
1787 FPRINTF(eth_code
, "{\n");
1788 FPRINTF(eth_code
, " offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr
);
1789 FPRINTF(eth_code
, " return offset;\n");
1790 FPRINTF(eth_code
, "}\n");
1791 FPRINTF(eth_code
, "\n");
1793 FPRINTF(NULL
,"NOEMIT Skipping this struct item :%s\n",tmpstr
);
1795 ptmpstr
=g_strdup(tmpstr
);
1798 FPRINTF(stderr
, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
1803 /* handle pointers */
1804 while(num_pointers
--){
1805 pointer_type
=pi
->type
;
1807 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", pointer_type
, ptmpstr
);
1808 if(check_if_to_emit(tmpstr
)){
1809 FPRINTF(eth_code
, "static int\n");
1810 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
1811 FPRINTF(eth_code
, "{\n");
1812 FPRINTF(eth_code
, " offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, di, drep, %s, %s, \"%s\", -1);\n", ptmpstr
, ptr_to_define(pointer_type
), field_name
);
1813 FPRINTF(eth_code
, " return offset;\n");
1814 FPRINTF(eth_code
, "}\n");
1815 FPRINTF(eth_code
, "\n");
1817 FPRINTF(NULL
,"NOEMIT Skipping this struct item :%s\n",tmpstr
);
1820 ptmpstr
=g_strdup(tmpstr
);
1825 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_dissect_%s_%s", ifname
, struct_name
, field_name
);
1826 ptmpstr
=g_strdup(tmpstr
);
1828 /* handle fixedsizearrays */
1829 if(is_array_of_pointers
){
1830 pointer_type
=pi
->type
;
1832 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", pointer_type
, ptmpstr
);
1833 ptmpstr
=g_strdup(tmpstr
);
1834 } else if(fixed_array_size
){
1835 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "fixedarray_%s", ptmpstr
);
1836 ptmpstr
=g_strdup(tmpstr
);
1839 /* handle switch_is */
1841 switch(bi
->flags
&(BI_SIZE_IS
|BI_LENGTH_IS
)){
1845 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucarray_%s", ptmpstr
);
1846 ptmpstr
=g_strdup(tmpstr
);
1849 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "uvarray_%s", ptmpstr
);
1850 ptmpstr
=g_strdup(tmpstr
);
1852 case BI_SIZE_IS
|BI_LENGTH_IS
:
1853 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucvarray_%s", ptmpstr
);
1854 ptmpstr
=g_strdup(tmpstr
);
1857 FPRINTF(stderr
, "ERROR: typedefstruct can not handle this combination of sizeis/lengthis\n");
1862 /* handle pointers */
1863 while(num_pointers
--){
1864 pointer_type
=pi
->type
;
1866 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", pointer_type
, ptmpstr
);
1867 ptmpstr
=g_strdup(tmpstr
);
1870 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr
);
1871 FPRINTF(eth_code
, "\n");
1874 if(g_strcmp0(ti
->str
,";")){
1875 FPRINTF(stderr
, "ERROR: field does not en with ';'\n");
1879 bi
=NULL
; /* clear bi before we start on the next field */
1883 FPRINTF(eth_code
, " proto_item_set_len(item, offset-old_offset);\n");
1884 FPRINTF(eth_code
, "\n");
1885 FPRINTF(eth_code
, " return offset;\n");
1886 FPRINTF(eth_code
, "}\n");
1887 register_new_type(struct_name
, dissectorname
, "FT_NONE", "BASE_NONE", "0", "NULL", alignment
);
1891 typedef_struct_finished
:
1892 FPRINTF(NULL
,"\nEND STRUCT:%s pass:%d\n-------\n",struct_name
,pass
);
1894 /* only advance token_list for pass==1
1895 ti now points to the '}' token
1898 if(!ti
|| g_strcmp0(ti
->str
,"}")){
1899 FPRINTF(stderr
, "ERROR: struct does not end with '}'\n");
1904 /* just skip the name */
1907 if(!ti
|| g_strcmp0(ti
->str
,";")){
1908 FPRINTF(stderr
, "ERROR: struct does not end with ';'\n");
1917 /* this function will parse a
1919 construct and generate the appropriate code.
1920 the typedef will be g_removed from the token_list once it has been processed
1921 the function assumes that the typedef is the first object in the token_list
1922 the function will be called twice, once with pass=0 and once with pass=1
1923 which controls whether subdissectors are to be generated or whether the
1924 bitmap dissector itself is to be generated
1926 bitmaps are by default 32 bits
1928 static void parsetypedefbitmap(int pass
)
1930 token_item_t
*ti
, *tmpti
;
1932 char dissectorname
[BASE_BUFFER_SIZE
], hf_bitname
[BASE_BUFFER_SIZE
];
1936 bracket_item_t
*bi
=NULL
;
1939 if(g_strcmp0(ti
->str
, "typedef")){
1940 FPRINTF(stderr
, "ERROR: typedefbitmap first token is not 'typedef'\n");
1945 alignment
=4; /* default size is 32 bits */
1947 if(!g_strcmp0(ti
->str
, "[")){
1948 ti
=parsebrackets(ti
, &bi
);
1950 /* check that we know how to handle the bracket thing */
1952 if(bi
->flags
&(~(BI_BITMAP32
|BI_BITMAP8
))){
1953 FPRINTF(stderr
, "ERROR: typedefbitmap unknown bracket flags encountered : 0x%08x\n",bi
->flags
);
1956 if(bi
->flags
&BI_BITMAP32
){
1959 if(bi
->flags
&BI_BITMAP8
){
1965 if(g_strcmp0(ti
->str
, "bitmap")){
1966 FPRINTF(stderr
, "ERROR: typedefbitmap second token is not 'bitmap'\n");
1971 if(g_strcmp0(ti
->str
, "{")){
1972 FPRINTF(stderr
, "ERROR: typedefbitmap third token is not '{'\n");
1977 /* search forward until the '}' so we can find the name of the bitmap */
1978 for(tmpti
=ti
;tmpti
;tmpti
=tmpti
->next
){
1979 if(!g_strcmp0(tmpti
->str
, "{")){
1980 FPRINTF(stderr
, "ERROR: typedefbitmap '{' encountered inside bitmap\n");
1983 if(!g_strcmp0(tmpti
->str
, "}")){
1987 if (!tmpti
|| !tmpti
->next
){
1988 FPRINTF(stderr
, "ERROR: typedefbitmap missing matching '}'\n");
1991 bitmap_name
=tmpti
->next
->str
;
1992 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, bitmap_name
);
1994 FPRINTF(NULL
,"\nBITMAP:%s pass:%d\n-------\n",bitmap_name
,pass
);
1996 /* pass 1 generate header for the struct dissector */
1998 FPRINTF(eth_ett
, "static int ett_%s_%s;\n", ifname
, bitmap_name
);
1999 FPRINTF(eth_ettarr
, " &ett_%s_%s,\n", ifname
, bitmap_name
);
2000 FPRINTF(eth_hdr
, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param);\n", dissectorname
);
2001 FPRINTF(eth_code
, "\n");
2002 FPRINTF(eth_code
, "int\n");
2003 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
2004 FPRINTF(eth_code
, "{\n");
2005 FPRINTF(eth_code
, " proto_item *item=NULL;\n");
2006 FPRINTF(eth_code
, " proto_tree *tree=NULL;\n");
2009 FPRINTF(eth_code
, " uint8_t flags;\n");
2010 FPRINTF(eth_code
, "\n");
2013 FPRINTF(eth_code
, " uint32_t flags;\n");
2014 FPRINTF(eth_code
, "\n");
2015 FPRINTF(eth_code
, " ALIGN_TO_4_BYTES;\n");
2018 FPRINTF(stderr
, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment
);
2021 FPRINTF(eth_code
, "\n");
2022 FPRINTF(eth_code
, " if(parent_tree){\n");
2023 FPRINTF(eth_code
, " item=proto_tree_add_item(parent_tree, hf_index, tvb, offset, %d, ENC_LITTLE_ENDIAN);\n", alignment
);
2024 FPRINTF(eth_code
, " tree=proto_item_add_subtree(item, ett_%s_%s);\n", ifname
, bitmap_name
);
2025 FPRINTF(eth_code
, " }\n");
2026 FPRINTF(eth_code
, "\n");
2029 FPRINTF(eth_code
, " offset=dissect_ndr_uint8(tvb, offset, pinfo, NULL, di, drep, -1, &flags);\n");
2030 FPRINTF(eth_code
, "\n");
2033 FPRINTF(eth_code
, " offset=dissect_ndr_uint32(tvb, offset, pinfo, NULL, di, drep, -1, &flags);\n");
2034 FPRINTF(eth_code
, "\n");
2037 FPRINTF(stderr
, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment
);
2040 FPRINTF(eth_code
, "\n");
2043 /* scan the struct and create call for all bits */
2045 if(!g_strcmp0(ti
->str
, "}")){
2048 if(!g_strcmp0(ti
->str
, "[")){
2049 FPRINTF(stderr
, "ERROR: typedefbitmap can not handle '[' yet\n");
2055 snprintf(hf_bitname
, BASE_BUFFER_SIZE
, "hf_%s_%s_%s", ifname
, bitmap_name
, name
);
2057 if(g_strcmp0(ti
->str
, "=")){
2058 FPRINTF(stderr
, "ERROR: typedefbitmap i expected a '=' here\n");
2066 if(!strncmp(value
, "0x", 2)){
2067 sscanf(value
, "0x%x", &val
);
2069 FPRINTF(stderr
, "ERROR: typedefbitmap can only handle hexadecimal constants\n");
2074 FPRINTF(stderr
, "ERROR: typedefbitmap can only handle single bit fields\n");
2079 char filter_name
[BASE_BUFFER_SIZE
], base_name
[BASE_BUFFER_SIZE
], tfs_name
[BASE_BUFFER_SIZE
];
2081 snprintf(filter_name
, BASE_BUFFER_SIZE
, "%s.%s.%s", ifname
, bitmap_name
, name
);
2082 snprintf(base_name
, BASE_BUFFER_SIZE
, "%d", alignment
*8);
2083 snprintf(tfs_name
, BASE_BUFFER_SIZE
, "TFS(&%s_tfs)", name
);
2084 register_hf_field(hf_bitname
, name
, filter_name
, "FT_BOOLEAN", base_name
, tfs_name
, value
, "");
2086 FPRINTF(eth_code
, "static const true_false_string %s_tfs = {\n",name
);
2087 FPRINTF(eth_code
, " \"%s is SET\",\n", name
);
2088 FPRINTF(eth_code
, " \"%s is NOT set\"\n", name
);
2089 FPRINTF(eth_code
, "};\n");
2090 FPRINTF(eth_code
, "\n");
2094 FPRINTF(eth_code
, " proto_tree_add_boolean(tree, %s, tvb, offset-%d, %d, flags);\n", hf_bitname
, alignment
, alignment
);
2095 FPRINTF(eth_code
, " if(flags&%s){\n", value
);
2096 FPRINTF(eth_code
, " proto_item_append_text(item, \" %s\");\n", name
);
2097 FPRINTF(eth_code
, " }\n");
2098 FPRINTF(eth_code
, " flags&=(~%s);\n", value
);
2099 FPRINTF(eth_code
, "\n");
2102 if(!g_strcmp0(ti
->str
, ",")){
2109 FPRINTF(eth_code
, " if(flags){\n");
2110 FPRINTF(eth_code
, " proto_item_append_text(item, \"UNKNOWN-FLAGS\");\n");
2111 FPRINTF(eth_code
, " }\n");
2112 FPRINTF(eth_code
, "\n");
2113 FPRINTF(eth_code
, " return offset;\n");
2114 FPRINTF(eth_code
, "}\n");
2117 register_new_type(bitmap_name
, dissectorname
, "FT_UINT8", "BASE_HEX", "0", "NULL", alignment
);
2120 register_new_type(bitmap_name
, dissectorname
, "FT_UINT32", "BASE_HEX", "0", "NULL", alignment
);
2123 FPRINTF(stderr
, "ERROR: typedefbitmap can not handle alignment:%d\n",alignment
);
2128 FPRINTF(NULL
,"\nEND BITMAP:%s pass:%d\n-------\n",bitmap_name
,pass
);
2130 /* only advance token_list for pass==1
2131 ti now points to the '}' token
2134 if(!ti
|| g_strcmp0(ti
->str
,"}")){
2135 FPRINTF(stderr
, "ERROR: bitmap does not end with '}'\n");
2140 /* just skip the name */
2143 if(!ti
|| g_strcmp0(ti
->str
,";")){
2144 FPRINTF(stderr
, "ERROR: bitmap does not end with ';'\n");
2153 /* a case tag might be a negative number, i.e. contain a '-' sign which
2154 is not valid inside a symbol name in c.
2157 case2str(const char *str
)
2163 newstr
=g_strdup(str
);
2168 /* this function will parse a
2170 construct and generate the appropriate code.
2171 the typedef will be g_removed from the token_list once it has been processed
2172 the function assumes that the typedef is the first object in the token_list
2173 the function will be called twice, once with pass=0 and once with pass=1
2174 which controls whether subdissectors are to be generated or whether the
2175 union dissector itself is to be generated
2177 static void parsetypedefunion(int pass
)
2180 token_item_t
*ti
, *tmpti
;
2181 char dissectorname
[BASE_BUFFER_SIZE
];
2182 bracket_item_t
*bi
=NULL
;
2183 char tmpstr
[BASE_BUFFER_SIZE
], *ptmpstr
;
2184 int level
, num_pointers
;
2185 static int alignment
;
2186 type_item_t
*type_item
;
2187 char hf_index
[BASE_BUFFER_SIZE
];
2188 int tag_alignment
, item_alignment
;
2191 if(g_strcmp0(ti
->str
, "typedef")){
2192 FPRINTF(stderr
, "ERROR: typedefunion first token is not 'typedef'\n");
2197 if(!g_strcmp0(ti
->str
, "[")){
2198 ti
=parsebrackets(ti
, &bi
);
2200 /* check that we know how to handle the bracket thing */
2202 if(bi
->flags
&(~(BI_SWITCH_TYPE
))){
2203 FPRINTF(stderr
, "ERROR: typedefunion unknown bracket flags encountered : 0x%08x\n",bi
->flags
);
2208 if(g_strcmp0(ti
->str
, "union")){
2209 FPRINTF(stderr
, "ERROR: typedefunion second token is not 'union'\n");
2214 if(g_strcmp0(ti
->str
, "{")){
2215 FPRINTF(stderr
, "ERROR: typedefunion third token is not '{'\n");
2220 /* search forward until the '}' so we can find the name of the union */
2221 for(tmpti
=ti
,level
=0;tmpti
;tmpti
=tmpti
->next
){
2222 if(!g_strcmp0(tmpti
->str
, "{")){
2226 if(!g_strcmp0(tmpti
->str
, "}")){
2235 if (!tmpti
|| !tmpti
->next
){
2236 FPRINTF(stderr
, "ERROR: typedefunion missing matching '}'\n");
2239 union_name
=tmpti
->next
->str
;
2240 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_union_%s", ifname
, union_name
);
2242 FPRINTF(NULL
,"\nUNION:%s pass:%d\n-------\n",union_name
,pass
);
2244 if(bi
&& bi
->flags
&BI_SWITCH_TYPE
){
2245 tag_alignment
=bi
->union_tag_size
;
2247 tag_alignment
=get_union_tag_size(union_name
);
2250 /* this is pass 0 so reset alignment to the minimum possible value
2251 and update as items are processed.
2252 we need alignment when pass 1 is run
2255 alignment
=tag_alignment
;
2258 /* pass 1 generate header for the struct dissector */
2260 FPRINTF(eth_ett
, "static int ett_%s_%s;\n", ifname
, union_name
);
2261 FPRINTF(eth_ettarr
, " &ett_%s_%s,\n", ifname
, union_name
);
2262 FPRINTF(eth_code
, "\n");
2263 FPRINTF(eth_code
, "static int\n");
2264 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent_tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
2265 FPRINTF(eth_code
, "{\n");
2266 FPRINTF(eth_code
, " proto_item *item=NULL;\n");
2267 FPRINTF(eth_code
, " proto_tree *tree=NULL;\n");
2268 FPRINTF(eth_code
, " int old_offset;\n");
2269 /* we do alignment on the tag itself here so that
2270 we skip any alignment padding prior to where the tag
2271 itself starts, this makes the byterange in the hexpane
2272 for the union expansion start with the first byte of the tag
2274 switch(tag_alignment
){
2278 FPRINTF(eth_code
, " uint16_t level;\n");
2279 FPRINTF(eth_code
, "\n");
2280 FPRINTF(eth_code
, " ALIGN_TO_2_BYTES;\n");
2281 FPRINTF(eth_code
, "\n");
2284 FPRINTF(eth_code
, " uint32_t level = 0;\n");
2285 FPRINTF(eth_code
, "\n");
2286 FPRINTF(eth_code
, " ALIGN_TO_4_BYTES;\n");
2287 FPRINTF(eth_code
, "\n");
2290 FPRINTF(stderr
, "ERROR: typedefunion 1 can not handle alignment:%d\n",alignment
);
2293 FPRINTF(eth_code
, " old_offset=offset;\n");
2294 FPRINTF(eth_code
, " if(parent_tree){\n");
2295 FPRINTF(eth_code
, " tree=proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_%s_%s, &item, \"%s\");\n", ifname
, union_name
, union_name
);
2296 FPRINTF(eth_code
, " }\n");
2297 FPRINTF(eth_code
, "\n");
2298 switch(tag_alignment
){
2302 FPRINTF(eth_code
, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree,\n");
2303 FPRINTF(eth_code
, " di, drep, hf_index, &level);\n");
2306 FPRINTF(eth_code
, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree,\n");
2307 FPRINTF(eth_code
, " di, drep, hf_index, &level);\n");
2310 FPRINTF(stderr
, "ERROR: typedefunion 2 can not handle alignment:%d\n",alignment
);
2313 FPRINTF(eth_code
, "\n");
2314 FPRINTF(eth_code
, " switch(level){\n");
2317 /* scan the struct and create all subdissectors */
2320 if(!g_strcmp0(ti
->str
, "{")){
2325 if(!g_strcmp0(ti
->str
, "}")){
2333 if(!g_strcmp0(ti
->str
, "[")){
2334 ti
=parsebrackets(ti
, &bi
);
2339 FPRINTF(stderr
, "ERROR : typedefunion no brackets found for case\n");
2342 /* make sure we catch when we havent implemented everything
2344 we currently only know about CASE and CASE_DEFAULT flags
2346 if(bi
->flags
&(~(BI_CASE
|BI_CASE_DEFAULT
|BI_POINTER
))){
2347 FPRINTF(stderr
, "ERROR: typedefunion unknown bracket flags encountered : 0x%08x\n",bi
->flags
);
2350 if(!(bi
->flags
&BI_CASE
)){
2351 FPRINTF(stderr
, "ERROR : typedefunion no case found in brackets\n");
2355 /* only empty default cases for now */
2356 if(bi
->flags
&BI_CASE_DEFAULT
){
2357 if(g_strcmp0(ti
->str
,";")){
2358 FPRINTF(stderr
, "ERROR: default tag is not empty\n");
2366 /* just skip all and any 'empty' arms */
2367 if(!g_strcmp0(ti
->str
, ";")){
2372 /* handle the type, verify that we KNOW this type */
2373 type_item
=find_type(ti
->str
);
2375 FPRINTF(stderr
, "ERROR : typedefunion unknown type %s\n",ti
->str
);
2379 /* count the levels of pointers */
2380 for(num_pointers
=0;!g_strcmp0(ti
->str
, "*");ti
=ti
->next
){
2384 /* keep track of alignment */
2388 item_alignment
=type_item
->alignment
;
2390 if(alignment
<item_alignment
){
2391 alignment
=item_alignment
;
2394 snprintf(hf_index
, BASE_BUFFER_SIZE
, "hf_%s_%s_%s_%s", ifname
, union_name
, case2str(bi
->case_name
), ti
->str
);
2395 /* pass 0 generate subdissectors */
2397 char filter_name
[BASE_BUFFER_SIZE
];
2400 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_dissect_union_%s_%s_%s", ifname
, union_name
, case2str(bi
->case_name
), ti
->str
);
2401 ptmpstr
=g_strdup(tmpstr
);
2403 snprintf(filter_name
, BASE_BUFFER_SIZE
, "%s.%s.%s", ifname
, union_name
, ti
->str
);
2404 hf
=register_hf_field(hf_index
, ti
->str
, filter_name
, type_item
->ft_type
, type_item
->base_type
, type_item
->vals
, type_item
->mask
, "");
2406 FPRINTF(eth_code
, "static int\n");
2407 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", ptmpstr
);
2408 FPRINTF(eth_code
, "{\n");
2409 FPRINTF(eth_code
, " uint32_t param=%s;\n",find_dissector_param_value(ptmpstr
));
2410 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep, %s, param);\n", type_item
->dissector
, hf
);
2411 FPRINTF(eth_code
, " return offset;\n");
2412 FPRINTF(eth_code
, "}\n");
2413 FPRINTF(eth_code
, "\n");
2415 /* handle pointers */
2416 while(num_pointers
--){
2417 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", ptmpstr
, "unique");
2418 FPRINTF(eth_code
, "static int\n");
2419 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
2420 FPRINTF(eth_code
, "{\n");
2421 FPRINTF(eth_code
, " offset=dissect_ndr_embedded_pointer(tvb, offset, pinfo, tree, di, drep, %s, NDR_POINTER_UNIQUE, \"%s\", -1);\n", ptmpstr
, ti
->str
);
2422 FPRINTF(eth_code
, " return offset;\n");
2423 FPRINTF(eth_code
, "}\n");
2424 FPRINTF(eth_code
, "\n");
2426 ptmpstr
=g_strdup(tmpstr
);
2432 /* handle pointers */
2433 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_dissect_union_%s_%s_%s", ifname
, union_name
, case2str(bi
->case_name
), ti
->str
);
2434 ptmpstr
=g_strdup(tmpstr
);
2435 while(num_pointers
--){
2436 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", ptmpstr
, "unique");
2437 ptmpstr
=g_strdup(tmpstr
);
2440 if(bi
->flags
&BI_CASE_DEFAULT
){
2441 FPRINTF(eth_code
, " default:\n");
2443 FPRINTF(eth_code
, " case %s:\n",bi
->case_name
);
2445 /* each arm itself is aligned independently */
2446 switch(item_alignment
){
2450 FPRINTF(eth_code
, " ALIGN_TO_2_BYTES;\n");
2453 FPRINTF(eth_code
, " ALIGN_TO_4_BYTES;\n");
2456 FPRINTF(eth_code
, " ALIGN_TO_8_BYTES;\n");
2459 FPRINTF(stderr
, "ERROR: typedefunion 3 can not handle alignment:%d\n",item_alignment
);
2462 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr
);
2463 FPRINTF(eth_code
, " break;\n");
2464 FPRINTF(eth_code
, "\n");
2468 if(g_strcmp0(ti
->str
,";")){
2469 FPRINTF(stderr
, "ERROR: field does not end with ';'\n");
2476 FPRINTF(eth_code
, " }\n");
2477 FPRINTF(eth_code
, "\n");
2478 FPRINTF(eth_code
, " proto_item_set_len(item, offset-old_offset);\n");
2479 FPRINTF(eth_code
, "\n");
2480 FPRINTF(eth_code
, " return offset;\n");
2481 FPRINTF(eth_code
, "}\n");
2482 switch(tag_alignment
){
2484 register_new_type(union_name
, dissectorname
, "FT_UINT16", "BASE_DEC", "0", "NULL", alignment
);
2487 register_new_type(union_name
, dissectorname
, "FT_UINT32", "BASE_DEC", "0", "NULL", alignment
);
2490 FPRINTF(stderr
, "ERROR: typedefunion 4 can not handle alignment:%d\n",alignment
);
2495 FPRINTF(NULL
,"\nEND UNION:%s pass:%d\n-------\n",union_name
,pass
);
2497 /* only advance token_list for pass==1
2498 ti now points to the '}' token
2501 if(!ti
|| g_strcmp0(ti
->str
,"}")){
2502 FPRINTF(stderr
, "ERROR: union does not end with '}'\n");
2507 /* just skip the name */
2510 if(!ti
|| g_strcmp0(ti
->str
,";")){
2511 FPRINTF(stderr
, "ERROR: union does not end with ';'\n");
2521 /* this function will parse a
2523 construct and generate the appropriate code.
2524 the function will be g_removed from the token_list once it has been processed
2525 the function assumes that the function is the first object in the token_list
2526 the function will be called three times with
2527 pass=0 generate subdissectors and entries for the function table
2528 pass=1 generate code for the REQUEST
2529 pass=2 generate code for the REPLY
2531 static void parsefunction(int pass
)
2533 char *function_name
;
2534 static int funcno
=0;
2536 bracket_item_t
*bi
=NULL
;
2538 const char *pointer_type
;
2540 char tmpstr
[BASE_BUFFER_SIZE
], *ptmpstr
;
2541 int level
, num_pointers
;
2542 type_item_t
*type_item
;
2543 char hf_index
[BASE_BUFFER_SIZE
];
2546 if(g_strcmp0(ti
->str
, "WERROR")){
2547 FPRINTF(stderr
, "ERROR: function first token is not 'WERROR'\n");
2552 function_name
=ti
->str
;
2555 if(g_strcmp0(ti
->str
, "(")){
2556 FPRINTF(stderr
, "ERROR: function third token is not '('\n");
2561 FPRINTF(NULL
,"\nFUNCTION:%s pass:%d\n-------\n",function_name
,pass
);
2564 FPRINTF(eth_ft
, " { %d, \"%s\",\n",funcno
,function_name
);
2565 FPRINTF(eth_ft
, " %s_dissect_%s_request,\n", ifname
, function_name
);
2566 FPRINTF(eth_ft
, " %s_dissect_%s_response },\n", ifname
, function_name
);
2570 /* pass 1,2 generate header for the function dissector */
2571 if((pass
==1)||(pass
==2)){
2572 FPRINTF(eth_code
, "\n");
2573 FPRINTF(eth_code
, "static int\n");
2574 FPRINTF(eth_code
, "%s_dissect_%s_%s(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, dcerpc_info* di _U_, uint8_t *drep _U_)\n", ifname
, function_name
, (pass
==1)?"request":"response");
2575 FPRINTF(eth_code
, "{\n");
2578 /* scan the struct and create all subdissectors */
2581 if(!g_strcmp0(ti
->str
, "(")){
2586 if(!g_strcmp0(ti
->str
, ")")){
2594 if(!g_strcmp0(ti
->str
, "[")){
2595 ti
=parsebrackets(ti
, &bi
);
2600 FPRINTF(stderr
, "ERROR : function no brackets found for case\n");
2604 /* make sure we catch when we havent implemented everything
2606 we currently only know about IN and OUT flags
2608 if(bi
->flags
&(~(BI_IN
|BI_OUT
|BI_POINTER
|BI_SIZE_IS
|BI_LENGTH_IS
))){
2609 FPRINTF(stderr
, "ERROR: function unknown bracket flags encountered : 0x%08x\n",bi
->flags
);
2612 if(!(bi
->flags
&(BI_IN
|BI_OUT
))){
2613 FPRINTF(stderr
, "ERROR : function parameter is neither in nor out\n");
2617 /* handle the type, verify that we KNOW this type */
2618 type_item
=find_type(ti
->str
);
2620 FPRINTF(stderr
, "ERROR : function unknown type %s\n",ti
->str
);
2624 /* count the levels of pointers */
2625 for(num_pointers
=0;!g_strcmp0(ti
->str
, "*");ti
=ti
->next
){
2629 /* now that we know how many real pointer there were we must
2630 prepend default pointers to the list so it has the right
2633 pi
=prepend_pointer_list(bi
->pointer_list
, num_pointers
);
2635 snprintf(hf_index
, BASE_BUFFER_SIZE
, "hf_%s_%s_%s", ifname
, function_name
, ti
->str
);
2636 /* pass 0 generate subdissectors */
2638 char filter_name
[BASE_BUFFER_SIZE
];
2641 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_dissect_%s_%s", ifname
, function_name
, ti
->str
);
2642 ptmpstr
=g_strdup(tmpstr
);
2644 snprintf(filter_name
, BASE_BUFFER_SIZE
, "%s.%s.%s", ifname
, function_name
, ti
->str
);
2645 hf
=register_hf_field(hf_index
, ti
->str
, filter_name
, type_item
->ft_type
, type_item
->base_type
, type_item
->vals
, type_item
->mask
, "");
2647 FPRINTF(eth_code
, "static int\n");
2648 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", ptmpstr
);
2649 FPRINTF(eth_code
, "{\n");
2650 FPRINTF(eth_code
, " uint32_t param=%s;\n",find_dissector_param_value(ptmpstr
));
2651 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep, %s, param);\n", type_item
->dissector
, hf
);
2652 FPRINTF(eth_code
, " return offset;\n");
2653 FPRINTF(eth_code
, "}\n");
2654 FPRINTF(eth_code
, "\n");
2657 /* handle switch_is */
2658 switch(bi
->flags
&(BI_SIZE_IS
|BI_LENGTH_IS
)){
2661 case BI_SIZE_IS
|BI_LENGTH_IS
:
2662 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucvarray_%s", ptmpstr
);
2663 FPRINTF(eth_code
, "static int\n");
2664 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
2665 FPRINTF(eth_code
, "{\n");
2666 FPRINTF(eth_code
, " offset=dissect_ndr_ucvarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr
);
2667 FPRINTF(eth_code
, " return offset;\n");
2668 FPRINTF(eth_code
, "}\n");
2669 FPRINTF(eth_code
, "\n");
2670 ptmpstr
=g_strdup(tmpstr
);
2673 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucarray_%s", ptmpstr
);
2674 FPRINTF(eth_code
, "static int\n");
2675 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
2676 FPRINTF(eth_code
, "{\n");
2677 FPRINTF(eth_code
, " offset=dissect_ndr_ucarray(tvb, offset, pinfo, tree, di, drep, %s);\n", ptmpstr
);
2678 FPRINTF(eth_code
, " return offset;\n");
2679 FPRINTF(eth_code
, "}\n");
2680 FPRINTF(eth_code
, "\n");
2681 ptmpstr
=g_strdup(tmpstr
);
2684 FPRINTF(stderr
, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
2688 /* handle pointers */
2689 while(num_pointers
--){
2690 pointer_type
=pi
->type
;
2692 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", pointer_type
, ptmpstr
);
2693 FPRINTF(eth_code
, "static int\n");
2694 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep)\n", tmpstr
);
2695 FPRINTF(eth_code
, "{\n");
2696 FPRINTF(eth_code
, " offset=dissect_ndr_toplevel_pointer(tvb, offset, pinfo, tree, di, drep, %s, %s, \"%s\", -1);\n", ptmpstr
, ptr_to_define(pointer_type
), ti
->str
);
2697 FPRINTF(eth_code
, " return offset;\n");
2698 FPRINTF(eth_code
, "}\n");
2699 FPRINTF(eth_code
, "\n");
2701 ptmpstr
=g_strdup(tmpstr
);
2706 if((pass
==1)||(pass
==2)){
2707 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_dissect_%s_%s", ifname
, function_name
, ti
->str
);
2708 ptmpstr
=g_strdup(tmpstr
);
2710 switch(bi
->flags
&(BI_SIZE_IS
|BI_LENGTH_IS
)){
2713 case BI_SIZE_IS
|BI_LENGTH_IS
:
2714 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucvarray_%s", ptmpstr
);
2715 ptmpstr
=g_strdup(tmpstr
);
2718 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "ucarray_%s", ptmpstr
);
2719 ptmpstr
=g_strdup(tmpstr
);
2722 FPRINTF(stderr
, "ERROR: typedeffunction can not handle this combination of sizeis/lengthis\n");
2726 /* handle pointers */
2727 while(num_pointers
--){
2728 pointer_type
=pi
->type
;
2730 snprintf(tmpstr
, BASE_BUFFER_SIZE
, "%s_%s", pointer_type
, ptmpstr
);
2731 ptmpstr
=g_strdup(tmpstr
);
2734 if((pass
==1)&&(bi
->flags
&BI_IN
)){
2735 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr
);
2736 FPRINTF(eth_code
, " offset=dissect_deferred_pointers(pinfo, tvb, offset, di, drep);\n");
2737 FPRINTF(eth_code
, "\n");
2739 if((pass
==2)&&(bi
->flags
&BI_OUT
)){
2740 FPRINTF(eth_code
, " offset=%s(tvb, offset, pinfo, tree, di, drep);\n", ptmpstr
);
2741 FPRINTF(eth_code
, " offset=dissect_deferred_pointers(pinfo, tvb, offset, di, drep);\n");
2742 FPRINTF(eth_code
, "\n");
2748 if(!g_strcmp0(ti
->str
,",")){
2754 if((pass
==1)||(pass
==2)){
2756 FPRINTF(eth_code
, " offset=dissect_ntstatus(tvb, offset, pinfo, tree, di, drep, %s, NULL);\n", hf_status
);
2757 FPRINTF(eth_code
, "\n");
2759 FPRINTF(eth_code
, "\n");
2760 FPRINTF(eth_code
, " return offset;\n");
2761 FPRINTF(eth_code
, "}\n");
2764 FPRINTF(NULL
,"\nEND FUNCTION:%s pass:%d\n-------\n",function_name
,pass
);
2766 /* only advance token_list for pass==2
2767 ti now points to the ')' token
2770 if(!ti
|| g_strcmp0(ti
->str
,")")){
2771 FPRINTF(stderr
, "ERROR: function does not end with ')'\n");
2776 if(!ti
|| g_strcmp0(ti
->str
,";")){
2777 FPRINTF(stderr
, "ERROR: function does not end with ';'\n");
2787 /* this function will parse a
2790 typedef [ v1_enum ] enum {
2791 construct and generate the appropriate code.
2792 the typedef will be g_removed from the token_list once it has been processed
2793 the function assumes that the typedef is the first object in the token_list
2795 static void parsetypedefenum(void)
2798 enum_list_t
*enum_list
, *el
, *lastel
;
2802 char dissectorname
[BASE_BUFFER_SIZE
], valsstring
[BASE_BUFFER_SIZE
];
2808 if(g_strcmp0(ti
->str
, "typedef")){
2809 FPRINTF(stderr
, "ERROR: typedefenum first token is not 'typedef'\n");
2814 /* this could be a [ v1_enum ] */
2815 if(!g_strcmp0(ti
->str
, "[")){
2818 if(g_strcmp0(ti
->str
, "v1_enum")){
2819 FPRINTF(stderr
, "ERROR: typedefenum not 'v1_enum' inside brackets\n");
2824 if(g_strcmp0(ti
->str
, "]")){
2825 FPRINTF(stderr
, "ERROR: typedefenum 'v1_enum' is not followed by ']'\n");
2834 if(g_strcmp0(ti
->str
, "enum")){
2835 FPRINTF(stderr
, "ERROR: typedefenum second token is not 'enum'\n");
2840 if(g_strcmp0(ti
->str
, "{")){
2841 FPRINTF(stderr
, "ERROR: typedefenum third token is not '{'\n");
2846 /* now parse all values until we find the "}" */
2852 if(!g_strcmp0(ti
->str
,"}")){
2857 /* handle 4 types of entries:
2863 el
=g_new0(enum_list_t
, 1);
2865 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
2880 /* grab separator */
2881 if(!g_strcmp0(ti
->str
,"=")){
2884 val
=strtol(ti
->str
,&p
,0);
2885 if (p
==ti
->str
||*p
) {
2886 FPRINTF(stderr
, "ERROR: typedefenum value is not a number\n");
2897 if(!g_strcmp0(ti
->str
,",")){
2903 if(!g_strcmp0(ti
->str
,"}")){
2908 FPRINTF(stderr
,"ERROR: typedefenum should not be reached\n");
2912 /* verify that it ends with a ';' */
2913 if(g_strcmp0(ti
->next
->str
,";")){
2914 FPRINTF(stderr
,"ERROR enum terminator is not ';'\n");
2918 snprintf(valsstring
, BASE_BUFFER_SIZE
, "%s_%s_vals", ifname
, ti
->str
);
2919 snprintf(dissectorname
, DISSECTORNAME_MAXLEN
, "%s_dissect_%s", ifname
, ti
->str
);
2921 FPRINTF(NULL
,"\nENUM:%s\n-------\n",ti
->str
);
2923 FPRINTF(eth_hdr
, "\n");
2924 for(el
=enum_list
;el
;el
=el
->next
){
2925 FPRINTF(eth_hdr
, "#define %s %d\n", el
->name
, el
->val
);
2928 FPRINTF(eth_hdr
, "\n");
2929 FPRINTF(eth_hdr
, "extern const value_string %s[];\n", valsstring
);
2930 FPRINTF(eth_hdr
, "int %s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param);\n", dissectorname
);
2932 FPRINTF(eth_code
, "\n");
2933 FPRINTF(eth_code
, "const value_string %s[] = {\n", valsstring
);
2935 for(el
=enum_list
;el
;el
=el
->next
){
2936 FPRINTF(eth_code
, " { %d , \"%s\" },\n", el
->val
, el
->name
);
2938 FPRINTF(eth_code
, " { 0 , NULL }\n");
2939 FPRINTF(eth_code
, "};\n");
2941 FPRINTF(eth_code
, "\n");
2942 FPRINTF(eth_code
, "int\n");
2943 FPRINTF(eth_code
, "%s(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, dcerpc_info *di, uint8_t *drep, int hf_index, uint32_t param _U_)\n", dissectorname
);
2944 FPRINTF(eth_code
, "{\n");
2947 FPRINTF(eth_code
, " offset=dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
2950 FPRINTF(eth_code
, " offset=dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hf_index, NULL);\n");
2953 FPRINTF(stderr
,"ERROR enum unknown size\n");
2957 FPRINTF(eth_code
, " return offset;\n");
2958 FPRINTF(eth_code
, "}\n");
2959 FPRINTF(eth_code
, "\n");
2961 hfvalsstring
= g_strdup_printf("VALS(%s)", valsstring
);
2964 register_new_type(ti
->str
, dissectorname
, "FT_INT16", "BASE_DEC", "0", hfvalsstring
, 2);
2967 register_new_type(ti
->str
, dissectorname
, "FT_INT32", "BASE_DEC", "0", hfvalsstring
, 4);
2970 FPRINTF(stderr
,"ERROR enum unknown size\n");
2971 g_free(hfvalsstring
);
2974 g_free(hfvalsstring
);
2976 FPRINTF(NULL
,"\n----------\nEND ENUM:%s\n",ti
->str
);
2978 /* skip past the name and the ';' */
2979 token_list
=ti
->next
->next
;
2982 typedef struct _trimmed_prefixes_t
{
2983 struct _trimmed_prefixes_t
*next
;
2985 } trimmed_prefixes_t
;
2986 static trimmed_prefixes_t
*prefixes_to_trim
=NULL
;
2988 static void preparetrimprefix(char *prefix_name
)
2990 trimmed_prefixes_t
*new_prefix
;
2991 new_prefix
=g_new0(trimmed_prefixes_t
, 1);
2993 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
2996 new_prefix
->next
=prefixes_to_trim
;
2997 prefixes_to_trim
=new_prefix
;
2998 new_prefix
->name
=g_strdup(prefix_name
);
3005 trimmed_prefixes_t
*pfx
;
3008 for(pfx
=prefixes_to_trim
;pfx
;pfx
=pfx
->next
){
3009 len
=strlen(pfx
->name
);
3010 for(ti
=token_list
;ti
;ti
=ti
->next
){
3011 if(!strncmp(ti
->str
, pfx
->name
, len
)){
3018 static int Exit(int code
)
3020 FPRINTF(stderr
, "The tokens remaining when aborting:\n");
3026 static void usage(void)
3028 FPRINTF(stderr
, "Usage: idl2wrs <interface>\n");
3032 mergefile(const char *name
, FILE *outfile
)
3036 FPRINTF(outfile
, "\n\n/* INCLUDED FILE : %s */\n", name
);
3037 infile
=g_fopen(name
, "r");
3038 while(!feof(infile
)){
3046 FPRINTF(outfile
, "/* END OF INCLUDED FILE : %s */\n\n\n", name
);
3052 str_read_string(char *str
, char **name
)
3054 char tmpstr
[BASE_BUFFER_SIZE
], *strptr
;
3064 *name
=g_strdup(tmpstr
);
3068 if( (*str
==' ') || (*str
=='\t') ){
3079 if( (*str
==' ') || (*str
=='\t') ){
3085 *name
=g_strdup(tmpstr
);
3088 if( (*str
=='"') || (*str
=='\n') ){
3090 *name
=g_strdup(tmpstr
);
3099 readcnffile(FILE *fh
)
3101 char cnfline
[4 * BASE_BUFFER_SIZE
];
3103 FPRINTF(NULL
, "Reading conformance file\n=======================\n");
3106 if(!fgets(cnfline
, 4 * BASE_BUFFER_SIZE
, fh
) || !cnfline
[0]){
3109 if(cnfline
[0]=='#'){
3110 /* ignore all comments */
3111 } else if(!strncmp(cnfline
, "NOEMIT", 6)){
3112 no_emit_item_t
*nei
;
3116 str_read_string(str
, &name
);
3117 nei
=g_new0(no_emit_item_t
, 1);
3119 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
3122 nei
->next
=no_emit_list
;
3125 FPRINTF(NULL
, "NOEMIT : %s\n", nei
->name
);
3126 } else if(!strncmp(cnfline
, "TYPE", 4)){
3127 char *name
, *dissectorname
, *ft_type
, *base_type
;
3128 char *mask
, *valsstring
, *al
;
3133 str
=str_read_string(str
, &name
);
3134 str
=str_read_string(str
, &dissectorname
);
3135 str
=str_read_string(str
, &ft_type
);
3136 str
=str_read_string(str
, &base_type
);
3137 str
=str_read_string(str
, &mask
);
3138 str
=str_read_string(str
, &valsstring
);
3139 str_read_string(str
, &al
);
3140 if (ws_strtoi32(al
, NULL
, &alignment
)) {
3141 FPRINTF(NULL
, "TYPE : X%s,%sX\n", name
, dissectorname
);
3142 register_new_type(name
, dissectorname
, ft_type
, base_type
, mask
, valsstring
, alignment
);
3144 } else if(!strncmp(cnfline
, "PARAM_VALUE", 11)){
3145 char *dissectorname
, *value
;
3149 str
=str_read_string(str
, &dissectorname
);
3150 str_read_string(str
, &value
);
3152 FPRINTF(NULL
, "PARAM_VALUE : %s=%s\n", dissectorname
,value
);
3153 register_dissector_param_value(dissectorname
, value
);
3154 } else if(!strncmp(cnfline
, "HF_FIELD", 8)){
3155 char *hf_index
, *title
, *filter_name
, *ft_type
;
3156 char *base_type
, *valsstring
, *mask
, *blurb
;
3160 str
=str_read_string(str
, &hf_index
);
3161 str
=str_read_string(str
, &title
);
3162 str
=str_read_string(str
, &filter_name
);
3163 str
=str_read_string(str
, &ft_type
);
3164 str
=str_read_string(str
, &base_type
);
3165 str
=str_read_string(str
, &valsstring
);
3166 str
=str_read_string(str
, &mask
);
3167 str_read_string(str
, &blurb
);
3168 FPRINTF(NULL
, "HF_FIELD: %s \"%s\"\n", hf_index
, title
);
3169 register_hf_field(hf_index
, title
, filter_name
, ft_type
, base_type
, valsstring
, mask
, blurb
);
3170 } else if(!strncmp(cnfline
, "HF_RENAME", 9)){
3171 char *old_name
, *new_name
;
3175 str
=str_read_string(str
, &old_name
);
3176 str_read_string(str
, &new_name
);
3177 FPRINTF(NULL
, "HF_RENAME: %s -> %s\n", old_name
, new_name
);
3178 register_hf_rename(old_name
, new_name
);
3179 } else if(!strncmp(cnfline
, "UNION_TAG_SIZE", 14)){
3180 char *union_name
, *union_tag
;
3181 int32_t union_tag_size
;
3182 union_tag_size_item_t
*utsi
;
3186 str
=str_read_string(str
, &union_name
);
3187 str_read_string(str
, &union_tag
);
3188 if (!ws_strtoi32(union_tag
, NULL
, &union_tag_size
)) {
3189 FPRINTF(NULL
, "UNION_TAG_SIZE: invalid string: %s\n", union_tag
);
3192 FPRINTF(NULL
, "UNION_TAG_SIZE: %s == %d\n", union_name
, union_tag_size
);
3193 utsi
=g_new0(union_tag_size_item_t
, 1);
3195 FPRINTF(stderr
, "Can't allocate memory. Exit.\n");
3198 utsi
->next
=union_tag_size_list
;
3199 union_tag_size_list
=utsi
;
3200 utsi
->name
=g_strdup(union_name
);
3201 utsi
->size
=union_tag_size
;
3202 } else if(!strncmp(cnfline
, "STRIP_PREFIX", 12)){
3207 str_read_string(str
, &prefix_name
);
3208 FPRINTF(NULL
, "STRIP_PREFIX: %s\n", prefix_name
);
3209 preparetrimprefix(prefix_name
);
3211 FPRINTF(stderr
, "ERROR: could not parse cnf directive:%s\n",cnfline
);
3217 int main(int argc
, const char *argv
[])
3219 char idlfile
[BASE_BUFFER_SIZE
];
3220 char tmplfile
[BASE_BUFFER_SIZE
];
3221 char prefix_str
[BASE_BUFFER_SIZE
];
3230 eth_code
=g_fopen("ETH_CODE", "w");
3231 eth_hdr
=g_fopen("ETH_HDR", "w");
3232 eth_hfarr
=g_fopen("ETH_HFARR", "w");
3233 eth_hf
=g_fopen("ETH_HF", "w");
3234 eth_ettarr
=g_fopen("ETH_ETTARR", "w");
3235 eth_ett
=g_fopen("ETH_ETT", "w");
3236 eth_ft
=g_fopen("ETH_FT", "w");
3237 eth_handoff
=g_fopen("ETH_HANDOFF", "w");
3239 snprintf(idlfile
, BASE_BUFFER_SIZE
, "%s.cnf", argv
[1]);
3240 fh
=g_fopen(idlfile
,"r");
3246 snprintf(idlfile
, BASE_BUFFER_SIZE
, "%s.idl", argv
[1]);
3247 fh
=g_fopen(idlfile
,"r");
3249 FPRINTF(stderr
, "ERROR: could not open idl-file:%s\n", idlfile
);
3256 prune_keyword_parameters("size_is");
3257 prune_keyword_parameters("length_is");
3258 rename_tokens("NTSTATUS", "WERROR");
3259 rename_tokens("unistr_noterm", "unistr");
3260 rename_tokens("ascstr_noterm", "ascstr");
3261 rename_tokens("hyper", "uint64");
3262 FPRINTF(NULL
,"\n\nParsing header:\n================\n");
3265 /* some idl files prepend a lot of symbols with <ifname>_
3266 search through the tokenlist and g_remove all such
3269 snprintf(prefix_str
, BASE_BUFFER_SIZE
, "%s_", ifname
);
3270 preparetrimprefix(prefix_str
);
3273 /* this is the main loop, each iteration it tries to identify what
3274 kind of construct is the first entry in the token_list and call
3275 the appropriate handler
3278 /* just skip any [ ] that starts a new construct */
3279 if( !g_strcmp0(token_list
->str
, "[") ){
3280 token_list
=parsebrackets(token_list
, &bi
);
3284 /* typedef enum { */
3285 if( !g_strcmp0(token_list
->str
,"typedef")
3286 &&!g_strcmp0(token_list
->next
->str
,"enum") ){
3291 /* typedef [ v1_enum ] enum { */
3292 if( !g_strcmp0(token_list
->str
,"typedef")
3293 &&!g_strcmp0(token_list
->next
->str
,"[")
3294 &&!g_strcmp0(token_list
->next
->next
->str
,"v1_enum")
3295 &&!g_strcmp0(token_list
->next
->next
->next
->str
,"]")
3296 &&!g_strcmp0(token_list
->next
->next
->next
->next
->str
,"enum") ){
3302 if( !g_strcmp0(token_list
->str
,"const") ){
3307 /* typedef struct { */
3308 if( !g_strcmp0(token_list
->str
,"typedef") ){
3309 token_item_t
*tmpti
;
3311 tmpti
=token_list
->next
;
3312 if( !g_strcmp0(tmpti
->str
, "[") ){
3313 tmpti
=parsebrackets(tmpti
, &bi
);
3314 /* do some sanity checks here of bi->flags */
3316 if( !g_strcmp0(tmpti
->str
, "struct") ){
3317 parsetypedefstruct(0);
3318 parsetypedefstruct(1);
3323 /* typedef union { */
3324 if( !g_strcmp0(token_list
->str
,"typedef") ){
3325 token_item_t
*tmpti
;
3327 tmpti
=token_list
->next
;
3328 if( !g_strcmp0(tmpti
->str
, "[") ){
3329 tmpti
=parsebrackets(tmpti
, &bi
);
3330 /* do some sanity checks here of bi->flags */
3332 if( !g_strcmp0(tmpti
->str
, "union") ){
3333 parsetypedefunion(0);
3334 parsetypedefunion(1);
3339 /* typedef bitmap { */
3340 if( !g_strcmp0(token_list
->str
,"typedef") ){
3341 token_item_t
*tmpti
;
3343 tmpti
=token_list
->next
;
3344 if( !g_strcmp0(tmpti
->str
, "[") ){
3345 tmpti
=parsebrackets(tmpti
, &bi
);
3346 /* do some sanity checks here of bi->flags */
3348 if( !g_strcmp0(tmpti
->str
, "bitmap") ){
3349 parsetypedefbitmap(0);
3350 parsetypedefbitmap(1);
3355 /* functions: WERROR function '(' */
3356 if( !g_strcmp0(token_list
->str
,"WERROR")
3357 &&!g_strcmp0(token_list
->next
->next
->str
,"(") ){
3365 if( !g_strcmp0(token_list
->str
,"declare") ){
3382 fclose(eth_handoff
);
3384 /* unless the token_list now only contains a single token : '}'
3385 we have failed to compile the idl file properly
3387 if( g_strcmp0(token_list
->str
, "}") || token_list
->next
){
3388 FPRINTF(stderr
, "ERROR: we did not process all tokens. Compiler is incomplete.\n===========================================\n");
3393 check_hf_rename_refcount();
3395 /* merge code and template into dissector */
3396 snprintf(line
, 4 * BASE_BUFFER_SIZE
, "packet-dcerpc-%s.c", ifname
);
3397 fh
=g_fopen(line
, "w");
3398 snprintf(tmplfile
, BASE_BUFFER_SIZE
, "packet-dcerpc-%s-template.c", argv
[1]);
3399 tfh
=g_fopen(tmplfile
, "r");
3401 FPRINTF(stderr
, "ERROR: could not find %s\n", tmplfile
);
3406 if(!fgets(line
, 4 * BASE_BUFFER_SIZE
, tfh
) || !line
[0]){
3409 if(!strncmp(line
, "ETH_CODE", 8)){
3410 mergefile("ETH_CODE",fh
);
3411 } else if(!strncmp(line
, "ETH_HDR", 7)){
3412 mergefile("ETH_HDR",fh
);
3413 } else if(!strncmp(line
, "ETH_HFARR", 9)){
3414 mergefile("ETH_HFARR",fh
);
3415 } else if(!strncmp(line
, "ETH_HF", 6)){
3416 mergefile("ETH_HF",fh
);
3417 } else if(!strncmp(line
, "ETH_ETTARR", 10)){
3418 mergefile("ETH_ETTARR",fh
);
3419 } else if(!strncmp(line
, "ETH_ETT", 7)){
3420 mergefile("ETH_ETT",fh
);
3421 } else if(!strncmp(line
, "ETH_FT", 6)){
3422 mergefile("ETH_FT",fh
);
3423 } else if(!strncmp(line
, "ETH_HANDOFF", 11)){
3424 mergefile("ETH_HANDOFF",fh
);
3432 snprintf(line
, 4 * BASE_BUFFER_SIZE
, "packet-dcerpc-%s.h", ifname
);
3433 fh
=g_fopen(line
, "w");
3434 snprintf(tmplfile
, BASE_BUFFER_SIZE
, "packet-dcerpc-%s-template.h", argv
[1]);
3435 tfh
=g_fopen(tmplfile
, "r");
3437 FPRINTF(stderr
, "ERROR: could not find %s\n", tmplfile
);
3442 if(!fgets(line
, 4 * BASE_BUFFER_SIZE
, tfh
) || !line
[0]){
3445 if(!strncmp(line
, "ETH_CODE", 8)){
3446 mergefile("ETH_CODE",fh
);
3447 } else if(!strncmp(line
, "ETH_HDR", 7)){
3448 mergefile("ETH_HDR",fh
);
3449 } else if(!strncmp(line
, "ETH_HFARR", 9)){
3450 mergefile("ETH_HFARR",fh
);
3451 } else if(!strncmp(line
, "ETH_HF", 6)){
3452 mergefile("ETH_HF",fh
);
3453 } else if(!strncmp(line
, "ETH_ETTARR", 10)){
3454 mergefile("ETH_ETTARR",fh
);
3455 } else if(!strncmp(line
, "ETH_ETT", 7)){
3456 mergefile("ETH_ETT",fh
);
3457 } else if(!strncmp(line
, "ETH_FT", 6)){
3458 mergefile("ETH_FT",fh
);
3459 } else if(!strncmp(line
, "ETH_HANDOFF", 11)){
3460 mergefile("ETH_HANDOFF",fh
);
3466 g_print("%s was successfully compiled\n", ifname
);
3471 if (g_remove("ETH_CODE") == -1) {
3472 FPRINTF(stderr
, "Can't remove ETH_CODE");
3474 if (g_remove("ETH_HDR") == -1) {
3475 FPRINTF(stderr
, "Can't remove ETH_CODE");
3477 if (g_remove("ETH_HFARR") == -1) {
3478 FPRINTF(stderr
, "Can't remove ETH_CODE");
3480 if (g_remove("ETH_HF") == -1) {
3481 FPRINTF(stderr
, "Can't remove ETH_CODE");
3483 if (g_remove("ETH_ETTARR") == -1) {
3484 FPRINTF(stderr
, "Can't remove ETH_CODE");
3486 if (g_remove("ETH_ETT") == -1) {
3487 FPRINTF(stderr
, "Can't remove ETH_CODE");
3489 if (g_remove("ETH_FT") == -1) {
3490 FPRINTF(stderr
, "Can't remove ETH_CODE");
3492 if (g_remove("ETH_HANDOFF") == -1) {
3493 FPRINTF(stderr
, "Can't remove ETH_CODE");
3501 * Editor modelines - https://www.wireshark.org/tools/modelines.html
3506 * indent-tabs-mode: t
3509 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
3510 * :indentSize=8:tabSize=8:noTabs=false: