@@ -101,6 +101,7 @@ void read_set(struct ipx_ipfix_set *set, ipx_msg_ipfix_t *msg, const fds_iemgr_t
101101 // Data set
102102 if (set_id >= FDS_IPFIX_SET_MIN_DSET ){
103103 struct ipx_ipfix_record * ipfix_rec = ipx_msg_ipfix_get_drec (msg ,* rec_i );
104+ if (ipfix_rec == NULL ) return ;
104105
105106 //All the records in the set has same template id, so we extract it from the first record and print it
106107 printf ("\ttemplate id: %" PRIu16 "\n" , ipfix_rec -> rec .tmplt -> id );
@@ -174,7 +175,7 @@ void read_template_set(struct fds_tset_iter *tset_iter, uint16_t set_id, const f
174175
175176 // Unknown field definition
176177 if (current .def == NULL ){
177- printf ("<Unknown field name>\n " );
178+ printf ("<Unknown field name>" );
178179 }
179180 // Known field definition
180181 else {
@@ -195,18 +196,15 @@ void print_indent(unsigned int n){
195196void read_record (struct fds_drec * rec , unsigned int indent , const fds_iemgr_t * iemgr ) {
196197 // Write info from header about the record template
197198 print_indent (indent );
198- printf ("field count: %" PRIu16 "\n" , rec -> tmplt -> fields_cnt_total );
199- print_indent (indent );
200- printf ("data length: %" PRIu16 "\n" , rec -> tmplt -> data_length );
201- print_indent (indent );
202- printf ("size : %" PRIu16 "\n" , rec -> size );
199+ printf ("[templateID: %-*" PRIu16 " " , 10 , rec -> tmplt -> id );
200+ printf ("field count: %-*" PRIu16 " " , 10 , rec -> tmplt -> fields_cnt_total );
201+ printf ("data length: %-*" PRIu16 " " , 10 , rec -> tmplt -> data_length );
202+ printf ("size: %" PRIu16 "]\n" , 10 , rec -> size );
203203
204204 // Iterate through all the fields in record
205205 struct fds_drec_iter iter ;
206206 fds_drec_iter_init (& iter , rec , 0 );
207207
208- print_indent (indent );
209- printf ("fields:\n" );
210208 while (fds_drec_iter_next (& iter ) != FDS_EOC ) {
211209 struct fds_drec_field field = iter .field ;
212210 read_field (& field ,indent , iemgr , rec -> snap , false); // add iemgr
@@ -234,7 +232,7 @@ void read_field(struct fds_drec_field *field, unsigned int indent, const fds_iem
234232 // Write info from header about field
235233 print_indent (indent );
236234 if (!in_basicList ) {
237- printf ("en:%*" PRIu32 " id:%*" PRIu16 " " , WRITER_EN_SPACE , field -> info -> en , WRITER_ID_SPACE , field -> info -> id );
235+ printf ("en:%*" PRIu32 " id:%*" PRIu16 " " , WRITER_EN_SPACE , field -> info -> en , WRITER_ID_SPACE , field -> info -> id );
238236 }
239237
240238 enum fds_iemgr_element_type type ;
@@ -264,38 +262,49 @@ void read_field(struct fds_drec_field *field, unsigned int indent, const fds_iem
264262 switch (type ){
265263 case FDS_ET_BASIC_LIST : {
266264 // Iteration through the basic list
267- bool did_read = false;
268265 struct fds_blist_iter blist_it ;
269266
270267 printf ("%*s %s" , WRITER_ORG_NAME_SPACE , org , field_name );
271268 fds_blist_iter_init (& blist_it ,field , iemgr );
272- printf ("%4s[semantic: %s]" ," " ,fds_semantic2str (blist_it .semantic )); // Semantic is known after initialization
273-
274- while (fds_blist_iter_next (& blist_it ) == FDS_OK ){
275- if (!did_read ){
276- putchar ('\n' );
277- did_read = true;
278- }
269+ // Before printing the frist record, we need to print semantics of list
270+ // only function _next returns the state of the iterator
271+ int ret = fds_blist_iter_next (& blist_it );
272+ if (ret == FDS_OK || ret == FDS_EOC ){
273+ printf (" (semantic: %s[%d])" , fds_semantic2str (blist_it .semantic ), blist_it .semantic );
274+ }
275+ if (ret == FDS_OK ) {
276+ putchar ('\n' );
279277 read_field (& blist_it .field ,indent + 1 , iemgr , snap , true);
278+ } else if (ret == FDS_EOC ){
279+ printf (" - empty\n" );
280280 }
281- if (! did_read ){ // if we didn't read a single field
282- printf ( "%4s : empty\n" , " " );
281+ while ( fds_blist_iter_next ( & blist_it ) == FDS_OK ){
282+ read_field ( & blist_it . field , indent + 1 , iemgr , snap , true );
283283 }
284284 return ;
285285 }
286286 case FDS_ET_SUB_TEMPLATE_LIST :
287287 case FDS_ET_SUB_TEMPLATE_MULTILIST : {
288288 // Iteration through the subTemplate and subTemplateMulti lists
289- printf ("%*s %s\n " , WRITER_ORG_NAME_SPACE , org , field_name );
290- struct fds_stlist_iter stlist_iter ;
289+ printf ("%*s %s" , WRITER_ORG_NAME_SPACE , org , field_name );
290+ struct fds_stlist_iter stlist_it ;
291291 print_indent (indent );
292- fds_stlist_iter_init (& stlist_iter , field , snap , 0 );
293- printf ("- semantic: %d\n" ,stlist_iter .semantic );
294- while (fds_stlist_iter_next (& stlist_iter ) == FDS_OK ){
295- read_record (& stlist_iter .rec , indent + 1 , iemgr );
292+ fds_stlist_iter_init (& stlist_it , field , snap , 0 );
293+ // Before printing the first record, we need to print the semantic of the list
294+ // only _next function returns state of the iterator
295+ int ret = fds_stlist_iter_next (& stlist_it );
296+ if (ret == FDS_OK || ret == FDS_EOC ){
297+ printf (" (semantic: %s[%d])" , fds_semantic2str (stlist_it .semantic ), stlist_it .semantic );
298+ }
299+ if (ret == FDS_OK ) {
296300 putchar ('\n' );
301+ read_record (& stlist_it .rec , indent + 1 , iemgr );
302+ } else if (ret == FDS_EOC ){
303+ printf (" - empty\n" );
304+ }
305+ while (fds_stlist_iter_next (& stlist_it ) == FDS_OK ){
306+ read_record (& stlist_it .rec , indent + 1 , iemgr );
297307 }
298- putchar ('\b' );
299308 return ;
300309 }
301310 default :
@@ -310,8 +319,9 @@ void read_field(struct fds_drec_field *field, unsigned int indent, const fds_iem
310319 // Conversion was successful
311320 if (type == FDS_ET_STRING ){
312321 printf ("\"%s\"" , buffer );
313- }
314- else {
322+ } else if (type == FDS_ET_OCTET_ARRAY ){
323+ printf ("0x%s" ,buffer );
324+ } else {
315325 printf ("%s" , buffer );
316326 }
317327
0 commit comments