cisco / joy

A package for capturing and analyzing network flow data and intraflow data, for network research, forensics, and security monitoring.
Other
1.31k stars 329 forks source link

Build Error while enable output compress #293

Open flat2010 opened 4 years ago

flat2010 commented 4 years ago

Files involved

joy-master/joy_config.h joy-master/src/p2f.c

Platform

Ubuntu 14.04 4.4.0-148

Problem

Step1: modify joy_config.h as follows:

/* Compression is enabled */
#define COMPRESSED_OUTPUT 1
#undef  FORCED_COMPRESSED_OUTPUT_OFF

Step2: modify p2f.c as follows:

// decomment line 1831
zflush(ctx->output);

Step3: then make

$make

Error occurs:

../src/p2f.c: In function 'flow_record_list_print_json':
../src/include/output.h:115:35: error: too few arguments to function 'gzflush'
     #define zflush(FILEp)        (gzflush(FILEp))
                                   ^~~~~~~
../src/p2f.c:1831:5: note: in expansion of macro 'zflush'
     zflush(ctx->output);
     ^~~~~~
In file included from ../src/include/output.h:103,
                 from ../src/include/hdr_dsc.h:47,
                 from ../src/include/p2f.h:59,
                 from ../src/include/pkt_proc.h:47,
                 from ../src/p2f.c:58:
/usr/local/include/zlib.h:1531:21: note: declared here
 ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));

This will happen when zflush called if gzip enabled.

Reason

According to Linux specification, gzflush needs 2 parameters which the last should be either:

But there's only 1 parameter in definition of zflush:

#ifdef USE_BZIP2
    ···
    #define zflush(FILEp)        (BZ2_bzflush(FILEp))
    ···
#else
    ···
   // gzflush needs 2  parameters
    #define zflush(FILEp)        (gzflush(FILEp))
    ···

Fix

  1. Modify definition of gzflush, pass a right macro value as the 2nd parameter;
flat2010 commented 4 years ago

Original:

// output.h
#else
    /** gzip compressed output */
    #include <zlib.h>
    typedef gzFile zfile;

    #define zopen(fname, ...)    (gzopen(fname, __VA_ARGS__))

    #ifdef WIN32
        #define zattach(FILEp, ...)  (gzdopen(_fileno(FILEp), __VA_ARGS__))
    #else
        #define zattach(FILEp, ...)  (gzdopen(fileno(FILEp), __VA_ARGS__))
    #endif

    #define zprintf(output, ...) (gzprintf(output, __VA_ARGS__))
    #define zflush(FILEp)        (gzflush(FILEp))
    #define zclose(output)       (gzclose(output))
    #define zsuffix              ".gz"
#endif

My fix:

// output.h
#else
    /** gzip compressed output */
    #include <zlib.h>
    typedef gzFile zfile;

    #define zopen(fname, ...)    (gzopen(fname, __VA_ARGS__))

    #ifdef WIN32
        #define zattach(FILEp, ...)  (gzdopen(_fileno(FILEp), __VA_ARGS__))
        #define zflush(FILEp)        (gzflush(FILEp))
    #else
        #define zattach(FILEp, ...)  (gzdopen(fileno(FILEp), __VA_ARGS__))
        // here we  pass Z_FINISH to gzflush
        #define zflush(FILEp)        (gzflush(FILEp, Z_FINISH))
    #endif

    #define zprintf(output, ...) (gzprintf(output, __VA_ARGS__))
    #define zclose(output)       (gzclose(output))
    #define zsuffix              ".gz"
#endif