static void frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh) { 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, buf, frame->length, &err, &errinfo); DEBUG_PRINT("re-read: err is %d, buf is (%s)\n", err, buf); /* Copy, and set length and timestamp from item. */ /* TODO: remove when wtap_seek_read() will read phdr */ phdr.ts = frame->time; /* Dump frame to outfile */ if (!wtap_dump(pdh, &phdr, buf, &err)) { printf("Error (%s) writing frame to outfile\n", wtap_strerror(err)); exit(1); } }
static gboolean nettrace_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec, Buffer *buf, int *err, gchar **err_info) { struct Buffer *frame_buffer_saved; gboolean result; nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; frame_buffer_saved = file_info->wth_tmp_file->rec_data; file_info->wth_tmp_file->rec_data = wth->rec_data; result = wtap_seek_read(file_info->wth_tmp_file, seek_off, rec, buf, err, err_info); file_info->wth_tmp_file->rec_data = frame_buffer_saved; return result; }
static gboolean nettrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info) { struct Buffer *frame_buffer_saved; gboolean result; nettrace_3gpp_32_423_file_info_t *file_info = (nettrace_3gpp_32_423_file_info_t *)wth->priv; frame_buffer_saved = file_info->wth_tmp_file->frame_buffer; file_info->wth_tmp_file->frame_buffer = wth->frame_buffer; result = wtap_seek_read(file_info->wth_tmp_file, seek_off, phdr, buf, err, err_info); file_info->wth_tmp_file->frame_buffer = frame_buffer_saved; return result; }
static void frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf, const char *infile) { int err; gchar *err_info; struct wtap_pkthdr phdr; memset(&phdr, 0, sizeof(struct wtap_pkthdr)); DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u)\n", frame->offset); /* Re-read the first frame from the stored location */ if (!wtap_seek_read(wth, frame->offset, &phdr, buf, &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 */ phdr.ts = frame->time; /* Dump frame to outfile */ if (!wtap_dump(pdh, &phdr, buffer_start_ptr(buf), &err)) { fprintf(stderr, "reordercap: Error (%s) writing frame to outfile\n", wtap_strerror(err)); exit(1); } }
static void frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, struct wtap_pkthdr *phdr, Buffer *buf, const char *infile) { int err; gchar *err_info; DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u)\n", frame->offset); /* Re-read the frame from the stored location */ if (!wtap_seek_read(wth, frame->offset, phdr, buf, &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)); if (err_info != NULL) { fprintf(stderr, "(%s)\n", err_info); g_free(err_info); } exit(1); } } /* Copy, and set length and timestamp from item. */ /* TODO: remove when wtap_seek_read() fills in phdr, including time stamps, for all file types */ phdr->ts = frame->frame_time; /* Dump frame to outfile */ if (!wtap_dump(pdh, phdr, ws_buffer_start_ptr(buf), &err, &err_info)) { fprintf(stderr, "reordercap: Error (%s) writing frame to outfile\n", wtap_strerror(err)); if (err_info != NULL) { fprintf(stderr, "(%s)\n", err_info); g_free(err_info); } exit(1); } }
static gboolean frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf) { int err; gchar *err_info; /* sanity check, capture file was closed? */ if (cfile.wth != frame_tvb->wth) return FALSE; if (!wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, frame_tvb->tvb.length + frame_tvb->offset, &err, &err_info)) { switch (err) { case WTAP_ERR_UNSUPPORTED_ENCAP: case WTAP_ERR_BAD_FILE: g_free(err_info); break; } return FALSE; } return TRUE; }
static void frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, wtap_rec *rec, Buffer *buf, const char *infile, const char *outfile) { int err; gchar *err_info; DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u)\n", frame->offset); /* Re-read the frame from the stored location */ if (!wtap_seek_read(wth, frame->offset, rec, buf, &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\".\n", infile); cfile_read_failure_message("reordercap", infile, err, err_info); exit(1); } } /* Copy, and set length and timestamp from item. */ /* TODO: remove when wtap_seek_read() fills in rec, including time stamps, for all file types */ rec->ts = frame->frame_time; /* Dump frame to outfile */ if (!wtap_dump(pdh, rec, ws_buffer_start_ptr(buf), &err, &err_info)) { cfile_write_failure_message("reordercap", infile, outfile, err, err_info, frame->num, wtap_file_type_subtype(wth)); exit(1); } }
static gboolean frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf) { int err; gchar *err_info; /* sanity check, capture file was closed? */ if (cfile.wth != frame_tvb->wth) return FALSE; /* XXX, what if phdr->caplen isn't equal to * frame_tvb->tvb.length + frame_tvb->offset? */ if (!wtap_seek_read(frame_tvb->wth, frame_tvb->file_off, phdr, buf, &err, &err_info)) { /* XXX - report error! */ switch (err) { case WTAP_ERR_BAD_FILE: g_free(err_info); break; } return FALSE; } return TRUE; }