diff --git a/dumpcap.c b/dumpcap.c index 23b9436d2a..95e54400ed 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -2824,7 +2824,10 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err if (capture_opts->multi_files_on) { ld->pdh = ringbuf_init_libpcap_fdopen(&err); } else { - ld->pdh = libpcap_fdopen(ld->save_file_fd, &err); + ld->pdh = ws_fdopen(ld->save_file_fd, "wb"); + if (ld->pdh == NULL) { + err = errno; + } } if (ld->pdh) { if (capture_opts->use_pcapng) { @@ -2949,7 +2952,14 @@ capture_loop_close_output(capture_options *capture_opts, loop_data *ld, int *err } } } - return libpcap_dump_close(ld->pdh, err_close); + if (ws_fclose(ld->pdh) == EOF) { + if (err_close != NULL) { + *err_close = errno; + } + return (FALSE); + } else { + return (TRUE); + } } } @@ -3364,7 +3374,7 @@ do_file_switch_or_stop(capture_options *capture_opts, cnd_reset(cnd_autostop_size); if (cnd_file_duration) cnd_reset(cnd_file_duration); - libpcap_dump_flush(global_ld.pdh, NULL); + ws_fflush(global_ld.pdh); if (!quiet) report_packet_count(global_ld.inpkts_to_sync_pipe); global_ld.inpkts_to_sync_pipe = 0; @@ -3515,7 +3525,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct message to our parent so that they'll open the capture file and update its windows to indicate that we have a live capture in progress. */ - libpcap_dump_flush(global_ld.pdh, NULL); + ws_fflush(global_ld.pdh); report_new_capture_file(capture_opts->save_file); } @@ -3632,7 +3642,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct continue; } /* cnd_autostop_size */ if (capture_opts->output_to_pipe) { - libpcap_dump_flush(global_ld.pdh, NULL); + ws_fflush(global_ld.pdh); } } /* inpkts */ @@ -3661,7 +3671,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct /* Let the parent process know. */ if (global_ld.inpkts_to_sync_pipe) { /* do sync here */ - libpcap_dump_flush(global_ld.pdh, NULL); + ws_fflush(global_ld.pdh); /* Send our parent a message saying we've written out "global_ld.inpkts_to_sync_pipe" packets to the capture file. */ @@ -3721,7 +3731,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct g_free(queue_element); global_ld.inpkts_to_sync_pipe += 1; if (capture_opts->output_to_pipe) { - libpcap_dump_flush(global_ld.pdh, NULL); + ws_fflush(global_ld.pdh); } } } diff --git a/pcapio.c b/pcapio.c index b45a0e7284..f4bb7f30dc 100644 --- a/pcapio.c +++ b/pcapio.c @@ -194,19 +194,6 @@ struct option { } while (0); \ } -/* Returns a FILE * to write to on success, NULL on failure */ -FILE * -libpcap_fdopen(int fd, int *err) -{ - FILE *fp; - - fp = fdopen(fd, "wb"); - if (fp == NULL) { - *err = errno; - } - return fp; -} - /* 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*/ @@ -751,28 +738,6 @@ libpcap_write_interface_statistics_block(FILE *fp, return TRUE; } -gboolean -libpcap_dump_flush(FILE *pd, int *err) -{ - if (fflush(pd) == EOF) { - if (err != NULL) - *err = errno; - return FALSE; - } - return TRUE; -} - -gboolean -libpcap_dump_close(FILE *pd, int *err) -{ - if (fclose(pd) == EOF) { - if (err != NULL) - *err = errno; - return FALSE; - } - return TRUE; -} - #endif /* HAVE_LIBPCAP */ /* diff --git a/pcapio.h b/pcapio.h index 839aad78d2..1d0a1446ad 100644 --- a/pcapio.h +++ b/pcapio.h @@ -25,10 +25,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/** Returns a FILE * to write to on success, NULL on failure */ -extern FILE * -libpcap_fdopen(int fd, 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*/ @@ -96,9 +92,3 @@ libpcap_write_enhanced_packet_block(FILE *fp, guint32 flags, long *bytes_written, int *err); - -extern gboolean -libpcap_dump_flush(FILE *pd, int *err); - -extern gboolean -libpcap_dump_close(FILE *pd, int *err); diff --git a/ringbuffer.c b/ringbuffer.c index 8c4a47bffd..c5a095dfff 100644 --- a/ringbuffer.c +++ b/ringbuffer.c @@ -63,7 +63,6 @@ #include -#include "pcapio.h" #include "ringbuffer.h" #include @@ -226,12 +225,17 @@ const gchar *ringbuf_current_filename(void) } /* - * Calls libpcap_fdopen() for the current ringbuffer file + * Calls ws_fdopen() for the current ringbuffer file */ FILE * ringbuf_init_libpcap_fdopen(int *err) { - rb_data.pdh = libpcap_fdopen(rb_data.fd, err); + rb_data.pdh = ws_fdopen(rb_data.fd, "wb"); + if (rb_data.pdh == NULL) { + if (err != NULL) { + *err = errno; + } + } return rb_data.pdh; } @@ -246,7 +250,10 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err) /* close current file */ - if (!libpcap_dump_close(rb_data.pdh, err)) { + if (ws_fclose(rb_data.pdh) == EOF) { + if (err != NULL) { + *err = errno; + } ws_close(rb_data.fd); /* XXX - the above should have closed this already */ rb_data.pdh = NULL; /* it's still closed, we just got an error while closing */ rb_data.fd = -1; @@ -279,7 +286,7 @@ ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd, int *err) } /* - * Calls libpcap_dump_close() for the current ringbuffer file + * Calls ws_fclose() for the current ringbuffer file */ gboolean ringbuf_libpcap_dump_close(gchar **save_file, int *err) @@ -288,11 +295,13 @@ ringbuf_libpcap_dump_close(gchar **save_file, int *err) /* close current file, if it's open */ if (rb_data.pdh != NULL) { - if (!libpcap_dump_close(rb_data.pdh, err)) { + if (ws_fclose(rb_data.pdh) == EOF) { + if (err != NULL) { + *err = errno; + } ws_close(rb_data.fd); ret_val = FALSE; } - rb_data.pdh = NULL; rb_data.fd = -1; } @@ -340,15 +349,13 @@ ringbuf_error_cleanup(void) /* try to close via wtap */ if (rb_data.pdh != NULL) { - if (libpcap_dump_close(rb_data.pdh, NULL)) { + if (ws_fclose(rb_data.pdh) == 0) { rb_data.fd = -1; } rb_data.pdh = NULL; } /* close directly if still open */ - /* XXX - it shouldn't still be open; "libpcap_dump_close()" should leave the - file closed even if it fails */ if (rb_data.fd != -1) { ws_close(rb_data.fd); rb_data.fd = -1; diff --git a/wsutil/file_util.h b/wsutil/file_util.h index a3867196ab..09c5c64af9 100644 --- a/wsutil/file_util.h +++ b/wsutil/file_util.h @@ -94,6 +94,9 @@ extern FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE * #define ws_dup _dup #define ws_fstat64 _fstati64 /* use _fstati64 for 64-bit size support */ #define ws_lseek64 _lseeki64 /* use _lseeki64 for 64-bit offset support */ +#define ws_fdopen _fdopen +#define ws_fclose fclose +#define ws_fflush fflush /* DLL loading */ @@ -149,6 +152,9 @@ extern char *getenv_utf8(const char *varname); #define ws_dup dup #define ws_fstat64 fstat /* AC_SYS_LARGEFILE should make off_t 64-bit */ #define ws_lseek64 lseek /* AC_SYS_LARGEFILE should make off_t 64-bit */ +#define ws_fdopen fdopen +#define ws_fclose fclose +#define ws_fflush fflush #define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */ #endif /* _WIN32 */