Pull the code to set the wtap_pkthdr into a common routine, so it's done

for read and seek-read.

Clarify a comment.  (wtap_open_offline() only rewinds the file before
calling each open routine; once one of those routines has decided the
file belongs to it, the seek offset belongs to it, so it needs to do all
the seeking necessary - files with a file header *don't* want a rewind,
they want to leave the seek offset positioned *past* the file header so
it can read the records that follow the file header.)

svn path=/trunk/; revision=49347
This commit is contained in:
Guy Harris 2013-05-16 22:01:44 +00:00
parent 609dac2f9e
commit 13262726bc
1 changed files with 16 additions and 7 deletions

View File

@ -258,6 +258,16 @@ create_pseudo_hdr(guint8 *buf, guint8 dat_trans_type, guint16 dat_len)
}
static void
fill_in_phdr(struct wtap_pkthdr *phdr, gint offset)
{
phdr->pkt_encap = WTAP_ENCAP_DVBCI;
/* timestamps aren't supported for now */
phdr->caplen = offset;
phdr->len = offset;
}
static gboolean
camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
@ -293,11 +303,7 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
offset += bytes_read;
wth->phdr.pkt_encap = WTAP_ENCAP_DVBCI;
wth->phdr.ts.secs = 0; /* timestamps aren't supported for now */
wth->phdr.ts.nsecs = 0;
wth->phdr.caplen = offset;
wth->phdr.len = offset;
fill_in_phdr(&wth->phdr, offset);
return TRUE;
}
@ -305,7 +311,7 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
static gboolean
camins_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *pkthdr _U_, guint8 *pd, int length,
struct wtap_pkthdr *pkthdr, guint8 *pd, int length,
int *err, gchar **err_info)
{
guint8 dat_trans_type;
@ -337,6 +343,9 @@ camins_seek_read(wtap *wth, gint64 seek_off,
/* see comment in camins_read() */
if (bytes_read < 0)
return FALSE;
offset += bytes_read;
fill_in_phdr(pkthdr, offset);
return TRUE;
}
@ -366,7 +375,7 @@ int camins_open(wtap *wth, int *err, gchar **err_info _U_)
if (found_start_blocks < 2)
return 0; /* no CAM Inspector file */
/* wtap_open_offline() does not rewind the fh, let's do it ourselves */
/* rewind the fh so we re-read from the beginning */
if (-1 == file_seek(wth->fh, 0, SEEK_SET, err))
return -1;