We always write to a FILE *, so:
authorGuy Harris <guy@alum.mit.edu>
Sun, 29 Sep 2013 20:26:25 +0000 (20:26 -0000)
committerGuy Harris <guy@alum.mit.edu>
Sun, 29 Sep 2013 20:26:25 +0000 (20:26 -0000)
make libpcap_write_to_file() static;

don't pass it as an argument to write routines, just have them
call it directly;

make the handle argument a FILE *.

Make the data length argument to libpcap_write_to_file() a size_t, as
that's what, for example, fwrite() takes as a size argument.

svn path=/trunk/; revision=52274

dumpcap.c
pcapio.c
pcapio.h
text2pcap.c

index ce2f4bf5d45627fc1bd9da2db4cac01f4cc39855..202f8d14fcc1ff559264fbbb35471698819e4602 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -2881,7 +2881,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
             get_os_version_info(os_info_str);
 
             g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
-            successful = libpcap_write_session_header_block(libpcap_write_to_file, ld->pdh,
+            successful = libpcap_write_session_header_block(ld->pdh,
                                 (const char *)capture_opts->capture_comment,   /* Comment*/
                                 NULL,                        /* HW*/
                                 os_info_str->str,            /* OS*/
@@ -2898,7 +2898,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
                 } else {
                     pcap_opts->snaplen = pcap_snapshot(pcap_opts->pcap_h);
                 }
-                successful = libpcap_write_interface_description_block(libpcap_write_to_file, global_ld.pdh,
+                successful = libpcap_write_interface_description_block(global_ld.pdh,
                                                                        NULL,                       /* OPT_COMMENT       1 */
                                                                        interface_opts.name,        /* IDB_NAME          2 */
                                                                        interface_opts.descr,       /* IDB_DESCRIPTION   3 */
@@ -2921,7 +2921,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
             } else {
                 pcap_opts->snaplen = pcap_snapshot(pcap_opts->pcap_h);
             }
-            successful = libpcap_write_file_header(libpcap_write_to_file, ld->pdh, pcap_opts->linktype, pcap_opts->snaplen,
+            successful = libpcap_write_file_header(ld->pdh, pcap_opts->linktype, pcap_opts->snaplen,
                                                    pcap_opts->ts_nsec, &ld->bytes_written, &err);
         }
         if (!successful) {
@@ -2983,7 +2983,7 @@ capture_loop_close_output(capture_options *capture_opts, loop_data *ld, int *err
                         isb_ifrecv = G_MAXUINT64;
                         isb_ifdrop = G_MAXUINT64;
                     }
-                    libpcap_write_interface_statistics_block(libpcap_write_to_file, ld->pdh,
+                    libpcap_write_interface_statistics_block(ld->pdh,
                                                              i,
                                                              &ld->bytes_written,
                                                              "Counters provided by dumpcap",
@@ -3374,7 +3374,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
                 get_os_version_info(os_info_str);
 
                 g_snprintf(appname, sizeof(appname), "Dumpcap " VERSION "%s", wireshark_svnversion);
-                successful = libpcap_write_session_header_block(libpcap_write_to_file, global_ld.pdh,
+                successful = libpcap_write_session_header_block(global_ld.pdh,
                                 NULL,                        /* Comment */
                                 NULL,                        /* HW */
                                 os_info_str->str,            /* OS */
@@ -3386,7 +3386,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
                 for (i = 0; successful && (i < capture_opts->ifaces->len); i++) {
                     interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
                     pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, i);
-                    successful = libpcap_write_interface_description_block(libpcap_write_to_file, global_ld.pdh,
+                    successful = libpcap_write_interface_description_block(global_ld.pdh,
                                                                            NULL,                       /* OPT_COMMENT       1 */
                                                                            interface_opts.name,        /* IDB_NAME          2 */
                                                                            interface_opts.descr,       /* IDB_DESCRIPTION   3 */
@@ -3404,7 +3404,7 @@ do_file_switch_or_stop(capture_options *capture_opts,
 
             } else {
                 pcap_opts = g_array_index(global_ld.pcaps, pcap_options *, 0);
-                successful = libpcap_write_file_header(libpcap_write_to_file, global_ld.pdh, pcap_opts->linktype, pcap_opts->snaplen,
+                successful = libpcap_write_file_header(global_ld.pdh, pcap_opts->linktype, pcap_opts->snaplen,
                                                        pcap_opts->ts_nsec, &global_ld.bytes_written, &global_ld.err);
             }
             if (!successful) {
@@ -4028,7 +4028,7 @@ capture_loop_write_packet_cb(u_char *pcap_opts_p, const struct pcap_pkthdr *phdr
            If this fails, set "ld->go" to FALSE, to stop the capture, and set
            "ld->err" to the error. */
         if (global_capture_opts.use_pcapng) {
-            successful = libpcap_write_enhanced_packet_block(libpcap_write_to_file, global_ld.pdh,
+            successful = libpcap_write_enhanced_packet_block(global_ld.pdh,
                                                              NULL,
                                                              phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
                                                              phdr->caplen, phdr->len,
@@ -4037,7 +4037,7 @@ capture_loop_write_packet_cb(u_char *pcap_opts_p, const struct pcap_pkthdr *phdr
                                                              pd, 0,
                                                              &global_ld.bytes_written, &err);
         } else {
-            successful = libpcap_write_packet(libpcap_write_to_file, global_ld.pdh,
+            successful = libpcap_write_packet(global_ld.pdh,
                                               phdr->ts.tv_sec, (gint32)phdr->ts.tv_usec,
                                               phdr->caplen, phdr->len,
                                               pd,
index eb725a5347e7e06f6238527beed2c83f5e3d38b2..cb33e15ecf71f64f20153ef793fef17603d1067b 100644 (file)
--- a/pcapio.c
+++ b/pcapio.c
@@ -178,19 +178,19 @@ struct option {
 #define ISB_USRDELIV      8
 #define ADD_PADDING(x) ((((x) + 3) >> 2) << 2)
 
-/* Write libcap to file.  write_data_info will be a FILE* */
-gboolean libpcap_write_to_file(void* write_data_info,
-                               const guint8* data,
-                               long data_length,
-                               guint64 *bytes_written,
-                               int *err)
+/* Write to capture file */
+static gboolean
+libpcap_write_to_file(FILE* pfile,
+                      const guint8* data,
+                      size_t data_length,
+                      guint64 *bytes_written,
+                      int *err)
 {
         size_t nwritten;
-        FILE* pFile = (FILE*)write_data_info;
 
-        nwritten = fwrite(data, data_length, 1, pFile);
+        nwritten = fwrite(data, data_length, 1, pfile);
         if (nwritten != 1) {
-                if (ferror(pFile)) {
+                if (ferror(pfile)) {
                         *err = errno;
                 } else {
                         *err = 0;
@@ -206,7 +206,7 @@ gboolean libpcap_write_to_file(void* write_data_info,
    Returns TRUE on success, FALSE on failure.
    Sets "*err" to an error code, or 0 for a short write, on failure*/
 gboolean
-libpcap_write_file_header(libpcap_write_t write_func, void* write_data_info, int linktype, int snaplen, gboolean ts_nsecs, guint64 *bytes_written, int *err)
+libpcap_write_file_header(FILE* pfile, int linktype, int snaplen, gboolean ts_nsecs, guint64 *bytes_written, int *err)
 {
         struct pcap_hdr file_hdr;
 
@@ -219,13 +219,13 @@ libpcap_write_file_header(libpcap_write_t write_func, void* write_data_info, int
         file_hdr.snaplen = snaplen;
         file_hdr.network = linktype;
 
-        return write_func(write_data_info, (const guint8*)&file_hdr, sizeof(file_hdr), bytes_written, err);
+        return libpcap_write_to_file(pfile, (const guint8*)&file_hdr, sizeof(file_hdr), bytes_written, err);
 }
 
 /* Write a record for a packet to a dump file.
    Returns TRUE on success, FALSE on failure. */
 gboolean
-libpcap_write_packet(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_packet(FILE* pfile,
                      time_t sec, guint32 usec,
                      guint32 caplen, guint32 len,
                      const guint8 *pd,
@@ -237,14 +237,14 @@ libpcap_write_packet(libpcap_write_t write_func, void* write_data_info,
         rec_hdr.ts_usec = usec;
         rec_hdr.incl_len = caplen;
         rec_hdr.orig_len = len;
-        if (!write_func(write_data_info, (const guint8*)&rec_hdr, sizeof(rec_hdr), bytes_written, err))
+        if (!libpcap_write_to_file(pfile, (const guint8*)&rec_hdr, sizeof(rec_hdr), bytes_written, err))
                 return FALSE;
 
-        return write_func(write_data_info, pd, caplen, bytes_written, err);
+        return libpcap_write_to_file(pfile, pd, caplen, bytes_written, err);
 }
 
 static gboolean
-write_string_option(libpcap_write_t write_func, void *write_data_info,
+write_string_option(FILE* pfile,
                     guint16 option_type, const char *option_value,
                     guint64 *bytes_written, int *err)
 {
@@ -260,14 +260,14 @@ write_string_option(libpcap_write_t write_func, void *write_data_info,
                 option.type = option_type;
                 option.value_length = (guint16)option_value_length;
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)option_value, (int) option_value_length, bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)option_value, (int) option_value_length, bytes_written, err))
                         return FALSE;
 
                 if (option_value_length % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - option_value_length % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - option_value_length % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -275,7 +275,7 @@ write_string_option(libpcap_write_t write_func, void *write_data_info,
 }
 
 gboolean
-libpcap_write_session_header_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_session_header_block(FILE* pfile,
                                    const char *comment,
                                    const char *hw,
                                    const char *os,
@@ -324,35 +324,35 @@ libpcap_write_session_header_block(libpcap_write_t write_func, void* write_data_
         shb.minor_version = PCAPNG_MINOR_VERSION;
         shb.section_length = section_length;
 
-        if (!write_func(write_data_info, (const guint8*)&shb, sizeof(struct shb), bytes_written, err))
+        if (!libpcap_write_to_file(pfile, (const guint8*)&shb, sizeof(struct shb), bytes_written, err))
                 return FALSE;
 
-        if (!write_string_option(write_func, write_data_info, OPT_COMMENT,
-                                 comment, bytes_written, err))
+        if (!write_string_option(pfile, OPT_COMMENT, comment,
+                                 bytes_written, err))
                 return FALSE;
-        if (!write_string_option(write_func, write_data_info, SHB_HARDWARE, hw,
+        if (!write_string_option(pfile, SHB_HARDWARE, hw,
                                  bytes_written, err))
                 return FALSE;
-        if (!write_string_option(write_func, write_data_info, SHB_OS, os,
+        if (!write_string_option(pfile, SHB_OS, os,
                                  bytes_written, err))
                 return FALSE;
-        if (!write_string_option(write_func, write_data_info, SHB_USERAPPL,
-                                 appname, bytes_written, err))
+        if (!write_string_option(pfile, SHB_USERAPPL, appname,
+                                 bytes_written, err))
                 return FALSE;
         if (have_options) {
                 /* write end of options */
                 option.type = OPT_ENDOFOPT;
                 option.value_length = 0;
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
         }
 
         /* write the trailing block total length */
-        return write_func(write_data_info, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
+        return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
 }
 
 gboolean
-libpcap_write_interface_description_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_interface_description_block(FILE* pfile,
                                           const char *comment, /* OPT_COMMENT        1 */
                                           const char *name,    /* IDB_NAME           2 */
                                           const char *descr,   /* IDB_DESCRIPTION    3 */
@@ -432,7 +432,7 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
         idb.link_type = link_type;
         idb.reserved = 0;
         idb.snap_len = snap_len;
-        if (!write_func(write_data_info, (const guint8*)&idb, sizeof(struct idb), bytes_written, err))
+        if (!libpcap_write_to_file(pfile, (const guint8*)&idb, sizeof(struct idb), bytes_written, err))
                 return FALSE;
 
         /* 01 - OPT_COMMENT - write comment string if applicable */
@@ -440,14 +440,14 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                 option.type = OPT_COMMENT;
                 option.value_length = (guint16)strlen(comment);
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
                         return FALSE;
 
                 if (strlen(comment) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -457,14 +457,14 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                 option.type = IDB_NAME;
                 option.value_length = (guint16)strlen(name);
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)name, (int) strlen(name), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)name, (int) strlen(name), bytes_written, err))
                         return FALSE;
 
                 if (strlen(name) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - strlen(name) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(name) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -475,14 +475,14 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                 option.type = IDB_DESCRIPTION;
                 option.value_length = (guint16)strlen(descr);
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)descr, (int) strlen(descr), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)descr, (int) strlen(descr), bytes_written, err))
                         return FALSE;
 
                 if (strlen(descr) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - strlen(descr) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(descr) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -492,10 +492,10 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                 option.type = IDB_IF_SPEED;
                 option.value_length = sizeof(guint64);
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&if_speed, sizeof(guint64), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&if_speed, sizeof(guint64), bytes_written, err))
                         return FALSE;
         }
 
@@ -504,13 +504,13 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                 option.type = IDB_TSRESOL;
                 option.value_length = sizeof(guint8);
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&tsresol, sizeof(guint8), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&tsresol, sizeof(guint8), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&padding, 3, bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 3, bytes_written, err))
                         return FALSE;
         }
 
@@ -520,16 +520,16 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
         if ((filter != NULL) && (strlen(filter) > 0) && (strlen(filter) < G_MAXUINT16)) {
                 option.type = IDB_FILTER;
                 option.value_length = (guint16)(strlen(filter) + 1 );
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
                 /* The first byte of the Option Data keeps a code of the filter used, 0 = lipbpcap filter string */
-                if (!write_func(write_data_info, (const guint8*)&padding, 1, bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 1, bytes_written, err))
                         return FALSE;
-                if (!write_func(write_data_info, (const guint8*)filter, (int) strlen(filter), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)filter, (int) strlen(filter), bytes_written, err))
                         return FALSE;
                 if ((strlen(filter) + 1) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - (strlen(filter) + 1) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - (strlen(filter) + 1) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -538,12 +538,12 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
         if ((os != NULL) && (strlen(os) > 0) && (strlen(os) < G_MAXUINT16)) {
                 option.type = IDB_OS;
                 option.value_length = (guint16)strlen(os);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
-                if (!write_func(write_data_info, (const guint8*)os, (int) strlen(os), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)os, (int) strlen(os), bytes_written, err))
                         return FALSE;
                 if (strlen(os) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - strlen(os) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(os) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -552,18 +552,18 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                 /* write end of options */
                 option.type = OPT_ENDOFOPT;
                 option.value_length = 0;
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
         }
 
         /* write the trailing Block Total Length */
-        return write_func(write_data_info, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
+        return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
 }
 
 /* Write a record for a packet to a dump file.
    Returns TRUE on success, FALSE on failure. */
 gboolean
-libpcap_write_enhanced_packet_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_enhanced_packet_block(FILE* pfile,
                                     const char *comment,
                                     time_t sec, guint32 usec,
                                     guint32 caplen, guint32 len,
@@ -606,47 +606,47 @@ libpcap_write_enhanced_packet_block(libpcap_write_t write_func, void* write_data
         epb.timestamp_low = (guint32)(timestamp & 0xffffffff);
         epb.captured_len = caplen;
         epb.packet_len = len;
-        if (!write_func(write_data_info, (const guint8*)&epb, sizeof(struct epb), bytes_written, err))
+        if (!libpcap_write_to_file(pfile, (const guint8*)&epb, sizeof(struct epb), bytes_written, err))
                 return FALSE;
-        if (!write_func(write_data_info, pd, caplen, bytes_written, err))
+        if (!libpcap_write_to_file(pfile, pd, caplen, bytes_written, err))
                 return FALSE;
         if (caplen % 4) {
-                if (!write_func(write_data_info, (const guint8*)&padding, 4 - caplen % 4, bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - caplen % 4, bytes_written, err))
                         return FALSE;
         }
         if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
                 option.type = OPT_COMMENT;
                 option.value_length = (guint16)strlen(comment);
 
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
                         return FALSE;
 
                 if (strlen(comment) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
         if (flags != 0) {
                 option.type = EPB_FLAGS;
                 option.value_length = sizeof(guint32);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
-                if (!write_func(write_data_info, (const guint8*)&flags, sizeof(guint32), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&flags, sizeof(guint32), bytes_written, err))
                         return FALSE;
                 option.type = OPT_ENDOFOPT;
                 option.value_length = 0;
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
        }
 
-       return write_func(write_data_info, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
+       return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
 }
 
 gboolean
-libpcap_write_interface_statistics_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_interface_statistics_block(FILE* pfile,
                                          guint32 interface_id,
                                          guint64 *bytes_written,
                                          const char *comment,   /* OPT_COMMENT           1 */
@@ -743,21 +743,21 @@ libpcap_write_interface_statistics_block(libpcap_write_t write_func, void* write
         isb.interface_id = interface_id;
         isb.timestamp_high = (guint32)((timestamp>>32) & 0xffffffff);
         isb.timestamp_low = (guint32)(timestamp & 0xffffffff);
-        if (!write_func(write_data_info, (const guint8*)&isb, sizeof(struct isb), bytes_written, err))
+        if (!libpcap_write_to_file(pfile, (const guint8*)&isb, sizeof(struct isb), bytes_written, err))
                 return FALSE;
 
         /* write comment string if applicable */
         if ((comment != NULL) && (strlen(comment) > 0) && (strlen(comment) < G_MAXUINT16)) {
                 option.type = OPT_COMMENT;
                 option.value_length = (guint16)strlen(comment);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)comment, (int) strlen(comment), bytes_written, err))
                         return FALSE;
 
                 if (strlen(comment) % 4) {
-                        if (!write_func(write_data_info, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
+                        if (!libpcap_write_to_file(pfile, (const guint8*)&padding, 4 - strlen(comment) % 4, bytes_written, err))
                                 return FALSE;
                 }
         }
@@ -769,13 +769,13 @@ libpcap_write_interface_statistics_block(libpcap_write_t write_func, void* write
                 option.value_length = sizeof(guint64);
                 high = (guint32)((isb_starttime>>32) & 0xffffffff);
                 low = (guint32)(isb_starttime & 0xffffffff);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&high, sizeof(guint32), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&high, sizeof(guint32), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&low, sizeof(guint32), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&low, sizeof(guint32), bytes_written, err))
                         return FALSE;
         }
         if (isb_endtime !=0) {
@@ -785,42 +785,42 @@ libpcap_write_interface_statistics_block(libpcap_write_t write_func, void* write
                 option.value_length = sizeof(guint64);
                 high = (guint32)((isb_endtime>>32) & 0xffffffff);
                 low = (guint32)(isb_endtime & 0xffffffff);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&high, sizeof(guint32), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&high, sizeof(guint32), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&low, sizeof(guint32), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&low, sizeof(guint32), bytes_written, err))
                         return FALSE;
         }
         if (isb_ifrecv != G_MAXUINT64) {
                 option.type = ISB_IFRECV;
                 option.value_length = sizeof(guint64);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&isb_ifrecv, sizeof(guint64), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&isb_ifrecv, sizeof(guint64), bytes_written, err))
                         return FALSE;
         }
         if (isb_ifdrop != G_MAXUINT64) {
                 option.type = ISB_IFDROP;
                 option.value_length = sizeof(guint64);
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
 
-                if (!write_func(write_data_info, (const guint8*)&isb_ifdrop, sizeof(guint64), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&isb_ifdrop, sizeof(guint64), bytes_written, err))
                         return FALSE;
         }
         if (have_options) {
                 /* write end of options */
                 option.type = OPT_ENDOFOPT;
                 option.value_length = 0;
-                if (!write_func(write_data_info, (const guint8*)&option, sizeof(struct option), bytes_written, err))
+                if (!libpcap_write_to_file(pfile, (const guint8*)&option, sizeof(struct option), bytes_written, err))
                         return FALSE;
         }
 
-        return write_func(write_data_info, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
+        return libpcap_write_to_file(pfile, (const guint8*)&block_total_length, sizeof(guint32), bytes_written, err);
 }
 
 /*
index 803ac33d8772309246f5e8be897c792895df66cf..dd0ad09c95dd2443d25dc8003429a8bacc4ee3d0 100644 (file)
--- a/pcapio.h
+++ b/pcapio.h
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-typedef gboolean (*libpcap_write_t) (void* write_data_info, const guint8* data,  long data_length,
-                                     guint64 *bytes_written, int *err);
-
-/* Write libcap to file.  write_data_info will be a FILE* */
-extern gboolean libpcap_write_to_file(void* write_data_info, 
-                                      const guint8* data, 
-                                      long data_length,
-                                      guint64 *bytes_written,
-                                      int *err);
-
-
 /** Write the file header to a dump file.
    Returns TRUE on success, FALSE on failure.
    Sets "*err" to an error code, or 0 for a short write, on failure*/
 extern gboolean
-libpcap_write_file_header(libpcap_write_t write_func, void* write_data_info, int linktype, int snaplen, 
+libpcap_write_file_header(FILE* pfile, int linktype, int snaplen, 
                           gboolean ts_nsecs, guint64 *bytes_written, int *err);
 
 /** Write a record for a packet to a dump file.
    Returns TRUE on success, FALSE on failure. */
 extern gboolean
-libpcap_write_packet(libpcap_write_t write_func, void* write_data_info
+libpcap_write_packet(FILE* pfile
                      time_t sec, guint32 usec,
                      guint32 caplen, guint32 len,
                      const guint8 *pd,
@@ -56,7 +45,7 @@ libpcap_write_packet(libpcap_write_t write_func, void* write_data_info,
  *
  */
 extern gboolean
-libpcap_write_session_header_block(libpcap_write_t write_func, void* write_data_info,  /**< Write information */
+libpcap_write_session_header_block(FILE* pfile,  /**< Write information */
                                    const char *comment,  /**< Comment on the section, Optinon 1 opt_comment
                                                           * A UTF-8 string containing a comment that is associated to the current block.
                                                           */
@@ -74,7 +63,7 @@ libpcap_write_session_header_block(libpcap_write_t write_func, void* write_data_
                                    int *err);
 
 extern gboolean
-libpcap_write_interface_description_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_interface_description_block(FILE* pfile,
                                           const char *comment,  /* OPT_COMMENT           1 */
                                           const char *name,     /* IDB_NAME              2 */
                                           const char *descr,    /* IDB_DESCRIPTION       3 */
@@ -88,7 +77,7 @@ libpcap_write_interface_description_block(libpcap_write_t write_func, void* writ
                                           int *err);
 
 extern gboolean
-libpcap_write_interface_statistics_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_interface_statistics_block(FILE* pfile,
                                          guint32 interface_id,
                                          guint64 *bytes_written,
                                          const char *comment,   /* OPT_COMMENT           1 */
@@ -99,7 +88,7 @@ libpcap_write_interface_statistics_block(libpcap_write_t write_func, void* write
                                          int *err);
 
 extern gboolean
-libpcap_write_enhanced_packet_block(libpcap_write_t write_func, void* write_data_info,
+libpcap_write_enhanced_packet_block(FILE* pfile,
                                     const char *comment,
                                     time_t sec, guint32 usec,
                                     guint32 caplen, guint32 len,
index 7c109929d28b72936430d80bcae98c5aff5c01ed..e90e8ead0461b1f43c9919d706cd34f286a1a5de 100644 (file)
@@ -842,7 +842,7 @@ write_current_packet(gboolean cont)
             length = 60;
         }
         if (use_pcapng) {
-            success = libpcap_write_enhanced_packet_block(libpcap_write_to_file, output_file,
+            success = libpcap_write_enhanced_packet_block(output_file,
                                                           NULL,
                                                           ts_sec, ts_usec,
                                                           length, length,
@@ -851,7 +851,7 @@ write_current_packet(gboolean cont)
                                                           packet_buf, direction,
                                                           &bytes_written, &err);
         } else {
-            success = libpcap_write_packet(libpcap_write_to_file, output_file,
+            success = libpcap_write_packet(output_file,
                                            ts_sec, ts_usec,
                                            length, length,
                                            packet_buf,
@@ -895,7 +895,7 @@ write_file_header (void)
         char comment[100];
 
         g_snprintf(comment, sizeof(comment), "Generated from input file %s.", input_filename);
-        success = libpcap_write_session_header_block(libpcap_write_to_file, output_file,
+        success = libpcap_write_session_header_block(output_file,
                                                      comment,
                                                      NULL,
                                                      NULL,
@@ -904,7 +904,7 @@ write_file_header (void)
                                                      &bytes_written,
                                                      &err);
         if (success) {
-            success = libpcap_write_interface_description_block(libpcap_write_to_file, output_file,
+            success = libpcap_write_interface_description_block(output_file,
                                                                 NULL,
                                                                 NULL,
                                                                 NULL,
@@ -918,7 +918,7 @@ write_file_header (void)
                                                                 &err);
         }
     } else {
-        success = libpcap_write_file_header(libpcap_write_to_file, output_file, pcap_link_type, PCAP_SNAPLEN,
+        success = libpcap_write_file_header(output_file, pcap_link_type, PCAP_SNAPLEN,
                                             FALSE, &bytes_written, &err);
     }
     if (!success) {
@@ -935,7 +935,7 @@ write_file_trailer (void)
     gboolean success;
 
     if (use_pcapng) {
-        success = libpcap_write_interface_statistics_block(libpcap_write_to_file, output_file,
+        success = libpcap_write_interface_statistics_block(output_file,
                                                            0,
                                                            &bytes_written,
                                                            "Counters provided by text2pcap",