/* Remember where this frame was in the file */
typedef struct FrameRecord_t {
- gint64 offset;
- guint32 length;
- guint num;
+ gint64 offset;
+ guint32 length;
+ guint num;
- struct wtap_nstime time;
+ nstime_t time;
} FrameRecord_t;
static void
-frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf)
+frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf,
+ const char *infile)
{
int err;
- gchar *errinfo;
+ gchar *err_info;
struct wtap_pkthdr phdr;
DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u, length=%u)\n",
/* Re-read the first frame from the stored location */
- wtap_seek_read(wth,
- frame->offset,
- &phdr,
- buf,
- frame->length,
- &err,
- &errinfo);
- DEBUG_PRINT("re-read: err is %d, buf is (%s)\n", err, buf);
+ if (!wtap_seek_read(wth, frame->offset, &phdr, buf, frame->length,
+ &err, &err_info)) {
+ if (err != 0) {
+ /* Print a message noting that the read failed somewhere along the line. */
+ fprintf(stderr,
+ "reordercap: An error occurred while re-reading \"%s\": %s.\n",
+ infile, wtap_strerror(err));
+ switch (err) {
+
+ case WTAP_ERR_UNSUPPORTED:
+ case WTAP_ERR_UNSUPPORTED_ENCAP:
+ case WTAP_ERR_BAD_FILE:
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
+ break;
+ }
+ exit(1);
+ }
+ }
/* Copy, and set length and timestamp from item. */
/* TODO: remove when wtap_seek_read() will read phdr */
const FrameRecord_t *frame1 = *(const FrameRecord_t **) a;
const FrameRecord_t *frame2 = *(const FrameRecord_t **) b;
- const struct wtap_nstime *time1 = &frame1->time;
- const struct wtap_nstime *time2 = &frame2->time;
+ const nstime_t *time1 = &frame1->time;
+ const nstime_t *time2 = &frame2->time;
if (time1->secs > time2->secs)
return 1;
if (wth == NULL) {
fprintf(stderr, "reordercap: Can't open %s: %s\n", infile,
wtap_strerror(err));
+ switch (err) {
+
+ case WTAP_ERR_UNSUPPORTED:
+ case WTAP_ERR_UNSUPPORTED_ENCAP:
+ case WTAP_ERR_BAD_FILE:
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
+ break;
+ }
exit(1);
}
- DEBUG_PRINT("file_type is %u\n", wtap_file_type(wth));
+ DEBUG_PRINT("file_type_subtype is %u\n", wtap_file_type_subtype(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_ng(outfile, wtap_file_type(wth), wtap_file_encap(wth),
+ pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
65535, FALSE, shb_hdr, idb_inf, &err);
g_free(idb_inf);
if (pdh == NULL) {
g_ptr_array_add(frames, newFrameRecord);
prevFrame = newFrameRecord;
}
+ if (err != 0) {
+ /* Print a message noting that the read failed somewhere along the line. */
+ fprintf(stderr,
+ "reordercap: An error occurred while reading \"%s\": %s.\n",
+ infile, wtap_strerror(err));
+ switch (err) {
+
+ case WTAP_ERR_UNSUPPORTED:
+ case WTAP_ERR_UNSUPPORTED_ENCAP:
+ case WTAP_ERR_BAD_FILE:
+ fprintf(stderr, "(%s)\n", err_info);
+ g_free(err_info);
+ break;
+ }
+ }
+
printf("%u frames, %u out of order\n", frames->len, wrong_order_count);
/* Sort the frames */
/* Avoid writing if already sorted and configured to */
if (write_output_regardless || (wrong_order_count > 0)) {
- frame_write(frame, wth, pdh, &buf);
+ frame_write(frame, wth, pdh, &buf, infile);
}
g_slice_free(FrameRecord_t, frame);
}