diff options
author | Guy Harris <guy@alum.mit.edu> | 2010-02-24 08:39:19 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2010-02-24 08:39:19 +0000 |
commit | 756bf6002032e9433e74206654c942561f71e1a5 (patch) | |
tree | d2496a52090fd76cdb31bbcda1e6ffad0663322b | |
parent | 7ca35912aa6a82e100c8154ca4d32c2372854012 (diff) |
Move the definition of the private data structure from wtap-int.h to the
iSeries capture processor. Parse the start date into year/month/day at
the time we see it, rather than for every packet; that means we don't
need to allocate a buffer to hold the date as a string (a buffer which
we weren't ever freeing).
svn path=/trunk/; revision=31981
-rw-r--r-- | wiretap/iseries.c | 58 | ||||
-rw-r--r-- | wiretap/wtap-int.h | 7 |
2 files changed, 33 insertions, 32 deletions
diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 0d968d3c59..c143466839 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -138,6 +138,13 @@ #define ISERIES_FORMAT_ASCII 1 #define ISERIES_FORMAT_UNICODE 2 +typedef struct { + gboolean have_date; /* TRUE if we found a capture start date */ + int year, month, day; /* The start date */ + gboolean tcp_formatted; /* TCP/IP data formated Y/N */ + int format; /* Trace format type */ +} iseries_t; + static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset); static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, @@ -257,14 +264,14 @@ iseries_check_file_type (wtap * wth, int *err, int format) guint line; int num_items_scanned; char buf[ISERIES_LINE_LENGTH], protocol[9], tcpformat[2]; - char *sdate; + iseries_t *iseries; /* Save trace format for passing between packets */ - sdate = g_malloc (10); - wth->capture.iseries = g_malloc (sizeof (iseries_t)); - wth->capture.iseries->sdate = NULL; - wth->capture.iseries->format = format; - wth->capture.iseries->tcp_formatted = FALSE; + iseries = (iseries_t *) g_malloc (sizeof (iseries_t)); + wth->capture.generic = iseries; + iseries->have_date = FALSE; + iseries->format = format; + iseries->tcp_formatted = FALSE; for (line = 0; line < ISERIES_HDR_LINES_TO_CHECK; line++) { @@ -273,7 +280,7 @@ iseries_check_file_type (wtap * wth, int *err, int format) /* * Check that we are dealing with an ETHERNET trace */ - if (wth->capture.iseries->format == ISERIES_FORMAT_UNICODE) + if (iseries->format == ISERIES_FORMAT_UNICODE) { iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); } @@ -297,11 +304,11 @@ iseries_check_file_type (wtap * wth, int *err, int format) { if (strncmp (tcpformat, "Y", 1) == 0) { - wth->capture.iseries->tcp_formatted = TRUE; + iseries->tcp_formatted = TRUE; } else { - wth->capture.iseries->tcp_formatted = FALSE; + iseries->tcp_formatted = FALSE; } } @@ -310,11 +317,12 @@ iseries_check_file_type (wtap * wth, int *err, int format) * extract it here and store for all packets to access */ num_items_scanned = sscanf (buf, - " START DATE/TIME . . . . . . : %8s", - sdate); - if (num_items_scanned == 1) + " START DATE/TIME . . . . . . : %d/%d/%d", + &iseries->month, &iseries->day, + &iseries->year); + if (num_items_scanned == 3) { - wth->capture.iseries->sdate = sdate; + iseries->have_date = TRUE; } } @@ -373,6 +381,7 @@ iseries_seek_next_packet (wtap * wth, int *err) int line; gint64 cur_off; long buflen; + iseries_t *iseries = (iseries_t *)wth->capture.generic; /* * Seeks to the beginning of the next packet, and returns the @@ -385,7 +394,7 @@ iseries_seek_next_packet (wtap * wth, int *err) /* Convert UNICODE to ASCII if required and determine */ /* the number of bytes to rewind to beginning of record. */ - if (wth->capture.iseries->format == ISERIES_FORMAT_UNICODE) + if (iseries->format == ISERIES_FORMAT_UNICODE) { /* buflen is #bytes to 1st 0x0A */ buflen = iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); @@ -478,7 +487,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, gboolean isValid, isCurrentPacket, IPread, TCPread, isDATA; int num_items_scanned, line, pktline, buflen, i; guint32 pkt_len; - int cap_len, pktnum, month, day, year, hr, min, sec, csec; + int cap_len, pktnum, hr, min, sec, csec; char direction[2], destmac[13], srcmac[13], type[5], ipheader[41], tcpheader[81]; char hex1[17], hex2[17], hex3[17], hex4[17]; @@ -486,6 +495,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, guint8 *buf; char *tcpdatabuf, *workbuf, *asciibuf; struct tm tm; + iseries_t *iseries = (iseries_t *)wth->capture.generic; /* * Check for packet headers in first 3 lines this should handle page breaks @@ -506,7 +516,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, return -1; } /* Convert UNICODE data to ASCII */ - if (wth->capture.iseries->format == ISERIES_FORMAT_UNICODE) + if (iseries->format == ISERIES_FORMAT_UNICODE) { iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); } @@ -550,13 +560,11 @@ iseries_parse_packet (wtap * wth, FILE_T fh, * different on other platforms though all the traces I've seen seem to show resolution * to Milliseconds (i.e HH:MM:SS.nnnnn) or Nanoseconds (i.e HH:MM:SS.nnnnnn) */ - if (wth->capture.iseries->sdate) + if (iseries->have_date) { - num_items_scanned = - sscanf (wth->capture.iseries->sdate, "%d/%d/%d", &month, &day, &year); - tm.tm_year = 100 + year; - tm.tm_mon = month - 1; - tm.tm_mday = day; + tm.tm_year = 100 + iseries->year; + tm.tm_mon = iseries->month - 1; + tm.tm_mday = iseries->day; tm.tm_hour = hr; tm.tm_min = min; tm.tm_sec = sec; @@ -616,7 +624,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, } /* Convert UNICODE data to ASCII and determine line length */ - if (wth->capture.iseries->format == ISERIES_FORMAT_UNICODE) + if (iseries->format == ISERIES_FORMAT_UNICODE) { buflen = iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); } @@ -704,7 +712,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, * For a formated trace ensure we have read at least the IP and TCP headers otherwise * exit and pass error message to user. */ - if (wth->capture.iseries->tcp_formatted) + if (iseries->tcp_formatted) { if (!IPread) { @@ -728,7 +736,7 @@ iseries_parse_packet (wtap * wth, FILE_T fh, if (isDATA) { /* packet contained data */ - if (wth->capture.iseries->tcp_formatted) + if (iseries->tcp_formatted) { /* build string for formatted fields */ g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s%s", diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h index 27acf0edb8..317fec49e0 100644 --- a/wiretap/wtap-int.h +++ b/wiretap/wtap-int.h @@ -45,12 +45,6 @@ #include "wtap.h" typedef struct { - char *sdate; /* Packet start date */ - gboolean tcp_formatted; /* TCP/IP data formated Y/N */ - int format; /* Trace format type */ -} iseries_t; - -typedef struct { gboolean byte_swapped; } i4btrace_t; @@ -143,7 +137,6 @@ struct wtap { gint64 data_offset; union { - iseries_t *iseries; i4btrace_t *i4btrace; nettl_t *nettl; netmon_t *netmon; |