+ count = 1;
+ for (;;) {
+ if (do_append)
+ wth = merge_append_read_packet(in_file_count, in_files, &read_err,
+ &err_info);
+ else
+ wth = merge_read_packet(in_file_count, in_files, &read_err,
+ &err_info);
+ if (wth == NULL) {
+ if (read_err != 0)
+ got_read_error = TRUE;
+ break;
+ }
+
+ if (verbose)
+ fprintf(stderr, "Record: %u\n", count++);
+
+ /* We simply write it, perhaps after truncating it; we could do other
+ * things, like modify it. */
+ phdr = wtap_phdr(wth);
+ if (snaplen != 0 && phdr->caplen > snaplen) {
+ snap_phdr = *phdr;
+ snap_phdr.caplen = snaplen;
+ phdr = &snap_phdr;
+ }
+
+ if (!wtap_dump(pdh, phdr, wtap_pseudoheader(wth),
+ wtap_buf_ptr(wth), &write_err)) {
+ got_write_error = TRUE;
+ break;
+ }
+ }
+
+ merge_close_in_files(in_file_count, in_files);
+ if (!got_read_error && !got_write_error) {
+ if (!wtap_dump_close(pdh, &write_err))
+ got_write_error = TRUE;
+ } else
+ wtap_dump_close(pdh, &close_err);
+
+ if (got_read_error) {
+ /*
+ * Find the file on which we got the error, and report the error.
+ */
+ for (i = 0; i < in_file_count; i++) {
+ if (in_files[i].state == GOT_ERROR) {
+ fprintf(stderr, "mergecap: Error reading %s: %s\n",
+ in_files[i].filename, wtap_strerror(read_err));
+ switch (read_err) {
+
+ case WTAP_ERR_UNSUPPORTED:
+ case WTAP_ERR_UNSUPPORTED_ENCAP:
+ case WTAP_ERR_BAD_RECORD:
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
+ break;
+ }
+ }
+ }
+ }