diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-05-23 10:50:02 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-05-23 10:50:10 +0000 |
commit | a344c9736efe5519543da1290e1ad9065d0b0cff (patch) | |
tree | 7757d80d74ae710e5d4e4a1b0cb638d0ec644fc4 /file.c | |
parent | 716fdc8e398ea7435b23192ab1f7d59e7b21e32b (diff) | |
download | wireshark-a344c9736efe5519543da1290e1ad9065d0b0cff.tar.gz wireshark-a344c9736efe5519543da1290e1ad9065d0b0cff.tar.bz2 wireshark-a344c9736efe5519543da1290e1ad9065d0b0cff.zip |
Revert "Allow wtap_read() and wtap_seek_read() to return non-packet records."
This reverts commit c0c480d08c175eed4524ea9e73ec86298f468cf4.
A better way to do this is to have the record type be part of struct wtap_pkthdr; that keeps the metadata for the record together and requires fewer API changes. That is in-progress.
Change-Id: Ic558f163a48e2c6d0df7f55e81a35a5e24b53bc6
Reviewed-on: https://code.wireshark.org/review/1741
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 87 |
1 files changed, 36 insertions, 51 deletions
@@ -575,7 +575,6 @@ cf_read(capture_file *cf, gboolean reloading) { int err; gchar *err_info; - int rec_type; gchar *name_ptr; progdlg_t *progbar = NULL; gboolean stop_flag; @@ -652,7 +651,7 @@ cf_read(capture_file *cf, gboolean reloading) }else progbar_quantum = 0; - while ((rec_type = wtap_read(cf->wth, &err, &err_info, &data_offset)) != -1) { + while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) { if (size >= 0) { count++; file_pos = wtap_read_so_far(cf->wth); @@ -702,9 +701,7 @@ cf_read(capture_file *cf, gboolean reloading) hours even on fast machines) just to see that it was the wrong file. */ break; } - - if (rec_type == REC_TYPE_PACKET) - read_packet(cf, dfcode, &edt, cinfo, data_offset); + read_packet(cf, dfcode, &edt, cinfo, data_offset); } } CATCH(OutOfMemoryError) { @@ -840,7 +837,6 @@ cf_read(capture_file *cf, gboolean reloading) cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err) { - int rec_type; gchar *err_info; volatile int newly_displayed_packets = 0; dfilter_t *dfcode; @@ -879,7 +875,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err) while (to_read != 0) { wtap_cleareof(cf->wth); - if ((rec_type = wtap_read(cf->wth, err, &err_info, &data_offset)) == -1) { + if (!wtap_read(cf->wth, err, &err_info, &data_offset)) { break; } if (cf->state == FILE_READ_ABORTED) { @@ -888,10 +884,8 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err) aren't any packets left to read) exit. */ break; } - if (rec_type == REC_TYPE_PACKET) { - if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) { - newly_displayed_packets++; - } + if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) { + newly_displayed_packets++; } to_read--; } @@ -965,7 +959,6 @@ cf_fake_continue_tail(capture_file *cf) { cf_read_status_t cf_finish_tail(capture_file *cf, int *err) { - int rec_type; gchar *err_info; gint64 data_offset; dfilter_t *dfcode; @@ -999,15 +992,14 @@ cf_finish_tail(capture_file *cf, int *err) epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE); - while ((rec_type = wtap_read(cf->wth, err, &err_info, &data_offset)) != -1) { + while ((wtap_read(cf->wth, err, &err_info, &data_offset))) { if (cf->state == FILE_READ_ABORTED) { /* Well, the user decided to abort the read. Break out of the loop, and let the code below (which is called even if there aren't any packets left to read) exit. */ break; } - if (rec_type == REC_TYPE_PACKET) - read_packet(cf, dfcode, &edt, cinfo, data_offset); + read_packet(cf, dfcode, &edt, cinfo, data_offset); } /* Cleanup and release all dfilter resources */ @@ -1761,11 +1753,10 @@ cf_redissect_packets(capture_file *cf) } } -int +gboolean cf_read_frame_r(capture_file *cf, const frame_data *fdata, struct wtap_pkthdr *phdr, Buffer *buf) { - int rec_type; int err; gchar *err_info; gchar *display_basename; @@ -1777,19 +1768,17 @@ cf_read_frame_r(capture_file *cf, const frame_data *fdata, if (!frame) { simple_error_message_box("fdata->file_off == -1, but can't find modified frame!"); - return -1; + return FALSE; } *phdr = frame->phdr; buffer_assure_space(buf, frame->phdr.caplen); memcpy(buffer_start_ptr(buf), frame->pd, frame->phdr.caplen); - /* XXX - what if this isn't a packet? */ - return REC_TYPE_PACKET; + return TRUE; } #endif - rec_type = wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info); - if (rec_type == -1) { + if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info)) { display_basename = g_filename_display_basename(cf->filename); switch (err) { @@ -1812,12 +1801,12 @@ cf_read_frame_r(capture_file *cf, const frame_data *fdata, break; } g_free(display_basename); - return -1; + return FALSE; } - return rec_type; + return TRUE; } -int +gboolean cf_read_frame(capture_file *cf, frame_data *fdata) { return cf_read_frame_r(cf, fdata, &cf->phdr, &cf->buf); @@ -2016,7 +2005,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb /* Frame dependencies from the previous dissection/filtering are no longer valid. */ fdata->flags.dependent_of_displayed = 0; - if (cf_read_frame(cf, fdata) == -1) + if (!cf_read_frame(cf, fdata)) break; /* error reading the frame */ /* If the previous frame is displayed, and we haven't yet seen the @@ -2343,7 +2332,7 @@ process_specified_packets(capture_file *cf, packet_range_t *range, } /* Get the packet */ - if (cf_read_frame_r(cf, fdata, &phdr, &buf) == -1) { + if (!cf_read_frame_r(cf, fdata, &phdr, &buf)) { /* Attempt to get the packet failed. */ ret = PSP_FAILED; break; @@ -3120,7 +3109,7 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion) epan_dissect_t edt; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3224,7 +3213,7 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3322,7 +3311,7 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3370,7 +3359,7 @@ match_narrow(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3417,7 +3406,7 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3463,7 +3452,7 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion) size_t c_match = 0; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3533,7 +3522,7 @@ match_dfilter(capture_file *cf, frame_data *fdata, void *criterion) match_result result; /* Load the frame's data. */ - if (cf_read_frame(cf, fdata) == -1) { + if (!cf_read_frame(cf, fdata)) { /* Attempt to get the packet failed. */ return MR_ERROR; } @@ -3859,7 +3848,7 @@ cf_select_packet(capture_file *cf, int row) } /* Get the data in that frame. */ - if (cf_read_frame (cf, fdata) == -1) { + if (!cf_read_frame (cf, fdata)) { return; } @@ -4039,7 +4028,7 @@ cf_get_comment(capture_file *cf, const frame_data *fd) memset(&phdr, 0, sizeof(struct wtap_pkthdr)); buffer_init(&buf, 1500); - if (cf_read_frame_r(cf, fd, &phdr, &buf) == -1) + if (!cf_read_frame_r(cf, fd, &phdr, &buf)) { /* XXX, what we can do here? */ } buffer_free(&buf); @@ -4333,7 +4322,6 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) { const struct wtap_pkthdr *phdr; gchar *err_info; - int rec_type; gchar *name_ptr; gint64 data_offset; gint64 file_pos; @@ -4420,7 +4408,10 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) framenum = 0; phdr = wtap_phdr(cf->wth); - while ((rec_type = wtap_read(cf->wth, err, &err_info, &data_offset)) != -1) { + while ((wtap_read(cf->wth, err, &err_info, &data_offset))) { + framenum++; + fdata = frame_data_sequence_find(cf->frames, framenum); + fdata->file_off = data_offset; if (size >= 0) { count++; file_pos = wtap_read_so_far(cf->wth); @@ -4464,19 +4455,13 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) break; } - if (rec_type == REC_TYPE_PACKET) { - framenum++; - fdata = frame_data_sequence_find(cf->frames, framenum); - fdata->file_off = data_offset; - - /* Add this packet's link-layer encapsulation type to cf->linktypes, if - it's not already there. - XXX - yes, this is O(N), so if every packet had a different - link-layer encapsulation type, it'd be O(N^2) to read the file, but - there are probably going to be a small number of encapsulation types - in a file. */ - cf_add_encapsulation_type(cf, phdr->pkt_encap); - } + /* Add this packet's link-layer encapsulation type to cf->linktypes, if + it's not already there. + XXX - yes, this is O(N), so if every packet had a different + link-layer encapsulation type, it'd be O(N^2) to read the file, but + there are probably going to be a small number of encapsulation types + in a file. */ + cf_add_encapsulation_type(cf, phdr->pkt_encap); } /* Free the display name */ |