diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-07-11 03:50:28 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-07-11 03:50:28 +0000 |
commit | 447bc256c1bedf2f17a77c02395f4d9262be104e (patch) | |
tree | 79bf452b1d01ab3ad485484c41d041dc033dd4bd /wiretap | |
parent | 5ad8cf408af966f3932c91021cccccc8a9255ab9 (diff) |
AARGH. There are two lumps of (almost-)identical code to handle
interface information when opening an output file, one of which I fixed
in my previous checkin and the other of which I didn't notice. Shuffle
code around a little bit so that the lumps are identical and then put
them into a common routine (*with* the fix in question).
#BACKPORT
svn path=/trunk/; revision=43655
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/file_access.c | 67 |
1 files changed, 26 insertions, 41 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 27fc2e3f2c..40d3317be6 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -1091,16 +1091,11 @@ wtap_dumper* wtap_dump_open(const char *filename, int filetype, int encap, return wtap_dump_open_ng(filename, filetype, encap,snaplen, compressed, NULL, NULL, err); } -wtap_dumper* wtap_dump_open_ng(const char *filename, int filetype, int encap, - int snaplen, gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err) +static wtap_dumper * +wtap_dump_init_dumper(int filetype, int encap, int snaplen, gboolean compressed, + wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err) { wtap_dumper *wdh; - WFILE_T fh; - - /* Check whether we can open a capture file with that file type - and that encapsulation. */ - if (!wtap_dump_open_check(filetype, encap, compressed, err)) - return NULL; /* Allocate a data structure for the output stream. */ wdh = wtap_dump_alloc_wdh(filetype, encap, snaplen, compressed, err); @@ -1136,6 +1131,25 @@ wtap_dumper* wtap_dump_open_ng(const char *filename, int filetype, int encap, wdh->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); g_array_append_val(wdh->interface_data, descr); } + return wdh; +} + +wtap_dumper* wtap_dump_open_ng(const char *filename, int filetype, int encap, + int snaplen, gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf, int *err) +{ + wtap_dumper *wdh; + WFILE_T fh; + + /* Check whether we can open a capture file with that file type + and that encapsulation. */ + if (!wtap_dump_open_check(filetype, encap, compressed, err)) + return NULL; + + /* Allocate and initialize a data structure for the output stream. */ + wdh = wtap_dump_init_dumper(filetype, encap, snaplen, compressed, + shb_hdr, idb_inf, err); + if (wdh == NULL) + return NULL; /* "-" means stdout */ if (strcmp(filename, "-") == 0) { @@ -1196,10 +1210,11 @@ wtap_dumper* wtap_dump_fdopen_ng(int fd, int filetype, int encap, int snaplen, if (!wtap_dump_open_check(filetype, encap, compressed, err)) return NULL; - /* Allocate a data structure for the output stream. */ - wdh = wtap_dump_alloc_wdh(filetype, encap, snaplen, compressed, err); + /* Allocate and initialize a data structure for the output stream. */ + wdh = wtap_dump_init_dumper(filetype, encap, snaplen, compressed, + shb_hdr, idb_inf, err); if (wdh == NULL) - return NULL; /* couldn't allocate it */ + return NULL; #ifdef _WIN32 if (fd == 1) { @@ -1212,36 +1227,6 @@ wtap_dumper* wtap_dump_fdopen_ng(int fd, int filetype, int encap, int snaplen, } #endif - /* Set Section Header Block data */ - wdh->shb_hdr = shb_hdr; - /* Set Interface Description Block data */ - if ((idb_inf != NULL) && (idb_inf->number_of_interfaces > 0)) { - wdh->number_of_interfaces = idb_inf->number_of_interfaces; - wdh->interface_data = idb_inf->interface_data; - } else { - wtapng_if_descr_t descr; - - descr.wtap_encap = encap; - descr.time_units_per_second = 0; - descr.link_type = wtap_wtap_encap_to_pcap_encap(encap); - descr.snap_len = snaplen; - descr.opt_comment = NULL; - descr.if_name = NULL; - descr.if_description = NULL; - descr.if_speed = 0; - descr.if_tsresol = 6; - descr.if_filter_str= NULL; - descr.bpf_filter_len= 0; - descr.if_filter_bpf_bytes= NULL; - descr.if_os = NULL; - descr.if_fcslen = -1; - descr.num_stat_entries = 0; /* Number of ISB:s */ - descr.interface_statistics = NULL; - wdh->number_of_interfaces= 1; - wdh->interface_data= g_array_new(FALSE, FALSE, sizeof(wtapng_if_descr_t)); - g_array_append_val(wdh->interface_data, descr); - } - /* In case "fopen()" fails but doesn't set "errno", set "errno" to a generic "the open failed" error. */ errno = WTAP_ERR_CANT_OPEN; |