aboutsummaryrefslogtreecommitdiffstats
path: root/reordercap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-07-26 21:49:42 +0000
committerGuy Harris <guy@alum.mit.edu>2013-07-26 21:49:42 +0000
commit6580abbbc31c22060e819cfb8b1b8484028b62ec (patch)
treee0b216282b2fa89ee0ad80fb9a8d345ab49be34a /reordercap.c
parent9df4d49905a0cae63ec967f9cbe93570022bf3fb (diff)
Give more detailed diagnostics for errors.
Actually *check* for errors when reading. svn path=/trunk/; revision=50934
Diffstat (limited to 'reordercap.c')
-rw-r--r--reordercap.c59
1 files changed, 48 insertions, 11 deletions
diff --git a/reordercap.c b/reordercap.c
index 1e29303908..2303b100dc 100644
--- a/reordercap.c
+++ b/reordercap.c
@@ -82,10 +82,11 @@ typedef struct 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",
@@ -93,14 +94,25 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf)
/* 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 */
@@ -203,6 +215,15 @@ int main(int argc, char *argv[])
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));
@@ -243,6 +264,22 @@ int main(int argc, char *argv[])
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 */
@@ -257,7 +294,7 @@ int main(int argc, char *argv[])
/* 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);
}