gint64 *data_offset);
static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err,
+ Buffer *buf, int length, int *err,
gchar **err_info);
static gboolean packetlogger_read_header(packetlogger_header_t *pl_hdr,
FILE_T fh, int *err, gchar **err_info);
-static gboolean packetlogger_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info);
+static gboolean packetlogger_read_packet(FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err,
+ gchar **err_info);
int packetlogger_open(wtap *wth, int *err, gchar **err_info)
{
wth->subtype_read = packetlogger_read;
wth->subtype_seek_read = packetlogger_seek_read;
- wth->file_type = WTAP_FILE_PACKETLOGGER;
+ wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_PACKETLOGGER;
wth->file_encap = WTAP_ENCAP_PACKETLOGGER;
wth->tsprecision = WTAP_FILE_TSPREC_USEC;
static gboolean
packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
- guint bytes_read;
-
*data_offset = file_tell(wth->fh);
- if(!packetlogger_process_header(wth->fh, &wth->phdr, err, err_info))
- return FALSE;
-
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- bytes_read = file_read(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen,
- wth->fh);
- if(bytes_read != wth->phdr.caplen) {
- *err = file_error(wth->fh, err_info);
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
-
- return FALSE;
- }
-
- return TRUE;
+ return packetlogger_read_packet(wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info);
}
static gboolean
packetlogger_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- guint8 *pd, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
- guint bytes_read;
-
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- if(!packetlogger_process_header(wth->random_fh, phdr, err, err_info)) {
+ if(!packetlogger_read_packet(wth->random_fh, phdr, buf, err, err_info)) {
if(*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- if((guint32)length != phdr->caplen) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("packetlogger: record length %u doesn't match requested length %d", phdr->caplen, length);
- return FALSE;
- }
-
- bytes_read = file_read(pd, phdr->caplen, wth->random_fh);
- if(bytes_read != phdr->caplen) {
- *err = file_error(wth->random_fh, err_info);
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
-
- return FALSE;
- }
-
return TRUE;
}
}
static gboolean
-packetlogger_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+packetlogger_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+ int *err, gchar **err_info)
{
packetlogger_header_t pl_hdr;
phdr->ts.secs = (time_t) (pl_hdr.ts >> 32);
phdr->ts.nsecs = (int)((pl_hdr.ts & 0xFFFFFFFF) * 1000);
- return TRUE;
+ return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
}