Pull code to fill in a wtap_pkthdr into a hcidump_process_header()

routine, and use it in both the read and seek-read routines.

svn path=/trunk/; revision=49365
This commit is contained in:
Guy Harris 2013-05-17 05:31:21 +00:00
parent f296630024
commit a335cd8d87
1 changed files with 30 additions and 29 deletions

View File

@ -36,18 +36,15 @@ struct dump_hdr {
#define DUMP_HDR_SIZE (sizeof(struct dump_hdr))
static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
static gboolean hcidump_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
int *err, gchar **err_info)
{
struct dump_hdr dh;
guint8 *buf;
int bytes_read, packet_size;
*data_offset = file_tell(wth->fh);
bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh);
bytes_read = file_read(&dh, DUMP_HDR_SIZE, fh);
if (bytes_read != DUMP_HDR_SIZE) {
*err = file_error(wth->fh, err_info);
*err = file_error(fh, err_info);
if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
@ -65,25 +62,38 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
return FALSE;
}
buffer_assure_space(wth->frame_buffer, packet_size);
phdr->presence_flags = WTAP_HAS_TS;
phdr->ts.secs = GUINT32_FROM_LE(dh.ts_sec);
phdr->ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000;
phdr->caplen = packet_size;
phdr->len = packet_size;
phdr->pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE);
return TRUE;
}
static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
guint8 *buf;
int bytes_read;
*data_offset = file_tell(wth->fh);
if (!hcidump_process_header(wth->fh, &wth->phdr, err, err_info))
return FALSE;
buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
buf = buffer_start_ptr(wth->frame_buffer);
bytes_read = file_read(buf, packet_size, wth->fh);
if (bytes_read != packet_size) {
bytes_read = file_read(buf, wth->phdr.caplen, wth->fh);
if (bytes_read == -1 || (guint32)bytes_read != wth->phdr.caplen) {
*err = file_error(wth->fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
wth->phdr.presence_flags = WTAP_HAS_TS;
wth->phdr.ts.secs = GUINT32_FROM_LE(dh.ts_sec);
wth->phdr.ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000;
wth->phdr.caplen = packet_size;
wth->phdr.len = packet_size;
wth->phdr.pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE);
return TRUE;
}
@ -91,20 +101,13 @@ static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, guint8 *pd, int length,
int *err, gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
struct dump_hdr dh;
int bytes_read;
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->random_fh);
if (bytes_read != DUMP_HDR_SIZE) {
*err = file_error(wth->random_fh, err_info);
if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
if (!hcidump_process_header(wth->random_fh, phdr, err, err_info))
return FALSE;
}
bytes_read = file_read(pd, length, wth->random_fh);
if (bytes_read != length) {
@ -114,8 +117,6 @@ static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off,
return FALSE;
}
pseudo_header->p2p.sent = (dh.in ? FALSE : TRUE);
return TRUE;
}