static void
-frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh)
+frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf)
{
int err;
gchar *errinfo;
struct wtap_pkthdr phdr;
- guint8 buf[65535];
DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u, length=%u)\n",
frame->offset, frame->length);
+
/* Re-read the first frame from the stored location */
wtap_seek_read(wth,
frame->offset,
phdr.ts = frame->time;
/* Dump frame to outfile */
- if (!wtap_dump(pdh, &phdr, buf, &err)) {
+ if (!wtap_dump(pdh, &phdr, buffer_start_ptr(buf), &err)) {
printf("Error (%s) writing frame to outfile\n", wtap_strerror(err));
exit(1);
}
{
wtap *wth = NULL;
wtap_dumper *pdh = NULL;
+ Buffer buf;
int err;
gchar *err_info;
gint64 data_offset;
guint wrong_order_count = 0;
gboolean write_output_regardless = TRUE;
guint i;
+ wtapng_section_t *shb_hdr;
+ wtapng_iface_descriptions_t *idb_inf;
GPtrArray *frames;
FrameRecord_t *prevFrame = NULL;
}
DEBUG_PRINT("file_type is %u\n", wtap_file_type(wth));
+ shb_hdr = wtap_file_get_shb_info(wth);
+ idb_inf = wtap_file_get_idb_info(wth);
+
/* Open outfile (same filetype/encap as input file) */
- pdh = wtap_dump_open(outfile, wtap_file_type(wth), wtap_file_encap(wth), 65535, FALSE, &err);
+ pdh = wtap_dump_open_ng(outfile, wtap_file_type(wth), wtap_file_encap(wth),
+ 65535, FALSE, shb_hdr, idb_inf, &err);
+ g_free(idb_inf);
if (pdh == NULL) {
printf("Failed to open output file: (%s) - error %s\n", outfile, wtap_strerror(err));
+ g_free(shb_hdr);
exit(1);
}
}
/* Write out each sorted frame in turn */
+ buffer_init(&buf, 1500);
for (i = 0; i < frames->len; i++) {
FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i];
/* Avoid writing if already sorted and configured to */
if (write_output_regardless || (wrong_order_count > 0)) {
- frame_write(frame, wth, pdh);
+ frame_write(frame, wth, pdh, &buf);
}
g_slice_free(FrameRecord_t, frame);
}
+ buffer_free(&buf);
if (!write_output_regardless && (wrong_order_count == 0)) {
printf("Not writing output file because input file is already in order!\n");
/* Close outfile */
if (!wtap_dump_close(pdh, &err)) {
printf("Error closing %s: %s\n", outfile, wtap_strerror(err));
+ g_free(shb_hdr);
exit(1);
}
+ g_free(shb_hdr);
/* Finally, close infile */
wtap_fdclose(wth);