summaryrefslogtreecommitdiff
path: root/wiretap/ascend.y
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-06-16 00:20:00 +0000
committerGuy Harris <guy@alum.mit.edu>2013-06-16 00:20:00 +0000
commit8c9edf12800bc6d68894dc457e7ebaf994429da8 (patch)
treeec6efefbd4e7f8227a7b96661f721ff4ba2986c3 /wiretap/ascend.y
parent3846abe34d6861c6ee0bba61fcd5baa4d213885c (diff)
downloadwireshark-8c9edf12800bc6d68894dc457e7ebaf994429da8.tar.gz
Have the seek-read routines take a Buffer rather than a guint8 pointer
as the "where to put the packet data" argument. This lets more of the libwiretap code be common between the read and seek-read code paths, and also allows for more flexibility in the "fill in the data" path - we can expand the buffer as needed in both cases. svn path=/trunk/; revision=49949
Diffstat (limited to 'wiretap/ascend.y')
-rw-r--r--wiretap/ascend.y102
1 files changed, 64 insertions, 38 deletions
diff --git a/wiretap/ascend.y b/wiretap/ascend.y
index 3f6ea62da9..c6c5b4b6a0 100644
--- a/wiretap/ascend.y
+++ b/wiretap/ascend.y
@@ -440,20 +440,16 @@ init_parse_ascend(void)
start_time = 0; /* we haven't see a date/time yet */
}
-/* Parse the capture file.
- Returns:
- PARSED_RECORD if we got a packet
- PARSED_NONRECORD if the parser succeeded but didn't see a packet
- PARSE_FAILED if the parser failed. */
-parse_t
-parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
+/* Run the parser. */
+static int
+run_ascend_parser(FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
{
/* yydebug = 1; */
int retval;
ascend_init_lexer(fh);
- pkt_data = pd;
pseudo_header = &phdr->pseudo_header.ascend;
+ pkt_data = pd;
bcur = 0;
first_hexbyte = 0;
@@ -477,21 +473,54 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
caplen = bcur;
+ return retval;
+}
+
+/* Parse the capture file.
+ Returns:
+ TRUE if we got a packet
+ FALSE otherwise. */
+gboolean
+check_ascend(FILE_T fh, struct wtap_pkthdr *phdr)
+{
+ guint8 buf[ASCEND_MAX_PKT_LEN];
+
+ run_ascend_parser(fh, phdr, buf);
+
+ /* if we got at least some data, return success even if the parser
+ reported an error. This is because the debug header gives the number
+ of bytes on the wire, not actually how many bytes are in the trace.
+ We won't know where the data ends until we run into the next packet. */
+ return (caplen != 0);
+}
+
+/* Parse the capture file.
+ Returns:
+ PARSED_RECORD if we got a packet
+ PARSED_NONRECORD if the parser succeeded but didn't see a packet
+ PARSE_FAILED if the parser failed. */
+parse_t
+parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+ guint length)
+{
+ int retval;
+
+ buffer_assure_space(buf, length);
+ retval = run_ascend_parser(fh, phdr, buffer_start_ptr(buf));
+
/* did we see any data (hex bytes)? if so, tip off ascend_seek()
as to where to look for the next packet, if any. If we didn't,
maybe this record was broken. Advance so we don't get into
an infinite loop reading a broken trace. */
if (first_hexbyte) {
- if (ascend != NULL)
- ascend->next_packet_seek_start = first_hexbyte;
+ ascend->next_packet_seek_start = first_hexbyte;
} else {
/* Sometimes, a header will be printed but the data will be omitted, or
worse -- two headers will be printed, followed by the data for each.
Because of this, we need to be fairly tolerant of what we accept
here. If we didn't find any hex bytes, skip over what we've read so
far so we can try reading a new packet. */
- if (ascend != NULL)
- ascend->next_packet_seek_start = file_tell(fh);
+ ascend->next_packet_seek_start = file_tell(fh);
retval = 0;
}
@@ -500,33 +529,31 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
of bytes on the wire, not actually how many bytes are in the trace.
We won't know where the data ends until we run into the next packet. */
if (caplen) {
- if (ascend) {
- if (! ascend->adjusted) {
- ascend->adjusted = TRUE;
- if (start_time != 0) {
- /*
- * Capture file contained a date and time.
- * We do this only if this is the very first packet we've seen -
- * i.e., if "ascend->adjusted" is false - because
- * if we get a date and time after the first packet, we can't
- * go back and adjust the time stamps of the packets we've already
- * processed, and basing the time stamps of this and following
- * packets on the time stamp from the file text rather than the
- * ctime of the capture file means times before this and after
- * this can't be compared.
- */
- ascend->inittime = start_time;
- }
- if (ascend->inittime > secs)
- ascend->inittime -= secs;
+ if (! ascend->adjusted) {
+ ascend->adjusted = TRUE;
+ if (start_time != 0) {
+ /*
+ * Capture file contained a date and time.
+ * We do this only if this is the very first packet we've seen -
+ * i.e., if "ascend->adjusted" is false - because
+ * if we get a date and time after the first packet, we can't
+ * go back and adjust the time stamps of the packets we've already
+ * processed, and basing the time stamps of this and following
+ * packets on the time stamp from the file text rather than the
+ * ctime of the capture file means times before this and after
+ * this can't be compared.
+ */
+ ascend->inittime = start_time;
}
- phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
- phdr->ts.secs = secs + ascend->inittime;
- phdr->ts.nsecs = usecs * 1000;
- phdr->caplen = caplen;
- phdr->len = wirelen;
+ if (ascend->inittime > secs)
+ ascend->inittime -= secs;
}
-
+ phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
+ phdr->ts.secs = secs + ascend->inittime;
+ phdr->ts.nsecs = usecs * 1000;
+ phdr->caplen = caplen;
+ phdr->len = wirelen;
+
/*
* For these types, the encapsulation we use is not WTAP_ENCAP_ASCEND,
* so set the pseudo-headers appropriately for the type (WTAP_ENCAP_ISDN
@@ -547,7 +574,6 @@ parse_ascend(ascend_t *ascend, FILE_T fh, struct wtap_pkthdr *phdr, guint8 *pd)
phdr->pseudo_header.eth.fcs_len = 0;
break;
}
-
return PARSED_RECORD;
}