forked from osmocom/wireshark
Get rid of f_len field in capture_file structure - we can just keep
the length locally. within cf_read(). svn path=/trunk/; revision=15454
This commit is contained in:
parent
980b568a3d
commit
53b54d11ed
1
cfile.h
1
cfile.h
|
@ -47,7 +47,6 @@ typedef struct _capture_file {
|
||||||
gboolean is_tempfile; /* Is capture file a temporary file? */
|
gboolean is_tempfile; /* Is capture file a temporary file? */
|
||||||
gboolean user_saved;/* If capture file is temporary, has it been saved by user yet? */
|
gboolean user_saved;/* If capture file is temporary, has it been saved by user yet? */
|
||||||
long f_datalen; /* Size of capture file data (uncompressed) */
|
long f_datalen; /* Size of capture file data (uncompressed) */
|
||||||
gint64 f_len; /* Length of capture file (compressed if file is) */
|
|
||||||
guint16 cd_t; /* File type of capture file */
|
guint16 cd_t; /* File type of capture file */
|
||||||
int lnk_t; /* Link-layer type with which to save capture */
|
int lnk_t; /* Link-layer type with which to save capture */
|
||||||
guint32 vers; /* Version. For tcpdump minor is appended to major */
|
guint32 vers; /* Version. For tcpdump minor is appended to major */
|
||||||
|
|
93
file.c
93
file.c
|
@ -167,19 +167,11 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
|
||||||
{
|
{
|
||||||
wtap *wth;
|
wtap *wth;
|
||||||
gchar *err_info;
|
gchar *err_info;
|
||||||
gint64 size;
|
|
||||||
|
|
||||||
wth = wtap_open_offline(fname, err, &err_info, TRUE);
|
wth = wtap_open_offline(fname, err, &err_info, TRUE);
|
||||||
if (wth == NULL)
|
if (wth == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* Find the size of the file. */
|
|
||||||
size = wtap_file_size(wth, err);
|
|
||||||
if (size == -1) {
|
|
||||||
wtap_close(wth);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The open succeeded. Close whatever capture file we had open,
|
/* The open succeeded. Close whatever capture file we had open,
|
||||||
and fill in the information for this file. */
|
and fill in the information for this file. */
|
||||||
cf_reset_state(cf);
|
cf_reset_state(cf);
|
||||||
|
@ -192,7 +184,6 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
|
||||||
|
|
||||||
cf->wth = wth;
|
cf->wth = wth;
|
||||||
cf->f_datalen = 0;
|
cf->f_datalen = 0;
|
||||||
cf->f_len = size;
|
|
||||||
|
|
||||||
/* Set the file name because we need it to set the follow stream filter.
|
/* Set the file name because we need it to set the follow stream filter.
|
||||||
XXX - is that still true? We need it for other reasons, though,
|
XXX - is that still true? We need it for other reasons, though,
|
||||||
|
@ -291,7 +282,6 @@ cf_reset_state(capture_file *cf)
|
||||||
packet_list_thaw();
|
packet_list_thaw();
|
||||||
|
|
||||||
cf->f_datalen = 0;
|
cf->f_datalen = 0;
|
||||||
cf->f_len = 0;
|
|
||||||
cf->count = 0;
|
cf->count = 0;
|
||||||
cf->esec = 0;
|
cf->esec = 0;
|
||||||
cf->eusec = 0;
|
cf->eusec = 0;
|
||||||
|
@ -343,11 +333,17 @@ cf_read(capture_file *cf)
|
||||||
|
|
||||||
name_ptr = get_basename(cf->filename);
|
name_ptr = get_basename(cf->filename);
|
||||||
|
|
||||||
|
/* Find the size of the file. */
|
||||||
|
size = wtap_file_size(cf->wth, NULL);
|
||||||
|
|
||||||
/* Update the progress bar when it gets to this value. */
|
/* Update the progress bar when it gets to this value. */
|
||||||
progbar_nextstep = 0;
|
progbar_nextstep = 0;
|
||||||
/* When we reach the value that triggers a progress bar update,
|
/* When we reach the value that triggers a progress bar update,
|
||||||
bump that value by this amount. */
|
bump that value by this amount. */
|
||||||
progbar_quantum = cf->f_len/N_PROGBAR_UPDATES;
|
if (size >= 0)
|
||||||
|
progbar_quantum = size/N_PROGBAR_UPDATES;
|
||||||
|
else
|
||||||
|
progbar_quantum = 0;
|
||||||
|
|
||||||
packet_list_freeze();
|
packet_list_freeze();
|
||||||
|
|
||||||
|
@ -355,41 +351,41 @@ cf_read(capture_file *cf)
|
||||||
g_get_current_time(&start_time);
|
g_get_current_time(&start_time);
|
||||||
|
|
||||||
while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
|
while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
|
||||||
/* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
|
if (size >= 0) {
|
||||||
when we update it, we have to run the GTK+ main loop to get it
|
/* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
|
||||||
to repaint what's pending, and doing so may involve an "ioctl()"
|
when we update it, we have to run the GTK+ main loop to get it
|
||||||
to see if there's any pending input from an X server, and doing
|
to repaint what's pending, and doing so may involve an "ioctl()"
|
||||||
that for every packet can be costly, especially on a big file. */
|
to see if there's any pending input from an X server, and doing
|
||||||
if (data_offset >= progbar_nextstep) {
|
that for every packet can be costly, especially on a big file. */
|
||||||
file_pos = wtap_read_so_far(cf->wth, NULL);
|
if (data_offset >= progbar_nextstep) {
|
||||||
prog_val = (gfloat) file_pos / (gfloat) cf->f_len;
|
file_pos = wtap_read_so_far(cf->wth, NULL);
|
||||||
if (prog_val > 1.0) {
|
prog_val = (gfloat) file_pos / (gfloat) size;
|
||||||
/* The file probably grew while we were reading it.
|
if (prog_val > 1.0) {
|
||||||
Update "cf->f_len", and try again. */
|
/* The file probably grew while we were reading it.
|
||||||
size = wtap_file_size(cf->wth, NULL);
|
Update file size, and try again. */
|
||||||
if (size != -1) {
|
size = wtap_file_size(cf->wth, NULL);
|
||||||
cf->f_len = size;
|
if (size >= 0)
|
||||||
prog_val = (gfloat) file_pos / (gfloat) cf->f_len;
|
prog_val = (gfloat) file_pos / (gfloat) size;
|
||||||
|
/* If it's still > 1, either "wtap_file_size()" failed (in which
|
||||||
|
case there's not much we can do about it), or the file
|
||||||
|
*shrank* (in which case there's not much we can do about
|
||||||
|
it); just clip the progress value at 1.0. */
|
||||||
|
if (prog_val > 1.0)
|
||||||
|
prog_val = 1.0;
|
||||||
}
|
}
|
||||||
/* If it's still > 1, either "wtap_file_size()" failed (in which
|
if (progbar == NULL) {
|
||||||
case there's not much we can do about it), or the file
|
/* Create the progress bar if necessary */
|
||||||
*shrank* (in which case there's not much we can do about
|
progbar = delayed_create_progress_dlg("Loading", name_ptr,
|
||||||
it); just clip the progress value at 1.0. */
|
&stop_flag, &start_time, prog_val);
|
||||||
if (prog_val > 1.0)
|
}
|
||||||
prog_val = 1.0;
|
if (progbar != NULL) {
|
||||||
}
|
g_snprintf(status_str, sizeof(status_str),
|
||||||
if (progbar == NULL) {
|
"%" PRId64 "KB of %" PRId64 "KB",
|
||||||
/* Create the progress bar if necessary */
|
file_pos / 1024, size / 1024);
|
||||||
progbar = delayed_create_progress_dlg("Loading", name_ptr,
|
update_progress_dlg(progbar, prog_val, status_str);
|
||||||
&stop_flag, &start_time, prog_val);
|
}
|
||||||
}
|
progbar_nextstep += progbar_quantum;
|
||||||
if (progbar != NULL) {
|
}
|
||||||
g_snprintf(status_str, sizeof(status_str),
|
|
||||||
"%" PRId64 "KB of %" PRId64 "KB",
|
|
||||||
file_pos / 1024, cf->f_len / 1024);
|
|
||||||
update_progress_dlg(progbar, prog_val, status_str);
|
|
||||||
}
|
|
||||||
progbar_nextstep += progbar_quantum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stop_flag) {
|
if (stop_flag) {
|
||||||
|
@ -539,7 +535,6 @@ cf_finish_tail(capture_file *cf, int *err)
|
||||||
{
|
{
|
||||||
gchar *err_info;
|
gchar *err_info;
|
||||||
long data_offset;
|
long data_offset;
|
||||||
gint64 size;
|
|
||||||
|
|
||||||
if(cf->wth == NULL) {
|
if(cf->wth == NULL) {
|
||||||
cf_close(cf);
|
cf_close(cf);
|
||||||
|
@ -577,12 +572,6 @@ cf_finish_tail(capture_file *cf, int *err)
|
||||||
/* We're done reading sequentially through the file. */
|
/* We're done reading sequentially through the file. */
|
||||||
cf->state = FILE_READ_DONE;
|
cf->state = FILE_READ_DONE;
|
||||||
|
|
||||||
/* we have to update the f_len field */
|
|
||||||
/* Find the size of the file. */
|
|
||||||
size = wtap_file_size(cf->wth, NULL);
|
|
||||||
if (size != -1)
|
|
||||||
cf->f_len = size;
|
|
||||||
|
|
||||||
/* We're done reading sequentially through the file; close the
|
/* We're done reading sequentially through the file; close the
|
||||||
sequential I/O side, to free up memory it requires. */
|
sequential I/O side, to free up memory it requires. */
|
||||||
wtap_sequential_close(cf->wth);
|
wtap_sequential_close(cf->wth);
|
||||||
|
|
|
@ -2971,7 +2971,6 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
|
||||||
|
|
||||||
cf->wth = wth;
|
cf->wth = wth;
|
||||||
cf->f_datalen = 0; /* not used, but set it anyway */
|
cf->f_datalen = 0; /* not used, but set it anyway */
|
||||||
cf->f_len = 0; /* not used, but set it anyway */
|
|
||||||
|
|
||||||
/* Set the file name because we need it to set the follow stream filter.
|
/* Set the file name because we need it to set the follow stream filter.
|
||||||
XXX - is that still true? We need it for other reasons, though,
|
XXX - is that still true? We need it for other reasons, though,
|
||||||
|
|
Loading…
Reference in New Issue