diff options
-rw-r--r-- | cfile.h | 3 | ||||
-rw-r--r-- | file.c | 47 | ||||
-rw-r--r-- | summary.c | 4 | ||||
-rw-r--r-- | summary.h | 3 | ||||
-rw-r--r-- | ui/gtk/summary_dlg.c | 14 |
5 files changed, 61 insertions, 10 deletions
@@ -74,7 +74,8 @@ typedef struct _capture_file { gint64 f_datalen; /* Size of capture file data (uncompressed) */ guint16 cd_t; /* File type of capture file */ gboolean iscompressed; /* TRUE if the file is compressed */ - int lnk_t; /* Link-layer type with which to save capture */ + int lnk_t; /* File link-layer type; could be WTAP_ENCAP_PER_PACKET */ + GArray *linktypes; /* Array of packet link-layer types */ guint32 count; /* Total number of frames */ guint32 displayed_count; /* Number of displayed frames */ guint32 marked_count; /* Number of marked frames */ @@ -312,6 +312,7 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) reset_elapsed(); cf->cd_t = wtap_file_type(cf->wth); + cf->linktypes = g_array_sized_new(FALSE, FALSE, (guint) sizeof(int), 1); cf->count = 0; cf->displayed_count = 0; cf->marked_count = 0; @@ -357,6 +358,21 @@ fail: return CF_ERROR; } +/* + * Add an encapsulation type to cf->linktypes. + */ +void +cf_add_encapsulation_type(capture_file *cf, int encap) +{ + guint i; + + for (i = 0; i < cf->linktypes->len; i++) { + if (g_array_index(cf->linktypes, gint, i) == encap) + return; /* it's already there */ + } + /* It's not already there - add it. */ + g_array_append_val(cf->linktypes, encap); +} /* * Reset the state for the currently closed file, but don't do the @@ -411,6 +427,10 @@ cf_reset_state(capture_file *cf) cf->current_row = 0; cf->finfo_selected = NULL; + /* No frame link-layer types, either. */ + g_array_free(cf->linktypes, TRUE); + cf->linktypes = NULL; + /* Clear the packet list. */ new_packet_list_freeze(); new_packet_list_clear(); @@ -530,7 +550,8 @@ cf_read(capture_file *cf, gboolean reloading) else cf_callback_invoke(cf_cb_file_read_started, cf); - /* Record whether the file is compressed. */ + /* Record whether the file is compressed. + XXX - do we know this at open time? */ cf->iscompressed = wtap_iscompressed(cf->wth); /* Find the size of the file. */ @@ -922,7 +943,7 @@ cf_finish_tail(capture_file *cf, int *err) 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. */ + aren't any packets left to read) exit. */ break; } read_packet(cf, dfcode, filtering_tap_listeners, tap_flags, data_offset); @@ -1198,6 +1219,14 @@ read_packet(capture_file *cf, dfilter_t *dfcode, int passed; int row = -1; + /* 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); + /* The frame number of this packet is one more than the count of frames in the file so far. */ framenum = cf->count + 1; @@ -3831,6 +3860,7 @@ cf_can_save_as(capture_file *cf) static cf_read_status_t rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) { + const struct wtap_pkthdr *phdr; gchar *err_info; gchar *name_ptr; const char *errmsg; @@ -3878,6 +3908,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) cf->unsaved_changes = FALSE; cf->cd_t = wtap_file_type(cf->wth); + cf->linktypes = g_array_sized_new(FALSE, FALSE, (guint) sizeof(int), 1); cf->snap = wtap_snapshot_length(cf->wth); if (cf->snap == 0) { @@ -3891,7 +3922,8 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) cf_callback_invoke(cf_cb_file_rescan_started, cf); - /* Record whether the file is compressed. */ + /* Record whether the file is compressed. + XXX - do we know this at open time? */ cf->iscompressed = wtap_iscompressed(cf->wth); /* Find the size of the file. */ @@ -3914,6 +3946,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) g_get_current_time(&start_time); framenum = 0; + phdr = wtap_phdr(cf->wth); while ((wtap_read(cf->wth, err, &err_info, &data_offset))) { framenum++; fdata = frame_data_sequence_find(cf->frames, framenum); @@ -3960,6 +3993,14 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) close the current capture. */ break; } + + /* 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 */ @@ -149,7 +149,8 @@ summary_fill_in(capture_file *cf, summary_tally *st) st->file_type = cf->cd_t; st->iscompressed = cf->iscompressed; st->is_tempfile = cf->is_tempfile; - st->encap_type = cf->lnk_t; + st->file_encap_type = cf->lnk_t; + st->packet_encap_types = cf->linktypes; st->has_snap = cf->has_snap; st->snap = cf->snap; st->elapsed_time = nstime_to_sec(&cf->elapsed_time); @@ -197,7 +198,6 @@ summary_fill_in(capture_file *cf, summary_tally *st) g_free(idb_info); } - #ifdef HAVE_LIBPCAP void summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st) @@ -65,7 +65,8 @@ typedef struct _summary_tally { gint64 file_length; /**< file length in bytes */ int file_type; /**< wiretap file type */ int iscompressed; /**< TRUE if file is compressed */ - int encap_type; /**< wiretap encapsulation type */ + int file_encap_type; /**< wiretap encapsulation type for file */ + GArray *packet_encap_types; /**< wiretap encapsulation types for packets */ gboolean has_snap; /**< TRUE if maximum capture packet length is known */ int snap; /**< Maximum captured packet length */ gboolean drops_known; /**< TRUE if number of packet drops is known */ diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c index b79776be16..175cab550f 100644 --- a/ui/gtk/summary_dlg.c +++ b/ui/gtk/summary_dlg.c @@ -247,9 +247,17 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) add_string_to_table(table, &row, "Format:", string_buff); /* encapsulation */ - g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.encap_type)); - add_string_to_table(table, &row, "Encapsulation:", string_buff); - + if (summary.file_encap_type == WTAP_ENCAP_PER_PACKET) { + for (i = 0; i < summary.packet_encap_types->len; i++) { + g_snprintf(string_buff, SUM_STR_MAX, "%s", + wtap_encap_string(g_array_index(summary.packet_encap_types, int, i))); + add_string_to_table(table, &row, (i == 0) ? "Encapsulation:" : "", + string_buff); + } + } else { + g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_encap_string(summary.file_encap_type)); + add_string_to_table(table, &row, "Encapsulation:", string_buff); + } if (summary.has_snap) { /* snapshot length */ g_snprintf(string_buff, SUM_STR_MAX, "%u bytes", summary.snap); |