@@ -47,8 +47,10 @@ using namespace std;
4747#include " Storage.hpp"
4848#include < libfds.h>
4949
50- /* * Base size of the conversion buffer */
50+ /* * Base size of the conversion buffer */
5151#define BUFFER_BASE 4096
52+ /* * Size of local conversion buffers (for snprintf) */
53+ #define LOCAL_BSIZE 64
5254
5355Storage::Storage (const ipx_ctx_t *ctx, const struct cfg_format &fmt)
5456 : m_ctx(ctx), m_format(fmt)
@@ -150,9 +152,8 @@ Storage::output_add(Output *output)
150152 * \param[in] tset_iter (Options) Template set structure to convert
151153 * \param[in] set_id Id of the set
152154 * \param[in] hdr Message header of IPFIX record
153- * \throw runtime_error if template parser failed
155+ * \throw runtime_error If template parser failed
154156 */
155-
156157void
157158Storage::convert_tmplt_rec (struct fds_tset_iter *tset_iter, uint16_t set_id, fds_ipfix_msg_hdr* hdr)
158159{
@@ -179,11 +180,11 @@ Storage::convert_tmplt_rec(struct fds_tset_iter *tset_iter, uint16_t set_id, fds
179180 }
180181
181182 // Printing out the header
182- char field[64 ];
183- snprintf (field, 64 , " \" ipfix:templateId\" :\" %" PRIu16 " \" " , tmplt->id );
183+ char field[LOCAL_BSIZE ];
184+ snprintf (field, LOCAL_BSIZE , " \" ipfix:templateId\" :\" %" PRIu16 " \" " , tmplt->id );
184185 buffer_append (field);
185186 if (set_id == FDS_IPFIX_SET_OPTS_TMPLT) {
186- snprintf (field, 64 , " ,\" ipfix:scopeCount\" :\" %" PRIu16 " \" " , tmplt->fields_cnt_scope );
187+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:scopeCount\" :\" %" PRIu16 " \" " , tmplt->fields_cnt_scope );
187188 buffer_append (field);
188189 }
189190
@@ -201,11 +202,11 @@ Storage::convert_tmplt_rec(struct fds_tset_iter *tset_iter, uint16_t set_id, fds
201202 buffer_append (" ," );
202203 }
203204 buffer_append (" {" );
204- snprintf (field, 64 , " \" ipfix:elementId\" :\" %" PRIu16 " \" " , current.id );
205+ snprintf (field, LOCAL_BSIZE , " \" ipfix:elementId\" :\" %" PRIu16 " \" " , current.id );
205206 buffer_append (field);
206- snprintf (field, 64 , " ,\" ipfix:enterpriseId\" :\" %" PRIu32 " \" " , current.en );
207+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:enterpriseId\" :\" %" PRIu32 " \" " , current.en );
207208 buffer_append (field);
208- snprintf (field, 64 , " ,\" ipfix:fieldLength\" :\" %" PRIu16 " \" " , current.length );
209+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:fieldLength\" :\" %" PRIu16 " \" " , current.length );
209210 buffer_append (field);
210211 buffer_append (" }" );
211212 }
@@ -344,17 +345,17 @@ void
344345Storage::addDetailedInfo (fds_ipfix_msg_hdr *hdr)
345346{
346347 // Array for formatting detailed info fields
347- char field[64 ];
348- snprintf (field, 64 , " ,\" ipfix:exportTime\" :\" %" PRIu32 " \" " , ntohl (hdr->export_time ));
348+ char field[LOCAL_BSIZE ];
349+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:exportTime\" :\" %" PRIu32 " \" " , ntohl (hdr->export_time ));
349350 buffer_append (field);
350351
351- snprintf (field, 64 , " ,\" ipfix:seqNumber\" :\" %" PRIu32 " \" " , ntohl (hdr->seq_num ));
352+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:seqNumber\" :\" %" PRIu32 " \" " , ntohl (hdr->seq_num ));
352353 buffer_append (field);
353354
354- snprintf (field, 64 , " ,\" ipfix:odid\" :\" %" PRIu32 " \" " , ntohl (hdr->odid ));
355+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:odid\" :\" %" PRIu32 " \" " , ntohl (hdr->odid ));
355356 buffer_append (field);
356357
357- snprintf (field, 32 , " ,\" ipfix:msgLength\" :\" %" PRIu16 " \" " , ntohs (hdr->length ));
358+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:msgLength\" :\" %" PRIu16 " \" " , ntohs (hdr->length ));
358359 buffer_append (field);
359360}
360361
@@ -390,18 +391,14 @@ Storage::convert(struct fds_drec &rec, const fds_iemgr_t *iemgr, fds_ipfix_msg_h
390391 addDetailedInfo (hdr);
391392
392393 // Add template ID to JSON string
393- char field[64 ];
394- snprintf (field, 32 , " ,\" ipfix:templateId\" :\" %" PRIu16 " \" " , rec.tmplt ->id );
394+ char field[LOCAL_BSIZE ];
395+ snprintf (field, LOCAL_BSIZE , " ,\" ipfix:templateId\" :\" %" PRIu16 " \" " , rec.tmplt ->id );
395396 buffer_append (field);
396397
397398 // Append the record with '}' parenthesis removed before
398399 buffer_append (" }" );
399400 }
400401
401- // Append the record with end of line character
402- buffer_append (" \n " );
403-
404- /* Note: additional information (e.g. ODID, Export Time, etc.) can be added here,
405- * just use buffer_append() and buffer_reserve() to append and extend buffer, respectively.
406- */
402+ // Append the record with end of line character
403+ buffer_append (" \n " );
407404}
0 commit comments