summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wiretap/ber.c54
-rw-r--r--wiretap/btsnoop.c34
-rw-r--r--wiretap/camins.c80
-rw-r--r--wiretap/commview.c30
-rw-r--r--wiretap/cosine.c9
-rw-r--r--wiretap/csids.c50
-rw-r--r--wiretap/daintree-sna.c12
-rw-r--r--wiretap/dbs-etherwatch.c62
-rw-r--r--wiretap/dct3trace.c109
-rw-r--r--wiretap/eyesdn.c72
-rw-r--r--wiretap/hcidump.c21
-rw-r--r--wiretap/i4btrace.c52
-rw-r--r--wiretap/ipfix.c35
-rw-r--r--wiretap/iptrace.c74
-rw-r--r--wiretap/iseries.c27
-rw-r--r--wiretap/lanalyzer.c36
-rw-r--r--wiretap/libpcap.c60
-rw-r--r--wiretap/nettl.c164
-rw-r--r--wiretap/packetlogger.c32
-rw-r--r--wiretap/peekclassic.c98
-rw-r--r--wiretap/peektagged.c34
-rw-r--r--wiretap/radcom.c65
-rw-r--r--wiretap/snoop.c93
-rw-r--r--wiretap/toshiba.c81
-rw-r--r--wiretap/visual.c153
-rw-r--r--wiretap/vms.c56
26 files changed, 604 insertions, 989 deletions
diff --git a/wiretap/ber.c b/wiretap/ber.c
index 32c0f2cede..5c83eb9a70 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -40,8 +40,27 @@
#define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */
#define BER_UNI_TAG_SET 17 /* SET, SET OF */
-static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
+static gboolean ber_read_file(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
+ gint64 file_size;
+ int packet_size;
+
+ if ((file_size = wtap_file_size(wth, err)) == -1)
+ return FALSE;
+
+ if (file_size > WTAP_MAX_PACKET_SIZE) {
+ /*
+ * Probably a corrupt capture file; don't blow up trying
+ * to allocate space for an immensely-large packet.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("ber: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
+ file_size, WTAP_MAX_PACKET_SIZE);
+ return FALSE;
+ }
+ packet_size = (int)file_size;
+
phdr->presence_flags = 0; /* yes, we have no bananas^Wtime stamp */
phdr->caplen = packet_size;
@@ -49,13 +68,13 @@ static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)
phdr->ts.secs = 0;
phdr->ts.nsecs = 0;
+
+ return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
gint64 offset;
- gint64 file_size;
- int packet_size;
*err = 0;
@@ -67,32 +86,12 @@ static gboolean ber_read(wtap *wth, int *err, gchar **err_info, gint64 *data_off
*data_offset = offset;
- if ((file_size = wtap_file_size(wth, err)) == -1)
- return FALSE;
-
- if (file_size > WTAP_MAX_PACKET_SIZE) {
- /*
- * Probably a corrupt capture file; don't blow up trying
- * to allocate space for an immensely-large packet.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("ber: File has %" G_GINT64_MODIFIER "d-byte packet, bigger than maximum of %u",
- file_size, WTAP_MAX_PACKET_SIZE);
- return FALSE;
- }
- packet_size = (int)file_size;
-
- ber_set_pkthdr(&wth->phdr, packet_size);
-
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, packet_size,
- err, err_info);
+ return ber_read_file(wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
}
static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr _U_,
- Buffer *buf, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
- int packet_size = length;
-
/* there is only one packet */
if(seek_off > 0) {
*err = 0;
@@ -102,10 +101,7 @@ static gboolean ber_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *ph
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- ber_set_pkthdr(phdr, packet_size);
-
- return wtap_read_packet_bytes(wth->random_fh, buf, packet_size,
- err, err_info);
+ return ber_read_file(wth, wth->random_fh, phdr, buf, err, err_info);
}
int ber_open(wtap *wth, int *err, gchar **err_info)
diff --git a/wiretap/btsnoop.c b/wiretap/btsnoop.c
index cb44f4e51a..ce16c2fa6d 100644
--- a/wiretap/btsnoop.c
+++ b/wiretap/btsnoop.c
@@ -76,8 +76,8 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
-static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info);
+static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
int btsnoop_open(wtap *wth, int *err, gchar **err_info)
{
@@ -157,33 +157,22 @@ static gboolean btsnoop_read(wtap *wth, int *err, gchar **err_info,
{
*data_offset = file_tell(wth->fh);
- /* Read record header. */
- if (!btsnoop_read_record_header(wth, wth->fh, &wth->phdr, err, err_info))
- return FALSE;
-
- /* Read packet data. */
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info);
+ return btsnoop_read_record(wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
static gboolean btsnoop_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read record header. */
- if (!btsnoop_read_record_header(wth, wth->random_fh, phdr, err, err_info))
- return FALSE;
-
- /* Read packet data. */
- return wtap_read_packet_bytes(wth->random_fh, buf, length, err,
- err_info);
+ return btsnoop_read_record(wth, wth->random_fh, phdr, buf, err, err_info);
}
-static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info)
+static gboolean btsnoop_read_record(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
int bytes_read;
struct btsnooprec_hdr hdr;
@@ -192,6 +181,8 @@ static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
guint32 orig_size;
gint64 ts;
+ /* Read record header. */
+
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&hdr, sizeof hdr, fh);
if (bytes_read != sizeof hdr) {
@@ -246,7 +237,10 @@ static gboolean btsnoop_read_record_header(wtap *wth, FILE_T fh,
phdr->pseudo_header.bthci.channel = BTHCI_CHANNEL_ACL;
}
}
- return TRUE;
+
+
+ /* Read packet data. */
+ return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
}
/* Returns 0 if we could write the specified encapsulation type,
diff --git a/wiretap/camins.c b/wiretap/camins.c
index 44381ed34d..121808d329 100644
--- a/wiretap/camins.c
+++ b/wiretap/camins.c
@@ -258,34 +258,20 @@ 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)
+gboolean
+camins_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+ int *err, gchar **err_info)
{
guint8 dat_trans_type;
guint16 dat_len;
- gboolean ret;
guint8 *p;
gint offset, bytes_read;
- *data_offset = file_tell(wth->fh);
-
- ret = find_next_pkt_dat_type_len(
- wth->fh, &dat_trans_type, &dat_len, err, err_info);
- if (!ret)
+ if (!find_next_pkt_dat_type_len(fh, &dat_trans_type, &dat_len, err, err_info))
return FALSE;
- buffer_assure_space(wth->frame_buffer, DVB_CI_PSEUDO_HDR_LEN+dat_len);
- p = buffer_start_ptr(wth->frame_buffer);
+ buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len);
+ p = buffer_start_ptr(buf);
/* NULL check for p is done in create_pseudo_hdr() */
offset = create_pseudo_hdr(p, dat_trans_type, dat_len);
if (offset<0) {
@@ -295,7 +281,7 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
}
- bytes_read = read_packet_data(wth->fh, dat_trans_type,
+ bytes_read = read_packet_data(fh, dat_trans_type,
&p[offset], dat_len, err, err_info);
/* 0<=bytes_read<=dat_len is very likely a corrupted packet
we let the dissector handle this */
@@ -303,54 +289,34 @@ camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
return FALSE;
offset += bytes_read;
- fill_in_phdr(&wth->phdr, offset);
+ phdr->pkt_encap = WTAP_ENCAP_DVBCI;
+ /* timestamps aren't supported for now */
+ phdr->caplen = offset;
+ phdr->len = offset;
return TRUE;
}
static gboolean
-camins_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *pkthdr, Buffer *buf, int length,
- int *err, gchar **err_info)
+camins_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
- guint8 dat_trans_type;
- guint16 dat_len;
- gboolean ret;
- guint8 *p;
- gint offset, bytes_read;
+ *data_offset = file_tell(wth->fh);
- if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err))
- return FALSE;
+ return camins_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err,
+ err_info);
+}
- ret = find_next_pkt_dat_type_len(wth->random_fh, &dat_trans_type,
- &dat_len, err, err_info);
- if (!ret)
- return FALSE;
- buffer_assure_space(buf, DVB_CI_PSEUDO_HDR_LEN+dat_len);
- p = buffer_start_ptr(buf);
- /* in the pseudo-header, we always store the length that we obtained
- from parsing the file
- (there's error conditions where this length field does not match
- the number of data bytes present in the file, we'll leave this to
- the dissector) */
- offset = create_pseudo_hdr(p, dat_trans_type, dat_len);
- if (offset<0)
- return FALSE;
-
- /* we only read the number of bytes requested by wtap in order to
- ensure we're not overflowing the buffer */
- bytes_read = read_packet_data(wth->random_fh, dat_trans_type,
- &p[offset], length, err, err_info);
- /* see comment in camins_read() */
- if (bytes_read < 0)
+static gboolean
+camins_seek_read(wtap *wth, gint64 seek_off,
+ struct wtap_pkthdr *pkthdr, Buffer *buf, int length _U_,
+ int *err, gchar **err_info)
+{
+ if (-1 == file_seek(wth->random_fh, seek_off, SEEK_SET, err))
return FALSE;
- offset += bytes_read;
- fill_in_phdr(pkthdr, offset);
-
- return TRUE;
+ return camins_read_packet(wth->random_fh, pkthdr, buf, err, err_info);
}
diff --git a/wiretap/commview.c b/wiretap/commview.c
index 9dc93c522e..ac45aea74c 100644
--- a/wiretap/commview.c
+++ b/wiretap/commview.c
@@ -132,7 +132,7 @@ int commview_open(wtap *wth, int *err, gchar **err_info)
}
static int
-commview_read_and_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
+commview_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
{
commview_header_t cv_hdr;
@@ -184,7 +184,7 @@ commview_read_and_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
phdr->ts.secs = mktime(&tm);
phdr->ts.nsecs = cv_hdr.usecs * 1000;
- return TRUE;
+ return wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info);
}
static gboolean
@@ -192,36 +192,18 @@ commview_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
- if(!commview_read_and_process_header(wth->fh, &wth->phdr, err,
- err_info))
- return FALSE;
-
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info);
+ return commview_read_packet(wth->fh, &wth->phdr, wth->frame_buffer, err,
+ err_info);
}
static gboolean
commview_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
if(file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- if(!commview_read_and_process_header(wth->random_fh, phdr, err,
- err_info)) {
- if(*err == 0)
- *err = WTAP_ERR_SHORT_READ;
- return FALSE;
- }
-
- if(length != (int)phdr->caplen) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("commview: record length %u doesn't match requested length %d", phdr->caplen, length);
- return FALSE;
- }
-
- return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen,
- err, err_info);
+ return commview_read_packet(wth->random_fh, phdr, buf, err, err_info);
}
static gboolean
diff --git a/wiretap/cosine.c b/wiretap/cosine.c
index 117e4b8069..48fdb5b788 100644
--- a/wiretap/cosine.c
+++ b/wiretap/cosine.c
@@ -315,8 +315,9 @@ static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
/* Used to read packets in random-access fashion */
static gboolean
cosine_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int len, int *err, gchar **err_info)
+ Buffer *buf, int len _U_, int *err, gchar **err_info)
{
+ int pkt_len;
char line[COSINE_LINE_LENGTH];
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
@@ -330,11 +331,13 @@ cosine_seek_read (wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
}
- if (parse_cosine_rec_hdr(phdr, line, err, err_info) == -1)
+ /* Parse the header */
+ pkt_len = parse_cosine_rec_hdr(phdr, line, err, err_info);
+ if (pkt_len == -1)
return FALSE;
/* Convert the ASCII hex dump to binary data */
- return parse_cosine_hex_dump(wth->random_fh, phdr, len, buf, err,
+ return parse_cosine_hex_dump(wth->random_fh, phdr, pkt_len, buf, err,
err_info);
}
diff --git a/wiretap/csids.c b/wiretap/csids.c
index aa75b053fc..29a5d79174 100644
--- a/wiretap/csids.c
+++ b/wiretap/csids.c
@@ -51,10 +51,8 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
static gboolean csids_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
-static gboolean csids_read_packet_header(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info);
-static gboolean csids_read_packet_data(FILE_T fh, csids_t *csids, int len,
- Buffer *buf, int *err, gchar **err_info);
+static gboolean csids_read_packet(FILE_T fh, csids_t *csids,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
struct csids_header {
guint32 seconds; /* seconds since epoch */
@@ -156,11 +154,8 @@ static gboolean csids_read(wtap *wth, int *err, gchar **err_info,
*data_offset = file_tell(wth->fh);
- if( !csids_read_packet_header(wth->fh, &wth->phdr, err, err_info ) )
- return FALSE;
-
- return csids_read_packet_data( wth->fh, csids, wth->phdr.caplen,
- wth->frame_buffer, err, err_info );
+ return csids_read_packet( wth->fh, csids, &wth->phdr, wth->frame_buffer,
+ err, err_info );
}
/* Used to read packets in random-access fashion */
@@ -169,7 +164,7 @@ csids_seek_read (wtap *wth,
gint64 seek_off,
struct wtap_pkthdr *phdr,
Buffer *buf,
- int len,
+ int len _U_,
int *err,
gchar **err_info)
{
@@ -178,26 +173,21 @@ csids_seek_read (wtap *wth,
if( file_seek( wth->random_fh, seek_off, SEEK_SET, err ) == -1 )
return FALSE;
- if( !csids_read_packet_header( wth->random_fh, phdr, err, err_info ) )
- return FALSE;
-
- if( (guint32)len != phdr->caplen ) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("csids: record length %u doesn't match requested length %d",
- phdr->caplen, len);
+ if( !csids_read_packet( wth->random_fh, csids, phdr, buf, err, err_info ) ) {
+ if( *err == 0 )
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- return csids_read_packet_data( wth->random_fh, csids, phdr->caplen, buf,
- err, err_info );
+ return TRUE;
}
static gboolean
-csids_read_packet_header(FILE_T fh, struct wtap_pkthdr *phdr, int *err,
- gchar **err_info)
+csids_read_packet(FILE_T fh, csids_t *csids, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
struct csids_header hdr;
int bytesRead = 0;
+ guint8 *pd;
bytesRead = file_read( &hdr, sizeof( struct csids_header), fh );
if( bytesRead != sizeof( struct csids_header) ) {
@@ -214,25 +204,17 @@ csids_read_packet_header(FILE_T fh, struct wtap_pkthdr *phdr, int *err,
phdr->caplen = hdr.caplen;
phdr->ts.secs = hdr.seconds;
phdr->ts.nsecs = 0;
- return TRUE;
-}
-
-static gboolean
-csids_read_packet_data(FILE_T fh, csids_t *csids, int len, Buffer *buf,
- int *err, gchar **err_info)
-{
- guint8 *pd;
- if( !wtap_read_packet_bytes( fh, buf, len, err, err_info ) )
+ if( !wtap_read_packet_bytes( fh, buf, phdr->caplen, err, err_info ) )
return FALSE;
pd = buffer_start_ptr( buf );
if( csids->byteswapped ) {
- if( len >= 2 ) {
+ if( phdr->caplen >= 2 ) {
PBSWAP16(pd); /* the ip len */
- if( len >= 4 ) {
+ if( phdr->caplen >= 4 ) {
PBSWAP16(pd+2); /* ip id */
- if( len >= 6 )
+ if( phdr->caplen >= 6 )
PBSWAP16(pd+4); /* ip flags and fragoff */
}
}
diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c
index c44e99a9bb..7cc5bfa841 100644
--- a/wiretap/daintree-sna.c
+++ b/wiretap/daintree-sna.c
@@ -168,7 +168,7 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
* Wireshark opens the capture file for random access when displaying user-selected packets */
static gboolean
daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int len, int *err, gchar **err_info)
+ Buffer *buf, int len _U_, int *err, gchar **err_info)
{
char readLine[DAINTREE_MAX_LINE_SIZE];
char readData[READDATA_BUF_SIZE];
@@ -190,14 +190,8 @@ daintree_sna_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
return FALSE;
/* process packet data */
- if (!daintree_sna_process_hex_data(phdr, buf, readData, err, err_info))
- return FALSE;
- if (phdr->caplen != (guint32)len) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup("daintree-sna: corrupted frame");
- return FALSE;
- }
- return TRUE;
+ return daintree_sna_process_hex_data(phdr, buf, readData, err,
+ err_info);
}
/* Scan a header line and fill in a struct wtap_pkthdr */
diff --git a/wiretap/dbs-etherwatch.c b/wiretap/dbs-etherwatch.c
index 3b69b425c2..0079cdc918 100644
--- a/wiretap/dbs-etherwatch.c
+++ b/wiretap/dbs-etherwatch.c
@@ -91,7 +91,7 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
static gboolean dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
-static int parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh,
+static gboolean parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh,
Buffer* buf, int *err, gchar **err_info);
static guint parse_single_hex_dump_line(char* rec, guint8 *buf,
int byte_offset);
@@ -203,7 +203,6 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- int pkt_len;
/* Find the next packet */
offset = dbs_etherwatch_seek_next_packet(wth, err, err_info);
@@ -212,38 +211,21 @@ static gboolean dbs_etherwatch_read(wtap *wth, int *err, gchar **err_info,
*data_offset = offset;
/* Parse the packet */
- pkt_len = parse_dbs_etherwatch_packet(&wth->phdr, wth->fh,
+ return parse_dbs_etherwatch_packet(&wth->phdr, wth->fh,
wth->frame_buffer, err, err_info);
- if (pkt_len == -1)
- return FALSE;
-
- return TRUE;
}
/* Used to read packets in random-access fashion */
static gboolean
-dbs_etherwatch_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int len,
+dbs_etherwatch_seek_read(wtap *wth, gint64 seek_off,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len _U_,
int *err, gchar **err_info)
{
- int pkt_len;
-
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
- pkt_len = parse_dbs_etherwatch_packet(phdr, wth->random_fh, buf, err,
+ return parse_dbs_etherwatch_packet(phdr, wth->random_fh, buf, err,
err_info);
-
- if (pkt_len != len) {
- if (pkt_len != -1) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("dbs_etherwatch: packet length %d doesn't match requested length %d",
- pkt_len, len);
- }
- return FALSE;
- }
-
- return TRUE;
}
/* Parse a packet */
@@ -290,7 +272,7 @@ unnumbered. Unnumbered has length 1, numbered 2.
*/
#define CTL_UNNUMB_MASK 0x03
#define CTL_UNNUMB_VALUE 0x03
-static int
+static gboolean
parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
int *err, gchar **err_info)
{
@@ -320,7 +302,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return -1;
+ return FALSE;
}
/* Get the destination address */
@@ -328,14 +310,14 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
if(!p) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: destination address not found");
- return -1;
+ return FALSE;
}
p += strlen(DEST_MAC_PREFIX);
if(parse_hex_dump(p, &pd[eth_hdr_len], HEX_HDR_SPR, HEX_HDR_END)
!= MAC_ADDR_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: destination address not valid");
- return -1;
+ return FALSE;
}
eth_hdr_len += MAC_ADDR_LENGTH;
@@ -353,7 +335,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
HEX_HDR_END) != MAC_ADDR_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: source address not valid");
- return -1;
+ return FALSE;
}
eth_hdr_len += MAC_ADDR_LENGTH;
@@ -363,14 +345,14 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return -1;
+ return FALSE;
}
/* Check the lines is as least as long as the length position */
if(strlen(line) < LENGTH_POS) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: line too short");
- return -1;
+ return FALSE;
}
num_items_scanned = sscanf(line + LENGTH_POS,
@@ -383,7 +365,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
if (num_items_scanned != 8) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: header line not valid");
- return -1;
+ return FALSE;
}
/* Determine whether it is Ethernet II or IEEE 802 */
@@ -395,7 +377,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
HEX_HDR_END) != PROTOCOL_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: Ethernet II protocol value not valid");
- return -1;
+ return FALSE;
}
eth_hdr_len += PROTOCOL_LENGTH;
} else {
@@ -411,7 +393,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
HEX_HDR_END) != SAP_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 DSAP+SSAP value not valid");
- return -1;
+ return FALSE;
}
eth_hdr_len += SAP_LENGTH;
/* Get the (first part of the) control field */
@@ -419,7 +401,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
HEX_HDR_END) != CTL_UNNUMB_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 control field first part not valid");
- return -1;
+ return FALSE;
}
/* Determine whether the control is numbered, and thus longer */
if((pd[eth_hdr_len] & CTL_UNNUMB_MASK) != CTL_UNNUMB_VALUE) {
@@ -429,7 +411,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
HEX_HDR_SPR) != CTL_NUMB_LENGTH - CTL_UNNUMB_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 control field second part value not valid");
- return -1;
+ return FALSE;
}
eth_hdr_len += CTL_NUMB_LENGTH;
} else {
@@ -443,7 +425,7 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
HEX_PID_END) != PID_LENGTH) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: 802.2 PID value not valid");
- return -1;
+ return FALSE;
}
eth_hdr_len += PID_LENGTH;
}
@@ -479,22 +461,22 @@ parse_dbs_etherwatch_packet(struct wtap_pkthdr *phdr, FILE_T fh, Buffer* buf,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return -1;
+ return FALSE;
}
if (!(line_count = parse_single_hex_dump_line(line,
&pd[eth_hdr_len + count], count))) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: packet data value not valid");
- return -1;
+ return FALSE;
}
count += line_count;
if (count > pkt_len) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("dbs_etherwatch: packet data value has too many bytes");
- return -1;
+ return FALSE;
}
}
- return eth_hdr_len + pkt_len;
+ return TRUE;
}
/* Parse a hex dump line */
diff --git a/wiretap/dct3trace.c b/wiretap/dct3trace.c
index f49c2d1e76..284af2e06a 100644
--- a/wiretap/dct3trace.c
+++ b/wiretap/dct3trace.c
@@ -95,31 +95,31 @@ hc2b(unsigned char hex)
}
static int
-hex2bin(unsigned char *out, unsigned char *in)
+hex2bin(guint8 *out, guint8 *out_end, unsigned char *in)
{
- unsigned char *out_start = out;
- unsigned char *end = in + strlen((char *)in);
+ guint8 *out_start = out;
int is_low = 0;
int c;
- /* Clamp to maximum packet size */
- if (end - in > MAX_PACKET_LEN*2) /* As we're reading nibbles */
- end = in + MAX_PACKET_LEN*2;
-
- while (in < end)
+ while (*in != '\0')
{
- c = hc2b(in[0]);
+ c = hc2b(*in);
if (c < 0)
{
in++;
continue;
}
+ if (out == out_end)
+ {
+ /* Too much data */
+ return -1;
+ }
if (is_low == 0)
{
- out[0] = c << 4;
+ *out = c << 4;
is_low = 1;
} else {
- out[0] |= (c & 0x0f);
+ *out |= (c & 0x0f);
is_low = 0;
out++;
}
@@ -189,12 +189,14 @@ int dct3trace_open(wtap *wth, int *err, gchar **err_info)
static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr,
- unsigned char *buf, int *err, gchar **err_info)
+ Buffer *buf, int *err, gchar **err_info)
{
unsigned char line[1024];
+ guint8 databuf[MAX_PACKET_LEN], *bufp;
gboolean have_data = FALSE;
int len = 0;
+ bufp = &databuf[0];
while (file_gets(line, sizeof(line), fh) != NULL)
{
if( memcmp(dct3trace_magic_end, line, strlen(dct3trace_magic_end)) == 0 )
@@ -216,6 +218,11 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr,
phdr->len = len;
*err = 0;
+
+ /* Make sure we have enough room for the packet */
+ buffer_assure_space(buf, phdr->caplen);
+ memcpy( buffer_start_ptr(buf), databuf, phdr->caplen );
+
return TRUE;
}
else
@@ -266,19 +273,25 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr,
default: phdr->pseudo_header.gsm_um.channel = GSM_UM_CHANNEL_UNKNOWN; break;
}
- /* Read data (if have it) into buf */
+ /* Read data (if have it) into databuf */
ptr = strstr(line, "data=\"");
if( ptr )
{
have_data = TRUE; /* If has data... */
- len = hex2bin(buf, ptr+6);
+ len = hex2bin(bufp, &databuf[MAX_PACKET_LEN], ptr+6);
+ if (len == -1)
+ {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen);
+ return FALSE;
+ }
}
}
else if( !have_data && memcmp(dct3trace_magic_l2_start, line, strlen(dct3trace_magic_l2_start)) == 0 )
{
/* For uplink packets we might not get the raw L1, so have to recreate it from the L2 */
/* Parse L2 header if didn't get data from L1 <l2 ...> */
- int data_len = 0;
+ int data_len;
char *ptr = strstr(line, "data=\"");
if( !ptr )
@@ -288,10 +301,14 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr,
have_data = TRUE;
+ /*
+ * We know we have no data already, so we know
+ * we have enough room for the header.
+ */
if( phdr->pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_SACCH || phdr->pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_FACCH || phdr->pseudo_header.gsm_um.channel == GSM_UM_CHANNEL_SDCCH )
{
/* Add LAPDm B header */
- memset(buf, 0x1, 2);
+ memset(bufp, 0x1, 2);
len = 3;
}
else
@@ -299,13 +316,19 @@ static gboolean dct3trace_get_packet(FILE_T fh, struct wtap_pkthdr *phdr,
/* Add LAPDm Bbis header */
len = 1;
}
- buf += len;
+ bufp += len;
- data_len = hex2bin(buf, ptr+6);
+ data_len = hex2bin(bufp, &databuf[MAX_PACKET_LEN], ptr+6);
+ if (data_len == -1)
+ {
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen);
+ return FALSE;
+ }
len += data_len;
/* Add LAPDm length byte */
- *(buf - 1) = data_len << 2 | 0x1;
+ *(bufp - 1) = data_len << 2 | 0x1;
}
}
@@ -327,58 +350,22 @@ baddata:
static gboolean dct3trace_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- guint64 offset = file_tell(wth->fh);
- unsigned char buf[MAX_PACKET_LEN];
-
- if( !dct3trace_get_packet(wth->fh, &wth->phdr, buf, err, err_info) )
- {
- return FALSE;
- }
-
- /* Make sure we have enough room for the packet */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- memcpy( buffer_start_ptr(wth->frame_buffer), buf, wth->phdr.caplen );
-
- *data_offset = offset;
+ *data_offset = file_tell(wth->fh);
- return TRUE;
+ return dct3trace_get_packet(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
/* Used to read packets in random-access fashion */
-static gboolean dct3trace_seek_read (wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int len,
+static gboolean dct3trace_seek_read(wtap *wth, gint64 seek_off,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len _U_,
int *err, gchar **err_info)
{
- unsigned char databuf[MAX_PACKET_LEN];
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
{
return FALSE;
}
- if( !dct3trace_get_packet(wth->random_fh, phdr, databuf, err, err_info) )
- {
- return FALSE;
- }
-
- if( (guint32)len != phdr->caplen )
- {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("dct3trace: requested length %d doesn't match record length %d",
- len, phdr->caplen);
- return FALSE;
- }
-
- if( phdr->caplen > MAX_PACKET_LEN)
- {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("dct3trace: record length %d too long", phdr->caplen);
- return FALSE;
- }
-
- /* Make sure we have enough room for the packet */
- buffer_assure_space(buf, phdr->caplen);
- memcpy( buffer_start_ptr(buf), databuf, phdr->caplen );
- return TRUE;
+ return dct3trace_get_packet(wth->random_fh, phdr, buf, err, err_info);
}
diff --git a/wiretap/eyesdn.c b/wiretap/eyesdn.c
index c26baee94a..40e3d25d97 100644
--- a/wiretap/eyesdn.c
+++ b/wiretap/eyesdn.c
@@ -97,9 +97,7 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
static gboolean eyesdn_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int len,
int *err, gchar **err_info);
-static gboolean parse_eyesdn_packet_data(FILE_T fh, int pkt_len, Buffer* buf,
- int *err, gchar **err_info);
-static int parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
+static int read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer* buf,
int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
@@ -158,56 +156,33 @@ static gboolean eyesdn_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- int pkt_len;
- /* Find the next packet */
+ /* Find the next record */
offset = eyesdn_seek_next_packet(wth, err, err_info);
if (offset < 1)
return FALSE;
-
- /* Parse the header */
- pkt_len = parse_eyesdn_rec_hdr(wth->fh, &wth->phdr, err, err_info);
- if (pkt_len == -1)
- return FALSE;
-
- /* Read the packet data */
- if (!parse_eyesdn_packet_data(wth->fh, pkt_len, wth->frame_buffer,
- err, err_info))
- return FALSE;
-
*data_offset = offset;
- return TRUE;
+
+ /* Parse the record */
+ return read_eyesdn_rec(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
eyesdn_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int len, int *err, gchar **err_info)
+ Buffer *buf, int len _U_, int *err, gchar **err_info)
{
- int pkt_len;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- pkt_len = parse_eyesdn_rec_hdr(wth->random_fh, phdr, err, err_info);
-
- if (pkt_len != len) {
- if (pkt_len != -1) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("eyesdn: requested length %d doesn't match length %d",
- len, pkt_len);
- }
- return FALSE;
- }
-
- return parse_eyesdn_packet_data(wth->random_fh, pkt_len, buf, err,
- err_info);
+ return read_eyesdn_rec(wth->random_fh, phdr, buf, err, err_info);
}
-/* Parses a packet record header. */
-static int
-parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+/* Parses a record. */
+static gboolean
+read_eyesdn_rec(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err,
+ gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
guint8 hdr[EYESDN_HDR_LENGTH];
@@ -215,6 +190,8 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
int usecs;
int pkt_len;
guint8 channel, direction;
+ int bytes_read;
+ guint8 *pd;
/* Our file pointer should be at the summary information header
* for a packet. Read in that header and extract the useful
@@ -224,7 +201,7 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
/* extract information from header */
@@ -277,7 +254,7 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err_info = g_strdup_printf(
"eyesdn: ATM cell has a length != 53 (%u)",
pkt_len);
- return -1;
+ return FALSE;
}
cur_off = file_tell(fh);
@@ -285,10 +262,10 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
if (file_seek(fh, cur_off, SEEK_SET, err) == -1)
- return -1;
+ return FALSE;
phdr->pkt_encap = WTAP_ENCAP_ATM_PDUS_UNTRUNCATED;
pseudo_header->atm.flags=ATM_RAW_CELL;
pseudo_header->atm.aal=AAL_UNKNOWN;
@@ -336,7 +313,7 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("eyesdn: File has %u-byte packet, bigger than maximum of %u",
pkt_len, EYESDN_MAX_PACKET_LEN);
- return -1;
+ return FALSE;
}
phdr->presence_flags = WTAP_HAS_TS;
@@ -345,17 +322,6 @@ parse_eyesdn_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
phdr->caplen = pkt_len;
phdr->len = pkt_len;
- return pkt_len;
-}
-
-/* read a packet */
-static gboolean
-parse_eyesdn_packet_data(FILE_T fh, int pkt_len, Buffer* buf, int *err,
- gchar **err_info)
-{
- int bytes_read;
- guint8 *pd;
-
/* Make sure we have enough room for the packet */
buffer_assure_space(buf, EYESDN_MAX_PACKET_LEN);
diff --git a/wiretap/hcidump.c b/wiretap/hcidump.c
index 0efac8be94..1d77389b82 100644
--- a/wiretap/hcidump.c
+++ b/wiretap/hcidump.c
@@ -36,8 +36,8 @@ struct dump_hdr {
#define DUMP_HDR_SIZE (sizeof(struct dump_hdr))
-static gboolean hcidump_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+static gboolean hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
struct dump_hdr dh;
int bytes_read, packet_size;
@@ -70,7 +70,7 @@ static gboolean hcidump_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
phdr->pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE);
- return TRUE;
+ return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
@@ -78,25 +78,18 @@ static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
{
*data_offset = file_tell(wth->fh);
- if (!hcidump_process_header(wth->fh, &wth->phdr, err, err_info))
- return FALSE;
-
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info);
+ return hcidump_process_packet(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
static gboolean hcidump_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- if (!hcidump_process_header(wth->random_fh, phdr, err, err_info))
- return FALSE;
-
- return wtap_read_packet_bytes(wth->random_fh, buf, length,
- err, err_info);
+ return hcidump_process_packet(wth->random_fh, phdr, buf, err, err_info);
}
int hcidump_open(wtap *wth, int *err, gchar **err_info)
diff --git a/wiretap/i4btrace.c b/wiretap/i4btrace.c
index fbfb06afce..b411922333 100644
--- a/wiretap/i4btrace.c
+++ b/wiretap/i4btrace.c
@@ -40,8 +40,8 @@ static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
static gboolean i4btrace_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
-static int i4b_process_rec_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info);
+static int i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info);
/*
* Test some fields in the header to see if they make sense.
@@ -116,53 +116,32 @@ int i4btrace_open(wtap *wth, int *err, gchar **err_info)
static gboolean i4btrace_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- int ret;
-
*data_offset = file_tell(wth->fh);
- /* Read and process the record header. */
- ret = i4b_process_rec_header(wth, wth->fh, &wth->phdr, err, err_info);
- if (ret <= 0) {
- /* Read error or EOF */
- return FALSE;
- }
-
- /*
- * Read the packet data.
- */
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info);
+ return i4b_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
static gboolean
i4btrace_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
- int ret;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read and process the record header. */
- ret = i4b_process_rec_header(wth, wth->random_fh, phdr, err, err_info);
- if (ret <= 0) {
+ if (!i4b_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) {
/* Read error or EOF */
- if (ret == 0) {
+ if (*err == 0) {
/* EOF means "short read" in random-access mode */
*err = WTAP_ERR_SHORT_READ;
}
return FALSE;
}
-
- /*
- * Read the packet data.
- */
- return wtap_read_packet_bytes(wth->random_fh, buf, length, err,
- err_info);
+ return TRUE;
}
static int
-i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+i4b_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
{
i4btrace_t *i4btrace = (i4btrace_t *)wth->priv;
@@ -174,13 +153,11 @@ i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
bytes_read = file_read(&hdr, sizeof hdr, fh);
if (bytes_read != sizeof hdr) {
*err = file_error(fh, err_info);
- if (*err != 0)
- return -1;
- if (bytes_read != 0) {
+ if (*err == 0 && bytes_read != 0) {
+ /* Read something, but not enough */
*err = WTAP_ERR_SHORT_READ;
- return -1;
}
- return 0;
+ return FALSE;
}
if (i4btrace->byte_swapped) {
@@ -261,5 +238,8 @@ i4b_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
phdr->pseudo_header.isdn.uton = (hdr.dir == FROM_TE);
- return 1;
+ /*
+ * Read the packet data.
+ */
+ return wtap_read_packet_bytes(fh, buf, length, err, err_info);
}
diff --git a/wiretap/ipfix.c b/wiretap/ipfix.c
index 26b2e43e49..fbba7db7fe 100644
--- a/wiretap/ipfix.c
+++ b/wiretap/ipfix.c
@@ -160,12 +160,12 @@ ipfix_read_message_header(ipfix_message_header_t *pfx_hdr, FILE_T fh, int *err,
/* Read IPFIX message header from file and fill in the struct wtap_pkthdr
- * for the packet. Return true on success. Set *err to 0 on EOF, any
- * other value for "real" errors (EOF is ok, since return value is still
- * FALSE)
+ * for the packet, and, if that succeeds, read the packet data.
+ * Return true on success. Set *err to 0 on EOF, any other value for "real"
+ * errors (EOF is ok, since return value is still FALSE).
*/
static gboolean
-ipfix_read_and_process_message_header(FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_info)
+ipfix_read_message(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
ipfix_message_header_t msg_hdr;
@@ -178,7 +178,7 @@ ipfix_read_and_process_message_header(FILE_T fh, struct wtap_pkthdr *phdr, int *
phdr->ts.secs = msg_hdr.export_time_secs;
phdr->ts.nsecs = 0;
- return TRUE;
+ return wtap_read_packet_bytes(fh, buf, msg_hdr.message_length, err, err_info);
}
@@ -289,22 +289,20 @@ ipfix_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
*data_offset = file_tell(wth->fh);
ipfix_debug1("ipfix_read: data_offset is initially %" G_GINT64_MODIFIER "d", *data_offset);
- if (!ipfix_read_and_process_message_header(wth->fh, &wth->phdr, err, err_info)) {
+ if (!ipfix_read_message(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info)) {
ipfix_debug2("ipfix_read: couldn't read message header with code: %d\n, and error '%s'",
*err, *err_info);
return FALSE;
}
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen,
- err, err_info);
+ return TRUE;
}
/* classic wtap: seek to file position and read packet */
static gboolean
-ipfix_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
- int *err, gchar **err_info)
+ipfix_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
/* seek to the right file position */
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) {
@@ -315,20 +313,13 @@ ipfix_seek_read(wtap *wth, gint64 seek_off,
ipfix_debug1("ipfix_seek_read: reading at offset %" G_GINT64_MODIFIER "u", seek_off);
- if (!ipfix_read_and_process_message_header(wth->random_fh, phdr, err, err_info)) {
+ if (!ipfix_read_message(wth->random_fh, phdr, buf, err, err_info)) {
ipfix_debug0("ipfix_seek_read: couldn't read message header");
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- if(length != (int)phdr->caplen) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("ipfix: record length %u doesn't match requested length %d",
- phdr->caplen, length);
- ipfix_debug1("ipfix_seek_read: %s", *err_info);
- return FALSE;
- }
-
- return wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info);
+ return TRUE;
}
diff --git a/wiretap/iptrace.c b/wiretap/iptrace.c
index d2d719c1ca..5d3ea6b6fa 100644
--- a/wiretap/iptrace.c
+++ b/wiretap/iptrace.c
@@ -47,7 +47,7 @@ static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
int *err, gchar **err_info);
-static gboolean iptrace_process_rec_data(FILE_T fh, Buffer *buf,
+static gboolean iptrace_read_rec_data(FILE_T fh, Buffer *buf,
struct wtap_pkthdr *phdr, int *err, gchar **err_info);
static void fill_in_pseudo_header(int encap,
union wtap_pseudo_header *pseudo_header, guint8 *header);
@@ -123,7 +123,7 @@ typedef struct {
#define IPTRACE_1_0_PDATA_SIZE 22 /* packet data */
static gboolean
-iptrace_process_rec_header_1_0(FILE_T fh, struct wtap_pkthdr *phdr,
+iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
{
guint8 header[IPTRACE_1_0_PHDR_SIZE];
@@ -213,25 +213,23 @@ iptrace_process_rec_header_1_0(FILE_T fh, struct wtap_pkthdr *phdr,
/* Fill in the pseudo-header. */
fill_in_pseudo_header(phdr->pkt_encap, &phdr->pseudo_header, header);
- return TRUE;
+ /* Get the packet data */
+ return iptrace_read_rec_data(fh, buf, phdr, err, err_info);
}
/* Read the next packet */
static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- /* Read the descriptor data */
*data_offset = file_tell(wth->fh);
- if (!iptrace_process_rec_header_1_0(wth->fh, &wth->phdr, err, err_info)) {
+
+ /* Read the packet */
+ if (!iptrace_read_rec_1_0(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info)) {
/* Read error or EOF */
return FALSE;
}
- /* Read the packet data */
- if (!iptrace_process_rec_data(wth->fh, wth->frame_buffer, &wth->phdr,
- err, err_info))
- return FALSE; /* Read error */
-
/* If the per-file encapsulation isn't known, set it to this
packet's encapsulation.
@@ -249,26 +247,19 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
}
static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int packet_size,
+ struct wtap_pkthdr *phdr, Buffer *buf, int packet_size _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read the descriptor data */
- if (!iptrace_process_rec_header_1_0(wth->random_fh, phdr, err, err_info))
- return FALSE;
-
- if (packet_size != (int)phdr->caplen) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("iptrace: record length %u doesn't match requested length %d",
- phdr->caplen, packet_size);
+ /* Read the packet */
+ if (!iptrace_read_rec_1_0(wth->random_fh, phdr, buf, err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- /* Get the packet data */
- return iptrace_process_rec_data(wth->random_fh, buf, phdr,
- err, err_info);
+ return TRUE;
}
/***********************************************************
@@ -310,7 +301,7 @@ typedef struct {
#define IPTRACE_2_0_PDATA_SIZE 32 /* packet data */
static gboolean
-iptrace_process_rec_header_2_0(FILE_T fh, struct wtap_pkthdr *phdr,
+iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
{
guint8 header[IPTRACE_2_0_PHDR_SIZE];
@@ -418,25 +409,23 @@ iptrace_process_rec_header_2_0(FILE_T fh, struct wtap_pkthdr *phdr,
/* Fill in the pseudo_header. */
fill_in_pseudo_header(phdr->pkt_encap, &phdr->pseudo_header, header);
- return TRUE;
+ /* Get the packet data */
+ return iptrace_read_rec_data(fh, buf, phdr, err, err_info);
}
/* Read the next packet */
static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- /* Read the descriptor data */
*data_offset = file_tell(wth->fh);
- if (!iptrace_process_rec_header_2_0(wth->fh, &wth->phdr, err, err_info)) {
+
+ /* Read the packet */
+ if (!iptrace_read_rec_2_0(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info)) {
/* Read error or EOF */
return FALSE;
}
- /* Read the packet data */
- if (!iptrace_process_rec_data(wth->fh, wth->frame_buffer, &wth->phdr,
- err, err_info))
- return FALSE; /* Read error */
-
/* If the per-file encapsulation isn't known, set it to this
packet's encapsulation.
@@ -454,26 +443,19 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
}
static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int packet_size,
+ struct wtap_pkthdr *phdr, Buffer *buf, int packet_size _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read the descriptor data */
- if (!iptrace_process_rec_header_2_0(wth->random_fh, phdr, err, err_info))
- return FALSE;
-
- if (packet_size != (int)phdr->caplen) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("iptrace: record length %u doesn't match requested length %d",
- phdr->caplen, packet_size);
+ /* Read the packet */
+ if (!iptrace_read_rec_2_0(wth->random_fh, phdr, buf, err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- /* Get the packet data */
- return iptrace_process_rec_data(wth->random_fh, buf, phdr, err,
- err_info);
+ return TRUE;
}
static int
@@ -498,7 +480,7 @@ iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err,
}
static gboolean
-iptrace_process_rec_data(FILE_T fh, Buffer *buf, struct wtap_pkthdr *phdr,
+iptrace_read_rec_data(FILE_T fh, Buffer *buf, struct wtap_pkthdr *phdr,
int *err, gchar **err_info)
{
if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info))
diff --git a/wiretap/iseries.c b/wiretap/iseries.c
index 8433be86d9..4136008d03 100644
--- a/wiretap/iseries.c
+++ b/wiretap/iseries.c
@@ -384,15 +384,13 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset)
offset = iseries_seek_next_packet (wth, err, err_info);
if (offset < 0)
return FALSE;
+ *data_offset = offset;
/*
* Parse the packet and extract the various fields
*/
- if (!iseries_parse_packet (wth, wth->fh, &wth->phdr, wth->frame_buffer, err, err_info))
- return FALSE;
-
- *data_offset = offset;
- return TRUE;
+ return iseries_parse_packet (wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
/*
@@ -423,7 +421,7 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
if (iseries->format == ISERIES_FORMAT_UNICODE)
{
/* buflen is #bytes to 1st 0x0A */
- buflen = iseries_UNICODE_to_ASCII ((guint8 *) buf, ISERIES_LINE_LENGTH);
+ buflen = iseries_UNICODE_to_ASCII ((guint8 *) buf, ISERIES_LINE_LENGTH);
}
else
{
@@ -464,7 +462,7 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info)
*/
static gboolean
iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer * buf, int len, int *err, gchar ** err_info)
+ Buffer * buf, int len _U_, int *err, gchar ** err_info)
{
/* seek to packet location */
@@ -474,19 +472,8 @@ iseries_seek_read (wtap * wth, gint64 seek_off, struct wtap_pkthdr *phdr,
/*
* Parse the packet and extract the various fields
*/
- if (!iseries_parse_packet (wth, wth->random_fh, phdr, buf,
- err, err_info))
- return FALSE;
-
- if (phdr->caplen != (guint32)len)
- {
- *err = WTAP_ERR_BAD_FILE;
- *err_info =
- g_strdup_printf ("iseries: requested length %d doesn't match record length %d",
- len, phdr->caplen);
- return FALSE;
- }
- return TRUE;
+ return iseries_parse_packet (wth, wth->random_fh, phdr, buf,
+ err, err_info);
}
static int
diff --git a/wiretap/lanalyzer.c b/wiretap/lanalyzer.c
index e5d6a01fa3..947d0c3da4 100644
--- a/wiretap/lanalyzer.c
+++ b/wiretap/lanalyzer.c
@@ -442,8 +442,8 @@ int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
#define DESCRIPTOR_LEN 32
-static gboolean lanalyzer_read_trace_record_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info)
+static gboolean lanalyzer_read_trace_record(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
int bytes_read;
char LE_record_type[2];
@@ -558,7 +558,8 @@ static gboolean lanalyzer_read_trace_record_header(wtap *wth, FILE_T fh,
break;
}
- return TRUE;
+ /* Read the packet data */
+ return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
/* Read the next packet */
@@ -567,33 +568,26 @@ static gboolean lanalyzer_read(wtap *wth, int *err, gchar **err_info,
{
*data_offset = file_tell(wth->fh);
- /* Read the record header and packet descriptor */
- if (!lanalyzer_read_trace_record_header(wth, wth->fh,
- &wth->phdr, err, err_info))
- return FALSE;
-
- /* Read the packet data */
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info);
+ /* Read the record */
+ return lanalyzer_read_trace_record(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info);
}
static gboolean lanalyzer_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_, int *err,
gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read the record header and packet descriptor */
- if (!lanalyzer_read_trace_record_header(wth, wth->random_fh, phdr,
- err, err_info))
+ /* Read the record */
+ if (!lanalyzer_read_trace_record(wth, wth->random_fh, phdr, buf,
+ err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- /*
- * Read the packet data.
- */
- return wtap_read_packet_bytes(wth->random_fh, buf,
- length, err, err_info);
+ }
+ return TRUE;
}
/*---------------------------------------------------
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index fc123e4a04..cbe8a06c98 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -73,11 +73,8 @@ static gboolean libpcap_seek_read(wtap *wth, gint64 seek_off,
static int libpcap_read_header(wtap *wth, FILE_T fh, int *err, gchar **err_info,
struct pcaprec_ss990915_hdr *hdr);
static void adjust_header(wtap *wth, struct pcaprec_hdr *hdr);
-static gboolean libpcap_process_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info);
-static gboolean libpcap_process_packet_bytes(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, Buffer *buf, int length, int *err,
- gchar **err_info);
+static gboolean libpcap_read_packet(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean libpcap_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@@ -601,36 +598,36 @@ static gboolean libpcap_read(wtap *wth, int *err, gchar **err_info,
{
*data_offset = file_tell(wth->fh);
- if (!libpcap_process_header(wth, wth->fh, &wth->phdr, err, err_info))
- return FALSE;
-
- return libpcap_process_packet_bytes(wth, wth->fh, &wth->phdr,
- wth->frame_buffer, wth->phdr.caplen, err, err_info);
+ return libpcap_read_packet(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info);
}
static gboolean
libpcap_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- if (!libpcap_process_header(wth, wth->random_fh, phdr, err, err_info))
+ if (!libpcap_read_packet(wth, wth->random_fh, phdr, buf, err,
+ err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- return libpcap_process_packet_bytes(wth, wth->random_fh, phdr, buf,
- length, err, err_info);
+ }
+ return TRUE;
}
static gboolean
-libpcap_process_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+libpcap_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
struct pcaprec_ss990915_hdr hdr;
guint packet_size;
guint orig_size;
int bytes_read;
int phdr_len;
+ libpcap_t *libpcap;
bytes_read = libpcap_read_header(wth, fh, err, err_info, &hdr);
if (bytes_read == -1) {
@@ -692,6 +689,16 @@ libpcap_process_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
phdr->caplen = packet_size;
phdr->len = orig_size;
+ /*
+ * Read the packet data.
+ */
+ if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info))
+ return FALSE; /* failed */
+
+ libpcap = (libpcap_t *)wth->priv;
+ pcap_read_post_process(wth->file_type, wth->file_encap,
+ &phdr->pseudo_header, buffer_start_ptr(buf), packet_size,
+ libpcap->byte_swapped, -1);
return TRUE;
}
@@ -817,25 +824,6 @@ adjust_header(wtap *wth, struct pcaprec_hdr *hdr)
}
}
-static gboolean
-libpcap_process_packet_bytes(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- Buffer *buf, int length, int *err, gchar **err_info)
-{
- libpcap_t *libpcap;
-
- /*
- * Read the packet data.
- */
- if (!wtap_read_packet_bytes(fh, buf, length, err, err_info))
- return FALSE; /* failed */
-
- libpcap = (libpcap_t *)wth->priv;
- pcap_read_post_process(wth->file_type, wth->file_encap,
- &phdr->pseudo_header, buffer_start_ptr(buf), length,
- libpcap->byte_swapped, -1);
- return TRUE;
-}
-
/* Returns 0 if we could write the specified encapsulation type,
an error indication otherwise. */
int libpcap_dump_can_write_encap(int encap)
diff --git a/wiretap/nettl.c b/wiretap/nettl.c
index c9545367d7..4e96499fd7 100644
--- a/wiretap/nettl.c
+++ b/wiretap/nettl.c
@@ -182,11 +182,8 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
static gboolean nettl_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf,
int length, int *err, gchar **err_info);
-static int nettl_read_rec_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr,
- int *err, gchar **err_info, gboolean *fddihack);
-static gboolean nettl_read_rec_data(FILE_T fh, Buffer *buf, int length,
- int *err, gchar **err_info, gboolean fddihack);
+static gboolean nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info);
static gboolean nettl_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
@@ -295,29 +292,14 @@ int nettl_open(wtap *wth, int *err, gchar **err_info)
static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- int ret;
- gboolean fddihack=FALSE;
-
/* Read record header. */
*data_offset = file_tell(wth->fh);
- ret = nettl_read_rec_header(wth, wth->fh, &wth->phdr,
- err, err_info, &fddihack);
- if (ret <= 0) {
+ if (!nettl_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info)) {
/* Read error or EOF */
return FALSE;
}
- if (wth->phdr.caplen > WTAP_MAX_PACKET_SIZE) {
- /*
- * Probably a corrupt capture file; don't blow up trying
- * to allocate space for an immensely-large packet.
- */
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("nettl: File has %u-byte packet, bigger than maximum of %u",
- wth->phdr.caplen, WTAP_MAX_PACKET_SIZE);
- return FALSE;
- }
-
/*
* If the per-file encapsulation isn't known, set it to this
* packet's encapsulation.
@@ -333,94 +315,74 @@ static gboolean nettl_read(wtap *wth, int *err, gchar **err_info,
wth->file_encap = WTAP_ENCAP_PER_PACKET;
}
- /*
- * Read the packet data.
- */
- buffer_assure_space(wth->frame_buffer, wth->phdr.caplen);
- if (!nettl_read_rec_data(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info, fddihack))
- return FALSE; /* Read error */
return TRUE;
}
static gboolean
nettl_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
- int ret;
- gboolean fddihack=FALSE;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
/* Read record header. */
- ret = nettl_read_rec_header(wth, wth->random_fh, phdr, err, err_info,
- &fddihack);
- if (ret <= 0) {
+ if (!nettl_read_rec(wth, wth->random_fh, phdr, buf, err, err_info)) {
/* Read error or EOF */
- if (ret == 0) {
+ if (*err == 0) {
/* EOF means "short read" in random-access mode */
*err = WTAP_ERR_SHORT_READ;
}
return FALSE;
}
-
- /*
- * Read the packet data.
- */
- return nettl_read_rec_data(wth->random_fh, buf, length, err, err_info,
- fddihack);
+ return TRUE;
}
-static int
-nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info, gboolean *fddihack)
+static gboolean
+nettl_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+ int *err, gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
nettl_t *nettl = (nettl_t *)wth->priv;
+ gboolean fddihack = FALSE;
int bytes_read;
struct nettlrec_hdr rec_hdr;
guint16 hdr_len;
struct nettlrec_ns_ls_drv_eth_hdr drv_eth_hdr;
- guint16 length, caplen;
- int offset = 0;
+ guint32 length, caplen;
int subsys;
- int padlen;
+ guint padlen;
+ int datalen;
guint8 dummyc[16];
+ int bytes_to_read;
+ guint8 *pd;
+ guint8 dummy[3];
errno = WTAP_ERR_CANT_READ;
bytes_read = file_read(&rec_hdr.hdr_len, sizeof rec_hdr.hdr_len, fh);
if (bytes_read != sizeof rec_hdr.hdr_len) {
*err = file_error(fh, err_info);
- if (*err != 0)
- return -1;
- if (bytes_read != 0) {
+ if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
- }
- return 0;
+ return FALSE;
}
- offset += 2;
hdr_len = g_ntohs(rec_hdr.hdr_len);
if (hdr_len < NETTL_REC_HDR_LEN) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("nettl: record header length %u too short",
hdr_len);
- return -1;
+ return FALSE;
}
bytes_read = file_read(&rec_hdr.subsys, NETTL_REC_HDR_LEN - 2, fh);
if (bytes_read != NETTL_REC_HDR_LEN - 2) {
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
- offset += NETTL_REC_HDR_LEN - 2;
subsys = g_ntohs(rec_hdr.subsys);
hdr_len -= NETTL_REC_HDR_LEN;
if (file_seek(fh, hdr_len, SEEK_CUR, err) == -1)
- return -1;
- offset += hdr_len;
+ return FALSE;
if ( (pntohl(&rec_hdr.kind) & NETTL_HDR_PDU_MASK) == 0 ) {
/* not actually a data packet (PDU) trace record */
@@ -500,7 +462,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
there are an extra 3 bytes after the DSAP and SSAP
for SNAP frames ???
*/
- *fddihack=TRUE;
+ fddihack=TRUE;
padlen = 0;
} else {
/* outbound appears to have variable padding */
@@ -509,29 +471,26 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
/* padding is usually either a total 11 or 16 bytes??? */
padlen = (int)dummyc[8];
if (file_seek(fh, padlen, SEEK_CUR, err) == -1)
- return -1;
+ return FALSE;
padlen += 9;
- offset += padlen;
}
} else if ( (subsys == NETTL_SUBSYS_PCI_FDDI)
|| (subsys == NETTL_SUBSYS_EISA_FDDI)
|| (subsys == NETTL_SUBSYS_HSC_FDDI) ) {
/* other flavor FDDI cards have an extra 3 bytes of padding */
if (file_seek(fh, 3, SEEK_CUR, err) == -1)
- return -1;
+ return FALSE;
padlen = 3;
- offset += padlen;
} else if (subsys == NETTL_SUBSYS_NS_LS_LOOPBACK) {
/* LOOPBACK has an extra 26 bytes of padding */
if (file_seek(fh, 26, SEEK_CUR, err) == -1)
- return -1;
+ return FALSE;
padlen = 26;
- offset += padlen;
} else if (subsys == NETTL_SUBSYS_NS_LS_SCTP) {
/*
* SCTP 8 byte header that we will ignore...
@@ -544,9 +503,8 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
* 2 = Outbound
*/
if (file_seek(fh, 8, SEEK_CUR, err) == -1)
- return -1;
+ return FALSE;
padlen = 8;
- offset += padlen;
} else {
padlen = 0;
}
@@ -562,9 +520,8 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
+ return FALSE;
}
- offset += NS_LS_DRV_ETH_HDR_LEN;
length = pntohs(&drv_eth_hdr.length);
caplen = pntohs(&drv_eth_hdr.caplen);
@@ -576,8 +533,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
* And what are the extra two bytes?
*/
if (nettl->is_hpux_11) {
- if (file_seek(fh, 2, SEEK_CUR, err) == -1) return -1;
- offset += 2;
+ if (file_seek(fh, 2, SEEK_CUR, err) == -1) return FALSE;
}
padlen = 0;
break;
@@ -607,8 +563,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
caplen = pntohl(&rec_hdr.caplen);
padlen = 24; /* sizeof (struct nettlrec_sx25l2_hdr) - NETTL_REC_HDR_LEN + 4 */
if (file_seek(fh, padlen, SEEK_CUR, err) == -1)
- return -1;
- offset += padlen;
+ return FALSE;
break;
default:
@@ -626,7 +581,7 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("nettl: packet length %u in record header too short, less than %u",
length, padlen);
- return -1;
+ return FALSE;
}
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
phdr->len = length - padlen;
@@ -634,9 +589,10 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("nettl: captured length %u in record header too short, less than %u",
caplen, padlen);
- return -1;
+ return FALSE;
}
- phdr->caplen = caplen - padlen;
+ datalen = caplen - padlen;
+ phdr->caplen = datalen;
phdr->ts.secs = pntohl(&rec_hdr.sec);
phdr->ts.nsecs = pntohl(&rec_hdr.usec) * 1000;
@@ -646,58 +602,61 @@ nettl_read_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
pseudo_header->nettl.pid = pntohl(&rec_hdr.pid);
pseudo_header->nettl.uid = pntohs(&rec_hdr.uid);
- return offset;
-}
-
-static gboolean
-nettl_read_rec_data(FILE_T fh, Buffer *buf, int length, int *err,
- gchar **err_info, gboolean fddihack)
-{
- int bytes_to_read, bytes_read;
- guint8 *pd;
- guint8 dummy[3];
+ if (phdr->caplen > WTAP_MAX_PACKET_SIZE) {
+ /*
+ * Probably a corrupt capture file; don't blow up trying
+ * to allocate space for an immensely-large packet.
+ */
+ *err = WTAP_ERR_BAD_FILE;
+ *err_info = g_strdup_printf("nettl: File has %u-byte packet, bigger than maximum of %u",
+ phdr->caplen, WTAP_MAX_PACKET_SIZE);
+ return FALSE;
+ }
- buffer_assure_space(buf, length);
+ /*
+ * Read the packet data.
+ */
+ buffer_assure_space(buf, datalen);
pd = buffer_start_ptr(buf);
errno = WTAP_ERR_CANT_READ;
if (fddihack) {
/* read in FC, dest, src, DSAP and SSAP */
bytes_to_read = 15;
- if (bytes_to_read > length)
- bytes_to_read = length;
+ if (bytes_to_read > datalen)
+ bytes_to_read = datalen;
bytes_read = file_read(pd, bytes_to_read, fh);
if (bytes_read != bytes_to_read) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- length -= bytes_read;
- if (length == 0) {
+ datalen -= bytes_read;
+ if (datalen == 0) {
/* There's nothing past the FC, dest, src, DSAP and SSAP */
return TRUE;
}
if (pd[13] == 0xAA) {
/* it's SNAP, have to eat 3 bytes??? */
bytes_to_read = 3;
- if (bytes_to_read > length)
- bytes_to_read = length;
+ if (bytes_to_read > datalen)
+ bytes_to_read = datalen;
bytes_read = file_read(dummy, bytes_to_read, fh);
if (bytes_read != bytes_to_read) {
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
return FALSE;
}
- length -= bytes_read;
- if (length == 0) {
+ datalen -= bytes_read;
+ if (datalen == 0) {
/* There's nothing past the FC, dest, src, DSAP, SSAP, and 3 bytes to eat */
return TRUE;
}
}
- bytes_read = file_read(pd + 15, length, fh);
+ bytes_read = file_read(pd + 15, datalen, fh);
} else
- bytes_read = file_read(pd, length, fh);
+ bytes_read = file_read(pd, datalen, fh);
- if (bytes_read != length) {
+ if (bytes_read != datalen) {
*err = file_error(fh, err_info);
if (*err == 0)
*err = WTAP_ERR_SHORT_READ;
@@ -706,7 +665,6 @@ nettl_read_rec_data(FILE_T fh, Buffer *buf, int length, int *err,
return TRUE;
}
-
/* Returns 0 if we could write the specified encapsulation type,
an error indication otherwise. nettl files are WTAP_ENCAP_UNKNOWN
when they are first opened, so we allow that for tshark read/write.
diff --git a/wiretap/packetlogger.c b/wiretap/packetlogger.c
index f72ece74d7..93e050d34f 100644
--- a/wiretap/packetlogger.c
+++ b/wiretap/packetlogger.c
@@ -54,8 +54,9 @@ static gboolean packetlogger_seek_read(wtap *wth, gint64 seek_off,
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)
{
@@ -100,35 +101,24 @@ packetlogger_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
{
*data_offset = file_tell(wth->fh);
- if(!packetlogger_process_header(wth->fh, &wth->phdr, err, err_info))
- return FALSE;
-
- return wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info);
+ 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,
- Buffer *buf, int length, int *err, gchar **err_info)
+ Buffer *buf, int length _U_, int *err, gchar **err_info)
{
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;
- }
-
- return wtap_read_packet_bytes(wth->random_fh, buf, phdr->caplen,
- err, err_info);
+ return TRUE;
}
static gboolean
@@ -146,8 +136,8 @@ packetlogger_read_header(packetlogger_header_t *pl_hdr, FILE_T fh, int *err,
}
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;
@@ -178,5 +168,5 @@ packetlogger_process_header(FILE_T fh, struct wtap_pkthdr *phdr,
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);
}
diff --git a/wiretap/peekclassic.c b/wiretap/peekclassic.c
index e787457742..471e5ee693 100644
--- a/wiretap/peekclassic.c
+++ b/wiretap/peekclassic.c
@@ -145,15 +145,15 @@ static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
-static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, guint *sliceLengthp, int *err, gchar **err_info);
+static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset);
static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
-static gboolean peekclassic_process_record_header_v56(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info);
+static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
int peekclassic_open(wtap *wth, int *err, gchar **err_info)
{
@@ -365,22 +365,18 @@ int peekclassic_open(wtap *wth, int *err, gchar **err_info)
static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- guint sliceLength;
+ int sliceLength;
*data_offset = file_tell(wth->fh);
- /* process the packet record header */
- if (!peekclassic_process_record_header_v7(wth, wth->fh, &wth->phdr,
- &sliceLength, err, err_info))
- return FALSE;
-
- /* read the packet data */
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info))
+ /* Read the packet. */
+ sliceLength = peekclassic_read_packet_v7(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info);
+ if (sliceLength < 0)
return FALSE;
/* Skip extra ignored data at the end of the packet. */
- if (sliceLength > wth->phdr.caplen) {
+ if ((guint32)sliceLength > wth->phdr.caplen) {
if (!file_skip(wth->fh, sliceLength - wth->phdr.caplen, err))
return FALSE;
}
@@ -396,26 +392,27 @@ static gboolean peekclassic_read_v7(wtap *wth, int *err, gchar **err_info,
}
static gboolean peekclassic_seek_read_v7(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* process the packet record header */
- if (!peekclassic_process_record_header_v7(wth, wth->random_fh, phdr,
- NULL, err, err_info))
+ /* Read the packet. */
+ if (peekclassic_read_packet_v7(wth, wth->random_fh, phdr, buf,
+ err, err_info) == -1) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- /* read the packet data */
- return wtap_read_packet_bytes(wth->random_fh, buf, length,
- err, err_info);
+ }
+ return TRUE;
}
-static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, guint *sliceLengthp, int *err, gchar **err_info)
+static int peekclassic_read_packet_v7(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
guint8 ep_pkt[PEEKCLASSIC_V7_PKT_SIZE];
+ int bytes_read;
#if 0
guint16 protoNum;
#endif
@@ -429,8 +426,13 @@ static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
time_t tsecs;
guint32 tusecs;
- wtap_file_read_expected_bytes(ep_pkt, sizeof(ep_pkt), fh, err,
- err_info);
+ bytes_read = file_read(ep_pkt, sizeof(ep_pkt), fh);
+ if (bytes_read != (int) sizeof(ep_pkt)) {
+ *err = file_error(fh, err_info);
+ if (*err == 0 && bytes_read > 0)
+ *err = WTAP_ERR_SHORT_READ;
+ return -1;
+ }
/* Extract the fields from the packet */
#if 0
@@ -475,7 +477,7 @@ static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
if (phdr->len < 4 || phdr->caplen < 4) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("peekclassic: 802.11 packet has length < 4");
- return FALSE;
+ return -1;
}
phdr->len -= 4;
phdr->caplen -= 4;
@@ -489,9 +491,11 @@ static gboolean peekclassic_process_record_header_v7(wtap *wth, FILE_T fh,
break;
}
- if (sliceLengthp)
- *sliceLengthp = sliceLength;
- return TRUE;
+ /* read the packet data */
+ if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info))
+ return -1;
+
+ return sliceLength;
}
static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
@@ -499,14 +503,9 @@ static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
{
*data_offset = file_tell(wth->fh);
- /* process the packet record header */
- if (!peekclassic_process_record_header_v56(wth, wth->fh, &wth->phdr,
- err, err_info))
- return FALSE;
-
- /* read the packet data */
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info))
+ /* read the packet */
+ if (!peekclassic_read_packet_v56(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info))
return FALSE;
/*
@@ -517,24 +516,24 @@ static gboolean peekclassic_read_v56(wtap *wth, int *err, gchar **err_info,
}
static gboolean peekclassic_seek_read_v56(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* process the packet record header */
- if (!peekclassic_process_record_header_v56(wth, wth->random_fh, phdr,
- err, err_info))
+ /* read the packet */
+ if (!peekclassic_read_packet_v56(wth, wth->random_fh, phdr, buf,
+ err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- /* read the packet data */
- return wtap_read_packet_bytes(wth->random_fh, buf, length,
- err, err_info);
+ }
+ return TRUE;
}
-static gboolean peekclassic_process_record_header_v56(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info)
+static gboolean peekclassic_read_packet_v56(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
peekclassic_t *peekclassic = (peekclassic_t *)wth->priv;
guint8 ep_pkt[PEEKCLASSIC_V56_PKT_SIZE];
@@ -610,5 +609,6 @@ static gboolean peekclassic_process_record_header_v56(wtap *wth, FILE_T fh,
break;
}
- return TRUE;
+ /* read the packet data */
+ return wtap_read_packet_bytes(fh, buf, sliceLength, err, err_info);
}
diff --git a/wiretap/peektagged.c b/wiretap/peektagged.c
index ec9c3c223a..2407edd474 100644
--- a/wiretap/peektagged.c
+++ b/wiretap/peektagged.c
@@ -378,7 +378,7 @@ typedef struct {
#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
/*
- * Process the packet header.
+ * Read the packet.
*
* XXX - we should supply the additional radio information;
* the pseudo-header should probably be supplied in a fashion
@@ -387,8 +387,8 @@ typedef struct {
* are present.
*/
static int
-peektagged_process_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+peektagged_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
peektagged_t *peektagged = (peektagged_t *)wth->priv;
hdr_info_t hdr_info;
@@ -582,6 +582,10 @@ peektagged_process_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
break;
}
+ /* Read the packet data. */
+ if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info))
+ return -1;
+
return skip_len;
}
@@ -592,16 +596,12 @@ static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info,
*data_offset = file_tell(wth->fh);
- /* Process the packet record header. */
- skip_len = peektagged_process_header(wth, wth->fh, &wth->phdr, err, err_info);
+ /* Read the packet. */
+ skip_len = peektagged_read_packet(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info);
if (skip_len == -1)
return FALSE;
- /* Read the packet data. */
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen,
- err, err_info))
- return FALSE;
-
if (skip_len != 0) {
/* Skip extra junk at the end of the packet data. */
if (!file_skip(wth->fh, skip_len, err))
@@ -613,17 +613,17 @@ static gboolean peektagged_read(wtap *wth, int *err, gchar **err_info,
static gboolean
peektagged_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Process the packet record header. */
- if (peektagged_process_header(wth, wth->random_fh, phdr, err, err_info) == -1)
+ /* Read the packet. */
+ if (peektagged_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- /* Read the packet data. */
- return wtap_read_packet_bytes(wth->random_fh, buf, length,
- err, err_info);
+ }
+ return TRUE;
}
diff --git a/wiretap/radcom.c b/wiretap/radcom.c
index ab9b80e14f..8e0ca6e1ad 100644
--- a/wiretap/radcom.c
+++ b/wiretap/radcom.c
@@ -91,8 +91,8 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
static gboolean radcom_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
-static int radcom_process_rec_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, int *err, gchar **err_info);
+static gboolean radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info);
static gboolean radcom_read_rec_data(FILE_T fh, guint8 *pd, int length,
int *err, gchar **err_info);
@@ -258,26 +258,18 @@ read_error:
static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- int ret;
int bytes_read;
char fcs[2];
- /* Read record header. */
*data_offset = file_tell(wth->fh);
- ret = radcom_process_rec_header(wth, wth->fh, &wth->phdr, err,
- err_info);
- if (ret <= 0) {
+
+ /* Read record header. */
+ if (!radcom_read_rec(wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info)) {
/* Read error or EOF */
return FALSE;
}
- /*
- * Read the packet data.
- */
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info))
- return FALSE; /* Read error */
-
if (wth->file_encap == WTAP_ENCAP_LAPB) {
/* Read the FCS.
XXX - should we have some way of indicating the
@@ -298,35 +290,28 @@ static gboolean radcom_read(wtap *wth, int *err, gchar **err_info,
static gboolean
radcom_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
- int ret;
-
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read record header. */
- ret = radcom_process_rec_header(wth, wth->random_fh, phdr, err,
- err_info);
- if (ret <= 0) {
+ /* Read record. */
+ if (!radcom_read_rec(wth, wth->random_fh, phdr, buf, err,
+ err_info)) {
/* Read error or EOF */
- if (ret == 0) {
+ if (*err == 0) {
/* EOF means "short read" in random-access mode */
*err = WTAP_ERR_SHORT_READ;
}
return FALSE;
}
-
- /*
- * Read the packet data.
- */
- return wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info);
+ return TRUE;
}
-static int
-radcom_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info)
+static gboolean
+radcom_read_rec(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+ int *err, gchar **err_info)
{
struct radcomrec_hdr hdr;
int bytes_read;
@@ -339,13 +324,9 @@ radcom_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
bytes_read = file_read(&hdr, sizeof hdr, fh);
if (bytes_read != sizeof hdr) {
*err = file_error(fh, err_info);
- if (*err != 0)
- return -1;
- if (bytes_read != 0) {
+ if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
- return -1;
- }
- return 0;
+ return FALSE;
}
data_length = pletohs(&hdr.data_length);
@@ -356,7 +337,7 @@ radcom_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
* check for that and treat it as an EOF indication.
*/
*err = 0;
- return 0;
+ return FALSE;
}
length = pletohs(&hdr.length);
real_length = pletohs(&hdr.real_length);
@@ -395,7 +376,7 @@ radcom_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*/
if (!radcom_read_rec_data(wth->fh, atmhdr, sizeof atmhdr, err,
err_info))
- return -1; /* Read error */
+ return FALSE; /* Read error */
length -= 8;
real_length -= 8;
break;
@@ -404,7 +385,13 @@ radcom_process_rec_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
phdr->len = real_length;
phdr->caplen = length;
- return 1;
+ /*
+ * Read the packet data.
+ */
+ if (!wtap_read_packet_bytes(fh, buf, length, err, err_info))
+ return FALSE; /* Read error */
+
+ return TRUE;
}
static gboolean
diff --git a/wiretap/snoop.c b/wiretap/snoop.c
index 6226e2a2f3..405fac6788 100644
--- a/wiretap/snoop.c
+++ b/wiretap/snoop.c
@@ -91,8 +91,8 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
static gboolean snoop_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int length,
int *err, gchar **err_info);
-static gboolean snoop_process_record_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, guint32 *rec_sizep, int *err, gchar **err_info);
+static int snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info);
static gboolean snoop_read_atm_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
static gboolean snoop_read_shomiti_wireless_pseudoheader(FILE_T fh,
@@ -453,31 +453,18 @@ typedef struct {
static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
- guint padbytes;
+ int padbytes;
int bytes_read;
char padbuf[4];
int bytes_to_read;
*data_offset = file_tell(wth->fh);
- if (!snoop_process_record_header(wth, wth->fh, &wth->phdr,
- &padbytes, err, err_info))
+ padbytes = snoop_read_packet(wth, wth->fh, &wth->phdr,
+ wth->frame_buffer, err, err_info);
+ if (padbytes == -1)
return FALSE;
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer,
- wth->phdr.caplen, err, err_info))
- return FALSE; /* Read error */
-
- /*
- * If this is ATM LANE traffic, try to guess what type of LANE
- * traffic it is based on the packet contents.
- */
- if (wth->file_encap == WTAP_ENCAP_ATM_PDUS &&
- wth->phdr.pseudo_header.atm.type == TRAF_LANE) {
- atm_guess_lane_type(buffer_start_ptr(wth->frame_buffer),
- wth->phdr.caplen, &wth->phdr.pseudo_header);
- }
-
/*
* Skip over the padding (don't "fseek()", as the standard
* I/O library on some platforms discards buffered data if
@@ -508,36 +495,23 @@ static gboolean snoop_read(wtap *wth, int *err, gchar **err_info,
static gboolean
snoop_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int length,
+ struct wtap_pkthdr *phdr, Buffer *buf, int length _U_,
int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- if (!snoop_process_record_header(wth, wth->random_fh, phdr, NULL,
- err, err_info))
+ if (snoop_read_packet(wth, wth->random_fh, phdr, buf, err, err_info) == -1) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- /*
- * Read the packet data.
- */
- if (!wtap_read_packet_bytes(wth->random_fh, buf, length, err, err_info))
- return FALSE; /* failed */
-
- /*
- * If this is ATM LANE traffic, try to guess what type of LANE
- * traffic it is based on the packet contents.
- */
- if (wth->file_encap == WTAP_ENCAP_ATM_PDUS &&
- phdr->pseudo_header.atm.type == TRAF_LANE)
- atm_guess_lane_type(buffer_start_ptr(buf), length,
- &phdr->pseudo_header);
+ }
return TRUE;
}
-static gboolean
-snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- guint32 *padbytesp, int *err, gchar **err_info)
+static int
+snoop_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
struct snooprec_hdr hdr;
int bytes_read;
@@ -553,7 +527,7 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = file_error(fh, err_info);
if (*err == 0 && bytes_read != 0)
*err = WTAP_ERR_SHORT_READ;
- return FALSE;
+ return -1;
}
rec_size = g_ntohl(hdr.rec_len);
@@ -567,7 +541,7 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("snoop: File has %u-byte original length, bigger than maximum of %u",
orig_size, WTAP_MAX_PACKET_SIZE);
- return FALSE;
+ return -1;
}
if (packet_size > WTAP_MAX_PACKET_SIZE) {
/*
@@ -577,7 +551,7 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("snoop: File has %u-byte packet, bigger than maximum of %u",
packet_size, WTAP_MAX_PACKET_SIZE);
- return FALSE;
+ return -1;
}
if (packet_size > rec_size) {
/*
@@ -586,7 +560,7 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("snoop: File has %u-byte packet, bigger than record size %u",
packet_size, rec_size);
- return FALSE;
+ return -1;
}
switch (wth->file_encap) {
@@ -606,11 +580,11 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("snoop: atmsnoop file has a %u-byte packet, too small to have even an ATM pseudo-header",
packet_size);
- return FALSE;
+ return -1;
}
if (!snoop_read_atm_pseudoheader(fh, &phdr->pseudo_header,
err, err_info))
- return FALSE; /* Read error */
+ return -1; /* Read error */
/*
* Don't count the pseudo-header as part of the packet.
@@ -641,11 +615,11 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("snoop: Shomiti wireless file has a %u-byte packet, too small to have even a wireless pseudo-header",
packet_size);
- return FALSE;
+ return -1;
}
if (!snoop_read_shomiti_wireless_pseudoheader(fh,
&phdr->pseudo_header, err, err_info, &header_size))
- return FALSE; /* Read error */
+ return -1; /* Read error */
/*
* Don't count the pseudo-header as part of the packet.
@@ -669,11 +643,26 @@ snoop_process_record_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("snoop: File has %u-byte record with packet size of %u",
rec_size, packet_size);
- return FALSE;
+ return -1;
}
- if (padbytesp != NULL)
- *padbytesp = rec_size - ((guint)sizeof hdr + packet_size);
- return TRUE;
+
+ /*
+ * Read the packet data.
+ */
+ if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info))
+ return -1; /* failed */
+
+ /*
+ * If this is ATM LANE traffic, try to guess what type of LANE
+ * traffic it is based on the packet contents.
+ */
+ if (wth->file_encap == WTAP_ENCAP_ATM_PDUS &&
+ phdr->pseudo_header.atm.type == TRAF_LANE) {
+ atm_guess_lane_type(buffer_start_ptr(buf), packet_size,
+ &phdr->pseudo_header);
+ }
+
+ return rec_size - ((guint)sizeof hdr + packet_size);
}
static gboolean
diff --git a/wiretap/toshiba.c b/wiretap/toshiba.c
index b3c8d2f51d..c530075bff 100644
--- a/wiretap/toshiba.c
+++ b/wiretap/toshiba.c
@@ -114,10 +114,8 @@ static gboolean toshiba_seek_read(wtap *wth, gint64 seek_off,
int *err, gchar **err_info);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf,
guint byte_offset);
-static gboolean parse_toshiba_hex_dump(FILE_T fh, int pkt_len, Buffer *buf,
- int *err, gchar **err_info);
-static int parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
- int *err, gchar **err_info);
+static gboolean parse_toshiba_packet(FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info);
/* Seeks to the beginning of the next packet, and returns the
byte offset. Returns -1 on failure, and sets "*err" to the error
@@ -223,55 +221,38 @@ static gboolean toshiba_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
gint64 offset;
- int pkt_len;
/* Find the next packet */
offset = toshiba_seek_next_packet(wth, err, err_info);
if (offset < 1)
return FALSE;
-
- /* Parse the header */
- pkt_len = parse_toshiba_rec_hdr(&wth->phdr, wth->fh, err, err_info);
- if (pkt_len == -1)
- return FALSE;
-
- /* Convert the ASCII hex dump to binary data */
- if (!parse_toshiba_hex_dump(wth->fh, pkt_len, wth->frame_buffer,
- err, err_info))
- return FALSE;
-
*data_offset = offset;
- return TRUE;
+
+ /* Parse the packet */
+ return parse_toshiba_packet(wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
toshiba_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len _U_,
int *err, gchar **err_info)
{
- int pkt_len;
-
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
- pkt_len = parse_toshiba_rec_hdr(phdr, wth->random_fh, err, err_info);
-
- if (pkt_len != len) {
- if (pkt_len != -1) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("toshiba: requested length %d doesn't match record length %d",
- len, pkt_len);
- }
+ if (!parse_toshiba_packet(wth->random_fh, phdr, buf, err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- return parse_toshiba_hex_dump(wth->random_fh, pkt_len, buf, err, err_info);
+ return TRUE;
}
-/* Parses a packet record header. */
-static int
-parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
+/* Parses a packet. */
+static gboolean
+parse_toshiba_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
int *err, gchar **err_info)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
@@ -279,6 +260,8 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
int num_items_scanned;
int pkt_len, pktnum, hr, min, sec, csec;
char channel[10], direction[10];
+ int i, hex_lines;
+ guint8 *pd;
/* Our file pointer should be on the line containing the
* summary information for a packet. Read in that line and
@@ -289,7 +272,7 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return -1;
+ return FALSE;
}
/* Find text in line after "[No.". Limit the length of the
@@ -301,7 +284,7 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
if (num_items_scanned != 7) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: record header isn't valid");
- return -1;
+ return FALSE;
}
/* Scan lines until we find the OFFSET line. In a "telnet" trace,
@@ -319,7 +302,7 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
if (*err == 0) {
*err = WTAP_ERR_SHORT_READ;
}
- return -1;
+ return FALSE;
}
/* Check for "OFFSET 0001-0203" at beginning of line */
@@ -331,16 +314,15 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
if (num_items_scanned != 1) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("toshiba: OFFSET line doesn't have valid LEN item");
- return -1;
+ return FALSE;
}
- {
- phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
- phdr->ts.secs = hr * 3600 + min * 60 + sec;
- phdr->ts.nsecs = csec * 10000000;
- phdr->caplen = pkt_len;
- phdr->len = pkt_len;
- }
+ phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
+ phdr->ts.secs = hr * 3600 + min * 60 + sec;
+ phdr->ts.nsecs = csec * 10000000;
+ phdr->caplen = pkt_len;
+ phdr->len = pkt_len;
+
switch (channel[0]) {
case 'B':
phdr->pkt_encap = WTAP_ENCAP_ISDN;
@@ -361,17 +343,6 @@ parse_toshiba_rec_hdr(struct wtap_pkthdr *phdr, FILE_T fh,
pseudo_header->eth.fcs_len = -1;
break;
}
- return pkt_len;
-}
-
-/* Converts ASCII hex dump to binary data */
-static gboolean
-parse_toshiba_hex_dump(FILE_T fh, int pkt_len, Buffer *buf, int *err,
- gchar **err_info)
-{
- char line[TOSHIBA_LINE_LENGTH];
- int i, hex_lines;
- guint8 *pd;
/* Make sure we have enough room for the packet */
buffer_assure_space(buf, TOSHIBA_MAX_PACKET_LEN);
diff --git a/wiretap/visual.c b/wiretap/visual.c
index 5dc45b6021..3fc3384621 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -165,11 +165,8 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
struct wtap_pkthdr *phdr, Buffer *buf, int packet_size,
int *err, gchar **err_info);
-static gboolean visual_process_packet_header(wtap *wth, FILE_T fh,
- struct wtap_pkthdr *phdr, struct visual_pkt_hdr *vpkt_hdrp,
- int *err, gchar **err_info);
-static void visual_fill_in_chdlc_encapsulation(struct wtap_pkthdr *phdr,
- guint8 encap_hint, Buffer *buf);
+static gboolean visual_read_packet(wtap *wth, FILE_T fh,
+ struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
const guint8 *pd, int *err);
static gboolean visual_dump_close(wtap_dumper *wdh, int *err);
@@ -291,7 +288,6 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
gint64 *data_offset)
{
struct visual_read_info *visual = (struct visual_read_info *)wth->priv;
- struct visual_pkt_hdr vpkt_hdr;
/* Check for the end of the packet data. Note that a check for file EOF
will not work because there are index values stored after the last
@@ -305,55 +301,34 @@ static gboolean visual_read(wtap *wth, int *err, gchar **err_info,
*data_offset = file_tell(wth->fh);
- if (!visual_process_packet_header(wth, wth->fh, &wth->phdr, &vpkt_hdr,
- err, err_info))
- return FALSE;
-
- if (!wtap_read_packet_bytes(wth->fh, wth->frame_buffer, wth->phdr.caplen,
- err, err_info))
- return FALSE;
-
- if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
- {
- visual_fill_in_chdlc_encapsulation(&wth->phdr, vpkt_hdr.encap_hint,
- wth->frame_buffer);
- }
- return TRUE;
+ return visual_read_packet(wth, wth->fh, &wth->phdr, wth->frame_buffer,
+ err, err_info);
}
/* Read packet header and data for random access. */
static gboolean visual_seek_read(wtap *wth, gint64 seek_off,
- struct wtap_pkthdr *phdr, Buffer *buf, int len,
+ struct wtap_pkthdr *phdr, Buffer *buf, int len _U_,
int *err, gchar **err_info)
{
- struct visual_pkt_hdr vpkt_hdr;
-
/* Seek to the packet header */
if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
return FALSE;
- /* Read and process the packet header. */
- if (!visual_process_packet_header(wth, wth->random_fh, phdr, &vpkt_hdr,
- err, err_info))
- return FALSE;
-
- /* Read the packet data. */
- if (!wtap_read_packet_bytes(wth->random_fh, buf, len, err, err_info))
+ /* Read the packet. */
+ if (!visual_read_packet(wth, wth->random_fh, phdr, buf, err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
-
- if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
- {
- visual_fill_in_chdlc_encapsulation(phdr, vpkt_hdr.encap_hint, buf);
}
-
return TRUE;
}
static gboolean
-visual_process_packet_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
- struct visual_pkt_hdr *vpkt_hdrp, int *err, gchar **err_info)
+visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info)
{
struct visual_read_info *visual = (struct visual_read_info *)wth->priv;
+ struct visual_pkt_hdr vpkt_hdr;
int bytes_read;
guint32 packet_size;
struct visual_atm_hdr vatm_hdr;
@@ -361,11 +336,12 @@ visual_process_packet_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
time_t secs;
guint32 usecs;
guint32 packet_status;
+ guint8 *pd;
/* Read the packet header. */
errno = WTAP_ERR_CANT_READ;
- bytes_read = file_read(vpkt_hdrp, (unsigned int)sizeof *vpkt_hdrp, fh);
- if (bytes_read < 0 || (size_t)bytes_read != sizeof *vpkt_hdrp)
+ bytes_read = file_read(&vpkt_hdr, (unsigned int)sizeof vpkt_hdr, fh);
+ if (bytes_read < 0 || (size_t)bytes_read != sizeof vpkt_hdr)
{
*err = file_error(fh, err_info);
if (*err == 0 && bytes_read != 0)
@@ -376,21 +352,21 @@ visual_process_packet_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
}
/* Get the included length of data. This includes extra headers + payload */
- packet_size = pletohs(&vpkt_hdrp->incl_len);
+ packet_size = pletohs(&vpkt_hdr.incl_len);
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
/* Set the packet time and length. */
t = visual->start_time;
- t += ((double)pletohl(&vpkt_hdrp->ts_delta))*1000;
+ t += ((double)pletohl(&vpkt_hdr.ts_delta))*1000;
secs = (time_t)(t/1000000);
usecs = (guint32)(t - secs*1000000);
phdr->ts.secs = secs;
phdr->ts.nsecs = usecs * 1000;
- phdr->len = pletohs(&vpkt_hdrp->orig_len);
+ phdr->len = pletohs(&vpkt_hdr.orig_len);
- packet_status = pletohl(&vpkt_hdrp->status);
+ packet_status = pletohl(&vpkt_hdr.status);
/* Do encapsulation-specific processing.
@@ -584,59 +560,60 @@ visual_process_packet_header(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
phdr->len = phdr->caplen;
}
- return TRUE;
-}
-
-static void visual_fill_in_chdlc_encapsulation(struct wtap_pkthdr *phdr,
- guint8 encap_hint, Buffer *buf)
-{
- guint8 *pd;
-
- /* Fill in the encapsulation. Visual files have a media type in the
- file header and an encapsulation type in each packet header. Files
- with a media type of HDLC can be either Cisco EtherType or PPP.
-
- The encapsulation hint values we've seen are:
-
- 2 - seen in an Ethernet capture
- 13 - seen in a PPP capture; possibly also seen in Cisco HDLC
- captures
- 14 - seen in a PPP capture; probably seen only for PPP.
-
- According to bug 2005, the collection probe can be configured
- for PPP, in which case the encapsulation hint is 14, or can
- be configured for auto-detect, in which case the encapsulation
- hint is 13, and the encapsulation must be guessed from the
- packet contents. Auto-detect is the default. */
- pd = buffer_start_ptr(buf);
+ /* Read the packet data */
+ if (!wtap_read_packet_bytes(fh, buf, packet_size, err, err_info))
+ return FALSE;
- /* If PPP is specified in the encap hint, then use that */
- if (encap_hint == 14)
+ if (wth->file_encap == WTAP_ENCAP_CHDLC_WITH_PHDR)
{
- /* But first we need to examine the first three octets to
- try to determine the proper encapsulation, see RFC 2364. */
- if (phdr->caplen >= 3 &&
- (0xfe == pd[0]) && (0xfe == pd[1]) && (0x03 == pd[2]))
+ /* Fill in the encapsulation. Visual files have a media type in the
+ file header and an encapsulation type in each packet header. Files
+ with a media type of HDLC can be either Cisco EtherType or PPP.
+
+ The encapsulation hint values we've seen are:
+
+ 2 - seen in an Ethernet capture
+ 13 - seen in a PPP capture; possibly also seen in Cisco HDLC
+ captures
+ 14 - seen in a PPP capture; probably seen only for PPP.
+
+ According to bug 2005, the collection probe can be configured
+ for PPP, in which case the encapsulation hint is 14, or can
+ be configured for auto-detect, in which case the encapsulation
+ hint is 13, and the encapsulation must be guessed from the
+ packet contents. Auto-detect is the default. */
+ pd = buffer_start_ptr(buf);
+
+ /* If PPP is specified in the encap hint, then use that */
+ if (vpkt_hdr.encap_hint == 14)
{
- /* It is actually LLC encapsulated PPP */
- phdr->pkt_encap = WTAP_ENCAP_ATM_RFC1483;
+ /* But first we need to examine the first three octets to
+ try to determine the proper encapsulation, see RFC 2364. */
+ if (packet_size >= 3 &&
+ (0xfe == pd[0]) && (0xfe == pd[1]) && (0x03 == pd[2]))
+ {
+ /* It is actually LLC encapsulated PPP */
+ phdr->pkt_encap = WTAP_ENCAP_ATM_RFC1483;
+ }
+ else
+ {
+ /* It is actually PPP */
+ phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
+ }
}
else
{
- /* It is actually PPP */
- phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
- }
- }
- else
- {
- /* Otherwise, we need to examine the first two octets to
- try to determine the encapsulation. */
- if (phdr->caplen >= 2 && (0xff == pd[0]) && (0x03 == pd[1]))
- {
- /* It is actually PPP */
- phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
+ /* Otherwise, we need to examine the first two octets to
+ try to determine the encapsulation. */
+ if (packet_size >= 2 && (0xff == pd[0]) && (0x03 == pd[1]))
+ {
+ /* It is actually PPP */
+ phdr->pkt_encap = WTAP_ENCAP_PPP_WITH_PHDR;
+ }
}
}
+
+ return TRUE;
}
/* Check for media types that may be written in Visual file format.
diff --git a/wiretap/vms.c b/wiretap/vms.c
index 31ad1debe0..6850323c9c 100644
--- a/wiretap/vms.c
+++ b/wiretap/vms.c
@@ -119,7 +119,7 @@ Format 2:
... packet seq # = nn at DD-MMM-YYYY hh:mm:ss.ss
-If there are other formats then code will have to be written in parse_vms_rec_hdr()
+If there are other formats then code will have to be written in parse_vms_packet()
to handle them.
--------------------------------------------------------------------------------
@@ -148,10 +148,8 @@ static gboolean vms_seek_read(wtap *wth, gint64 seek_off,
int *err, gchar **err_info);
static gboolean parse_single_hex_dump_line(char* rec, guint8 *buf,
long byte_offset, int in_off, int remaining_bytes);
-static gboolean parse_vms_hex_dump(FILE_T fh, int pkt_len, Buffer *buf,
- int *err, gchar **err_info);
-static gboolean parse_vms_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr,
- int *err, gchar **err_info);
+static gboolean parse_vms_packet(FILE_T fh, struct wtap_pkthdr *phdr,
+ Buffer *buf, int *err, gchar **err_info);
#ifdef TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE
/* Seeks to the beginning of the next packet, and returns the
@@ -275,38 +273,26 @@ static gboolean vms_read(wtap *wth, int *err, gchar **err_info,
*err = file_error(wth->fh, err_info);
return FALSE;
}
-
- /* Parse the header */
- if (!parse_vms_rec_hdr(wth->fh, &wth->phdr, err, err_info))
- return FALSE;
-
- /* Convert the ASCII hex dump to binary data */
- if (!parse_vms_hex_dump(wth->fh, wth->phdr.caplen, wth->frame_buffer, err, err_info))
- return FALSE;
-
*data_offset = offset;
- return TRUE;
+
+ /* Parse the packet */
+ return parse_vms_packet(wth->fh, &wth->phdr, wth->frame_buffer, err, err_info);
}
/* Used to read packets in random-access fashion */
static gboolean
vms_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
- Buffer *buf, int len, int *err, gchar **err_info)
+ Buffer *buf, int len _U_, int *err, gchar **err_info)
{
if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1)
return FALSE;
- if (!parse_vms_rec_hdr(wth->random_fh, phdr, err, err_info))
- return FALSE;
-
- if (phdr->caplen != (guint32)len) {
- *err = WTAP_ERR_BAD_FILE;
- *err_info = g_strdup_printf("vms: requested length %d doesn't match length %d",
- len, phdr->caplen);
+ if (!parse_vms_packet(wth->random_fh, phdr, buf, err, err_info)) {
+ if (*err == 0)
+ *err = WTAP_ERR_SHORT_READ;
return FALSE;
}
-
- return parse_vms_hex_dump(wth->random_fh, phdr->caplen, buf, err, err_info);
+ return TRUE;
}
/* isdumpline assumes that dump lines start with some non-alphanumerics
@@ -334,9 +320,9 @@ isdumpline( gchar *line )
return isspace((guchar)*line);
}
-/* Parses a packet record header. */
+/* Parses a packet record. */
static gboolean
-parse_vms_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_info)
+parse_vms_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
{
char line[VMS_LINE_LENGTH + 1];
int num_items_scanned;
@@ -347,6 +333,9 @@ parse_vms_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_inf
char mon[4] = {'J', 'A', 'N', 0};
gchar *p;
static const gchar months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
+ int i;
+ int offset = 0;
+ guint8 *pd;
tm.tm_year = 1970;
tm.tm_mon = 0;
@@ -420,19 +409,6 @@ parse_vms_rec_hdr(FILE_T fh, struct wtap_pkthdr *phdr, int *err, gchar **err_inf
phdr->caplen = pkt_len;
phdr->len = pkt_len;
- return TRUE;
-}
-
-/* Converts ASCII hex dump to binary data */
-static gboolean
-parse_vms_hex_dump(FILE_T fh, int pkt_len, Buffer *buf, int *err,
- gchar **err_info)
-{
- gchar line[VMS_LINE_LENGTH + 1];
- int i;
- int offset = 0;
- guint8 *pd;
-
/* Make sure we have enough room for the packet */
buffer_assure_space(buf, pkt_len);
pd = buffer_start_ptr(buf);