From 5a1b276845f242c813c02d1f4bd415f4609cf122 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 20 Apr 2012 01:43:12 +0000 Subject: [PATCH] Use consistent 2-space indentation, and don't use tabs. svn path=/trunk/; revision=42146 --- wiretap/iseries.c | 992 +++++++++++++++++++++++----------------------- 1 file changed, 496 insertions(+), 496 deletions(-) diff --git a/wiretap/iseries.c b/wiretap/iseries.c index 66eec92204..3df9ba1d4a 100644 --- a/wiretap/iseries.c +++ b/wiretap/iseries.c @@ -147,7 +147,7 @@ Number S/R Length Timer MAC Address MAC Address #include -#define ISERIES_HDR_MAGIC_STR "COMMUNICATIONS TRACE" +#define ISERIES_HDR_MAGIC_STR "COMMUNICATIONS TRACE" #define ISERIES_HDR_MAGIC_LEN 20 #define ISERIES_UNICODE_HDR_MAGIC_LEN 17 #define ISERIES_PKT_MAGIC_STR "ETHV2" @@ -170,20 +170,20 @@ typedef struct { } iseries_t; static gboolean iseries_read (wtap * wth, int *err, gchar ** err_info, - gint64 *data_offset); + gint64 *data_offset); static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, - union wtap_pseudo_header *pseudo_header, - guint8 * pd, int len, int *err, - gchar ** err_info); + union wtap_pseudo_header *pseudo_header, + guint8 * pd, int len, int *err, + gchar ** err_info); static gboolean iseries_check_file_type (wtap * wth, int *err, gchar **err_info, - int format); + int format); static gint64 iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info); static int iseries_parse_packet (wtap * wth, FILE_T fh, - union wtap_pseudo_header *pseudo_header, - guint8 * pd, int *err, gchar ** err_info); + union wtap_pseudo_header *pseudo_header, + guint8 * pd, int *err, gchar ** err_info); static int iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes); static gboolean iseries_parse_hex_string (const char * ascii, guint8 * buf, - int len); + int len); int iseries_open (wtap * wth, int *err, gchar ** err_info) @@ -207,7 +207,7 @@ iseries_open (wtap * wth, int *err, gchar ** err_info) { *err = file_error (wth->fh, err_info); if (*err != 0) - return -1; + return -1; return 0; } @@ -217,76 +217,76 @@ iseries_open (wtap * wth, int *err, gchar ** err_info) offset=0; while (offset < ISERIES_LINE_LENGTH - ISERIES_UNICODE_HDR_MAGIC_LEN) { - if (memcmp (magic + offset, unicodemagic, ISERIES_UNICODE_HDR_MAGIC_LEN) == 0) { - if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) - { - return 0; - } - /* - * Do some basic sanity checking to ensure we can handle the - * contents of this trace - */ - if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_UNICODE)) - { - if (*err == 0) - return 0; - else - return -1; - } - wth->data_offset = 0; - wth->file_encap = WTAP_ENCAP_ETHERNET; - wth->file_type = WTAP_FILE_ISERIES; - wth->snapshot_length = 0; - wth->subtype_read = iseries_read; - wth->subtype_seek_read = iseries_seek_read; - wth->tsprecision = WTAP_FILE_TSPREC_USEC; - if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) - { - return 0; - } - return 1; - } - offset += 1; + if (memcmp (magic + offset, unicodemagic, ISERIES_UNICODE_HDR_MAGIC_LEN) == 0) { + if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) + { + return 0; + } + /* + * Do some basic sanity checking to ensure we can handle the + * contents of this trace + */ + if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_UNICODE)) + { + if (*err == 0) + return 0; + else + return -1; + } + wth->data_offset = 0; + wth->file_encap = WTAP_ENCAP_ETHERNET; + wth->file_type = WTAP_FILE_ISERIES; + wth->snapshot_length = 0; + wth->subtype_read = iseries_read; + wth->subtype_seek_read = iseries_seek_read; + wth->tsprecision = WTAP_FILE_TSPREC_USEC; + if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) + { + return 0; + } + return 1; + } + offset += 1; } - /* + /* * Check if this is a ASCII formatted file by scanning for the magic string */ offset=0; while (offset < ISERIES_LINE_LENGTH - ISERIES_HDR_MAGIC_LEN) - { - if (memcmp (magic + offset, ISERIES_HDR_MAGIC_STR, ISERIES_HDR_MAGIC_LEN) == 0) { - - if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) - { - return 0; - } - /* - * Do some basic sanity checking to ensure we can handle the - * contents of this trace - */ - if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_ASCII)) - { - if (*err == 0) - return 0; - else - return -1; - } - wth->data_offset = 0; - wth->file_encap = WTAP_ENCAP_ETHERNET; - wth->file_type = WTAP_FILE_ISERIES; - wth->snapshot_length = 0; - wth->subtype_read = iseries_read; - wth->subtype_seek_read = iseries_seek_read; - wth->tsprecision = WTAP_FILE_TSPREC_USEC; - if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) - { - return 0; - } - return 1; - } - offset += 1; - } + { + if (memcmp (magic + offset, ISERIES_HDR_MAGIC_STR, ISERIES_HDR_MAGIC_LEN) == 0) + { + if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) + { + return 0; + } + /* + * Do some basic sanity checking to ensure we can handle the + * contents of this trace + */ + if (!iseries_check_file_type (wth, err, err_info, ISERIES_FORMAT_ASCII)) + { + if (*err == 0) + return 0; + else + return -1; + } + wth->data_offset = 0; + wth->file_encap = WTAP_ENCAP_ETHERNET; + wth->file_type = WTAP_FILE_ISERIES; + wth->snapshot_length = 0; + wth->subtype_read = iseries_read; + wth->subtype_seek_read = iseries_seek_read; + wth->tsprecision = WTAP_FILE_TSPREC_USEC; + if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) + { + return 0; + } + return 1; + } + offset += 1; + } /* Neither ASCII or UNICODE so not supported */ return 0; @@ -316,88 +316,88 @@ iseries_check_file_type (wtap * wth, int *err, gchar **err_info, int format) for (line = 0; line < ISERIES_HDR_LINES_TO_CHECK; line++) { if (file_gets (buf, ISERIES_LINE_LENGTH, wth->fh) != NULL) - { - /* - * Check that we are dealing with an ETHERNET trace - */ - if (iseries->format == ISERIES_FORMAT_UNICODE) - { + { + /* + * Check that we are dealing with an ETHERNET trace + */ + if (iseries->format == ISERIES_FORMAT_UNICODE) + { iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); - } - ascii_strup_inplace(buf); - num_items_scanned = sscanf (buf, - "%*[ \n\t]OBJECT PROTOCOL%*[ .:\n\t]%8s", - protocol); - if (num_items_scanned == 1) - { - if (memcmp (protocol, "ETHERNET", 8) != 0) - return FALSE; - } + } + ascii_strup_inplace(buf); + num_items_scanned = sscanf (buf, + "%*[ \n\t]OBJECT PROTOCOL%*[ .:\n\t]%8s", + protocol); + if (num_items_scanned == 1) + { + if (memcmp (protocol, "ETHERNET", 8) != 0) + return FALSE; + } - /* - * The header is the only place where the date part of the timestamp is held, so - * extract it here and store for all packets to access - */ - num_items_scanned = sscanf (buf, - "%*[ \n\t]START DATE/TIME%*[ .:\n\t]%2d/%2d/%2d", - &iseries->month, &iseries->day, - &iseries->year); - if (num_items_scanned == 3) - { - iseries->have_date = TRUE; - } + /* + * The header is the only place where the date part of the timestamp is held, so + * extract it here and store for all packets to access + */ + num_items_scanned = sscanf (buf, + "%*[ \n\t]START DATE/TIME%*[ .:\n\t]%2d/%2d/%2d", + &iseries->month, &iseries->day, + &iseries->year); + if (num_items_scanned == 3) + { + iseries->have_date = TRUE; + } - /* - * Determine if this is a IPv4 or IPv6 trace - */ - num_items_scanned = - sscanf (buf+78, - "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); - if (num_items_scanned == 1) - { - if (strncmp (type, "0800", 1) == 0) - { - iseries->ipv6_trace = FALSE; - } - if (strncmp (type, "86DD", 1) == 0) - { - iseries->ipv6_trace = TRUE; - } - } + /* + * Determine if this is a IPv4 or IPv6 trace + */ + num_items_scanned = + sscanf (buf+78, + "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); + if (num_items_scanned == 1) + { + if (strncmp (type, "0800", 1) == 0) + { + iseries->ipv6_trace = FALSE; + } + if (strncmp (type, "86DD", 1) == 0) + { + iseries->ipv6_trace = TRUE; + } + } - /* - * Determine if the data has been formatted - */ - /* IPv6 formatted */ - num_items_scanned = sscanf (buf, - "%*[ \n\t]IPV6 HEADER%1s", - work); - if (num_items_scanned == 1) - { - iseries->tcp_formatted = TRUE; - return TRUE; - } - /* IPv4 formatted */ - num_items_scanned = sscanf (buf, - "%*[ \n\t]IP HEADER %1s", - work); - if (num_items_scanned == 1) - { - iseries->tcp_formatted = TRUE; - return TRUE; - } + /* + * Determine if the data has been formatted + */ + /* IPv6 formatted */ + num_items_scanned = sscanf (buf, + "%*[ \n\t]IPV6 HEADER%1s", + work); + if (num_items_scanned == 1) + { + iseries->tcp_formatted = TRUE; + return TRUE; + } + /* IPv4 formatted */ + num_items_scanned = sscanf (buf, + "%*[ \n\t]IP HEADER %1s", + work); + if (num_items_scanned == 1) + { + iseries->tcp_formatted = TRUE; + return TRUE; + } -} + } else - { - /* EOF or error. */ - if (file_eof (wth->fh)) - *err = 0; - else - *err = file_error (wth->fh, err_info); - return FALSE; - } + { + /* EOF or error. */ + if (file_eof (wth->fh)) + *err = 0; + else + *err = file_error (wth->fh, err_info); + return FALSE; + } } *err = 0; return TRUE; @@ -424,7 +424,7 @@ iseries_read (wtap * wth, int *err, gchar ** err_info, gint64 *data_offset) */ pkt_len = iseries_parse_packet (wth, wth->fh, &wth->pseudo_header, NULL, err, - err_info); + err_info); if (pkt_len == -1) return FALSE; @@ -455,56 +455,56 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) for (line = 0; line < ISERIES_MAX_TRACE_LEN; line++) { if (file_gets (buf, ISERIES_LINE_LENGTH, wth->fh) != NULL) - { + { - /* Convert UNICODE to ASCII if required and determine */ - /* the number of bytes to rewind to beginning of record. */ - if (iseries->format == ISERIES_FORMAT_UNICODE) - { - /* buflen is #bytes to 1st 0x0A */ + /* Convert UNICODE to ASCII if required and determine */ + /* the number of bytes to rewind to beginning of record. */ + if (iseries->format == ISERIES_FORMAT_UNICODE) + { + /* buflen is #bytes to 1st 0x0A */ buflen = iseries_UNICODE_to_ASCII ((guint8 *)buf, ISERIES_LINE_LENGTH); - } - else - { - /* Else buflen is just length of the ASCII string */ - buflen = (long) strlen (buf); - } - ascii_strup_inplace(buf); - /* If packet header found return the offset */ - num_items_scanned = - sscanf (buf+78, - "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); - if (num_items_scanned == 1) - { - /* Rewind to beginning of line */ - cur_off = file_tell (wth->fh); - if (cur_off == -1) - { - *err = file_error (wth->fh, err_info); - return -1; - } - if (file_seek (wth->fh, cur_off - buflen, SEEK_SET, err) == -1) - { - return -1; - } - return cur_off - buflen; - } - } + } + else + { + /* Else buflen is just length of the ASCII string */ + buflen = (long) strlen (buf); + } + ascii_strup_inplace(buf); + /* If packet header found return the offset */ + num_items_scanned = + sscanf (buf+78, + "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); + if (num_items_scanned == 1) + { + /* Rewind to beginning of line */ + cur_off = file_tell (wth->fh); + if (cur_off == -1) + { + *err = file_error (wth->fh, err_info); + return -1; + } + if (file_seek (wth->fh, cur_off - buflen, SEEK_SET, err) == -1) + { + return -1; + } + return cur_off - buflen; + } + } /* Otherwise we got an error or reached EOF */ else - { - if (file_eof (wth->fh)) - { - /* We got an EOF. */ - *err = 0; - } - else - { - /* We got an error. */ - *err = file_error (wth->fh, err_info); - } - return -1; - } + { + if (file_eof (wth->fh)) + { + /* We got an EOF. */ + *err = 0; + } + else + { + /* We got an error. */ + *err = file_error (wth->fh, err_info); + } + return -1; + } } return -1; @@ -515,8 +515,8 @@ iseries_seek_next_packet (wtap * wth, int *err, gchar **err_info) */ static gboolean iseries_seek_read (wtap * wth, gint64 seek_off, - union wtap_pseudo_header *pseudo_header, guint8 * pd, - int len, int *err, gchar ** err_info) + union wtap_pseudo_header *pseudo_header, guint8 * pd, + int len, int *err, gchar ** err_info) { int pkt_len; @@ -528,18 +528,18 @@ iseries_seek_read (wtap * wth, gint64 seek_off, * Parse the packet and extract the various fields */ pkt_len = iseries_parse_packet (wth, wth->random_fh, pseudo_header, pd, - err, err_info); + err, err_info); if (pkt_len != len) { if (pkt_len != -1) - { - *err = WTAP_ERR_BAD_FILE; - *err_info = - g_strdup_printf - ("iseries: requested length %d doesn't match record length %d", - len, pkt_len); - } + { + *err = WTAP_ERR_BAD_FILE; + *err_info = + g_strdup_printf + ("iseries: requested length %d doesn't match record length %d", + len, pkt_len); + } return FALSE; } return TRUE; @@ -548,8 +548,8 @@ iseries_seek_read (wtap * wth, gint64 seek_off, /* Parses a packet. */ static int iseries_parse_packet (wtap * wth, FILE_T fh, - union wtap_pseudo_header *pseudo_header, guint8 * pd, - int *err, gchar ** err_info) + union wtap_pseudo_header *pseudo_header, guint8 * pd, + int *err, gchar ** err_info) { iseries_t *iseries = (iseries_t *)wth->priv; gint64 cur_off; @@ -574,36 +574,36 @@ iseries_parse_packet (wtap * wth, FILE_T fh, for (line = 1; line < ISERIES_PKT_LINES_TO_CHECK; line++) { if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) - { - *err = file_error (fh, err_info); - if (*err == 0) - { - *err = WTAP_ERR_SHORT_READ; - } - return -1; - } + { + *err = file_error (fh, err_info); + if (*err == 0) + { + *err = WTAP_ERR_SHORT_READ; + } + return -1; + } /* Convert UNICODE data to ASCII */ if (iseries->format == ISERIES_FORMAT_UNICODE) - { + { iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); - } - ascii_strup_inplace(data); + } + ascii_strup_inplace(data); num_items_scanned = - sscanf (data, - "%*[ \n\t]%6d%*[ *\n\t]%1s%*[ \n\t]%6d%*[ \n\t]%2d:%2d:%2d.%9d%*[ \n\t]%12s%*[ \n\t]%12s%*[ \n\t]ETHV2%*[ \n\t]TYPE:%*[ \n\t]%4s", - &pktnum, direction, &cap_len, &hr, &min, &sec, &csec, destmac, - srcmac, type); + sscanf (data, + "%*[ \n\t]%6d%*[ *\n\t]%1s%*[ \n\t]%6d%*[ \n\t]%2d:%2d:%2d.%9d%*[ \n\t]%12s%*[ \n\t]%12s%*[ \n\t]ETHV2%*[ \n\t]TYPE:%*[ \n\t]%4s", + &pktnum, direction, &cap_len, &hr, &min, &sec, &csec, destmac, + srcmac, type); if (num_items_scanned == 10) - { - /* OK! We found the packet header line */ - isValid = TRUE; - /* - * XXX - The Capture length returned by the iSeries trace doesn't seem to include the src/dest MAC - * addresses or the packet type. So we add them here. - */ - cap_len += 14; - break; - } + { + /* OK! We found the packet header line */ + isValid = TRUE; + /* + * XXX - The Capture length returned by the iSeries trace doesn't seem to include the src/dest MAC + * addresses or the packet type. So we add them here. + */ + cap_len += 14; + break; + } } /* @@ -638,14 +638,14 @@ iseries_parse_packet (wtap * wth, FILE_T fh, wth->phdr.ts.secs = mktime (&tm); /* Handle Millisecond precision for timer */ if (csec > 99999) - { - wth->phdr.ts.nsecs = csec * 1000; - } + { + wth->phdr.ts.nsecs = csec * 1000; + } /* Handle Nanosecond precision for timer */ else - { - wth->phdr.ts.nsecs = csec * 10000; - } + { + wth->phdr.ts.nsecs = csec * 10000; + } } wth->phdr.caplen = cap_len; @@ -673,248 +673,248 @@ iseries_parse_packet (wtap * wth, FILE_T fh, pktline++; /* Read the next line */ if (file_gets (data, ISERIES_LINE_LENGTH, fh) == NULL) - { - if (file_eof (fh)) - { - break; - } - else - { - *err = file_error (fh, err_info); - if (*err == 0) - { - *err = WTAP_ERR_SHORT_READ; - } - return -1; - } - } + { + if (file_eof (fh)) + { + break; + } + else + { + *err = file_error (fh, err_info); + if (*err == 0) + { + *err = WTAP_ERR_SHORT_READ; + } + return -1; + } + } /* Convert UNICODE data to ASCII and determine line length */ if (iseries->format == ISERIES_FORMAT_UNICODE) - { + { buflen = iseries_UNICODE_to_ASCII ((guint8 *)data, ISERIES_LINE_LENGTH); - } + } else - { - /* Else bytes to rewind is just length of ASCII string */ - buflen = (int) strlen (data); - } + { + /* Else bytes to rewind is just length of ASCII string */ + buflen = (int) strlen (data); + } - /* - * Decode data for IPv4 traces and unformatted IPv6 traces - */ - if ((!iseries->ipv6_trace) || ((iseries->ipv6_trace) && (!iseries->tcp_formatted))) - { - /* If this is a IP header hex string then set flag */ - num_items_scanned = sscanf (data + 22, "IP Header%*[ .:\n\t]%40s", ipheader); - if (num_items_scanned == 1) - { - IPread = TRUE; - } + /* + * Decode data for IPv4 traces and unformatted IPv6 traces + */ + if ((!iseries->ipv6_trace) || ((iseries->ipv6_trace) && (!iseries->tcp_formatted))) + { + /* If this is a IP header hex string then set flag */ + num_items_scanned = sscanf (data + 22, "IP Header%*[ .:\n\t]%40s", ipheader); + if (num_items_scanned == 1) + { + IPread = TRUE; + } - /* If this is TCP header hex string then set flag */ - num_items_scanned = sscanf (data + 22, "TCP Header%*[ .:\n\t]%80s", tcpheader); - if (num_items_scanned == 1) - { - TCPread = TRUE; - } + /* If this is TCP header hex string then set flag */ + num_items_scanned = sscanf (data + 22, "TCP Header%*[ .:\n\t]%80s", tcpheader); + if (num_items_scanned == 1) + { + TCPread = TRUE; + } - /* - * If there is data in the packet handle it here. - * - * The data header line will have the "Data . . " identifier, subsequent lines don't - */ - num_items_scanned = - sscanf (data + 27, "%16[A-F0-9] %16[A-F0-9] %16[A-F0-9] %16[A-F0-9]", - hex1, hex2, hex3, hex4); - if (num_items_scanned > 0) - { - isDATA = TRUE; - /* - * Scan the data line for data blocks, depending on the number of blocks scanned - * add them along with current tcpdata buffer to the work buffer and then copy - * work buffer to tcpdata buffer to continue building up tcpdata buffer to contain - * a single hex string. - */ - switch (num_items_scanned) - { - case 1: - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, - hex1); - break; - case 2: - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", - tcpdatabuf, hex1, hex2); - break; - case 3: - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", - tcpdatabuf, hex1, hex2, hex3); - break; - default: - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", - tcpdatabuf, hex1, hex2, hex3, hex4); - } - memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); - } - } + /* + * If there is data in the packet handle it here. + * + * The data header line will have the "Data . . " identifier, subsequent lines don't + */ + num_items_scanned = + sscanf (data + 27, "%16[A-F0-9] %16[A-F0-9] %16[A-F0-9] %16[A-F0-9]", + hex1, hex2, hex3, hex4); + if (num_items_scanned > 0) + { + isDATA = TRUE; + /* + * Scan the data line for data blocks, depending on the number of blocks scanned + * add them along with current tcpdata buffer to the work buffer and then copy + * work buffer to tcpdata buffer to continue building up tcpdata buffer to contain + * a single hex string. + */ + switch (num_items_scanned) + { + case 1: + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, + hex1); + break; + case 2: + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", + tcpdatabuf, hex1, hex2); + break; + case 3: + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", + tcpdatabuf, hex1, hex2, hex3); + break; + default: + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", + tcpdatabuf, hex1, hex2, hex3, hex4); + } + memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); + } + } - /* - * Decode data for IPv6 formatted traces - */ - if ((iseries->ipv6_trace) && (iseries->tcp_formatted)) - { - /* - * If there are IPv6 headers in the packet handle it here. - * - * iSeries IPv6 headers are aligned after column 36 and appears as a single hex string - * of 16,32,48 or 64 bytes - */ - isDataHandled=FALSE; - num_items_scanned = - sscanf (data + 35, "%*[ \n\t]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]", - hex1, hex2, hex3, hex4); - if (num_items_scanned > 0) - { - isDATA = TRUE; - /* - * Scan the data line for data blocks, depending on the number of blocks scanned - * add them along with current tcpdata buffer to the work buffer and then copy - * work buffer to tcpdata buffer to continue building up tcpdata buffer to contain - * a single hex string. - */ - switch (num_items_scanned) - { - case 1: - if (strlen(hex1)==16) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, - hex1); - isDataHandled=TRUE; - } - break; - case 2: - if ((strlen(hex1)==16) && (strlen(hex2)==16)) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", - tcpdatabuf, hex1, hex2); - isDataHandled=TRUE; - } - break; - case 3: - if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16)) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", - tcpdatabuf, hex1, hex2, hex3); - isDataHandled=TRUE; - } - break; - default: - if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16) && (strlen(hex4)==16)) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", - tcpdatabuf, hex1, hex2, hex3, hex4); - isDataHandled=TRUE; - } - } - memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); - } - /* - * If there is data in the packet handle it here. - * - * The data header line will have the "Data . . " identifier, subsequent lines don't - * Check to ensure we haven't already captured and used this data block already above - */ - num_items_scanned = - sscanf (data + 26, "%*[ \n\t]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]", - hex1, hex2, hex3, hex4); - if ((num_items_scanned > 0) && (isDataHandled==FALSE)) - { - isDATA = TRUE; - /* - * Scan the data line for data blocks, depending on the number of blocks scanned - * add them along with current tcpdata buffer to the work buffer and then copy - * work buffer to tcpdata buffer to continue building up tcpdata buffer to contain - * a single hex string. - */ - switch (num_items_scanned) - { - case 1: - if (strlen(hex1)==16) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, - hex1); - } - break; - case 2: - if ((strlen(hex1)==16) && (strlen(hex2)==16)) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", - tcpdatabuf, hex1, hex2); - } - break; - case 3: - if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16)) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", - tcpdatabuf, hex1, hex2, hex3); - } - break; - default: - if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16) && (strlen(hex4)==16)) - { - g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", - tcpdatabuf, hex1, hex2, hex3, hex4); - } - } - memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); - } - } + /* + * Decode data for IPv6 formatted traces + */ + if ((iseries->ipv6_trace) && (iseries->tcp_formatted)) + { + /* + * If there are IPv6 headers in the packet handle it here. + * + * iSeries IPv6 headers are aligned after column 36 and appears as a single hex string + * of 16,32,48 or 64 bytes + */ + isDataHandled=FALSE; + num_items_scanned = + sscanf (data + 35, "%*[ \n\t]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]", + hex1, hex2, hex3, hex4); + if (num_items_scanned > 0) + { + isDATA = TRUE; + /* + * Scan the data line for data blocks, depending on the number of blocks scanned + * add them along with current tcpdata buffer to the work buffer and then copy + * work buffer to tcpdata buffer to continue building up tcpdata buffer to contain + * a single hex string. + */ + switch (num_items_scanned) + { + case 1: + if (strlen(hex1)==16) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, + hex1); + isDataHandled=TRUE; + } + break; + case 2: + if ((strlen(hex1)==16) && (strlen(hex2)==16)) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", + tcpdatabuf, hex1, hex2); + isDataHandled=TRUE; + } + break; + case 3: + if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16)) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", + tcpdatabuf, hex1, hex2, hex3); + isDataHandled=TRUE; + } + break; + default: + if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16) && (strlen(hex4)==16)) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", + tcpdatabuf, hex1, hex2, hex3, hex4); + isDataHandled=TRUE; + } + } + memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); + } + /* + * If there is data in the packet handle it here. + * + * The data header line will have the "Data . . " identifier, subsequent lines don't + * Check to ensure we haven't already captured and used this data block already above + */ + num_items_scanned = + sscanf (data + 26, "%*[ \n\t]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]%16[A-F0-9]", + hex1, hex2, hex3, hex4); + if ((num_items_scanned > 0) && (isDataHandled==FALSE)) + { + isDATA = TRUE; + /* + * Scan the data line for data blocks, depending on the number of blocks scanned + * add them along with current tcpdata buffer to the work buffer and then copy + * work buffer to tcpdata buffer to continue building up tcpdata buffer to contain + * a single hex string. + */ + switch (num_items_scanned) + { + case 1: + if (strlen(hex1)==16) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s", tcpdatabuf, + hex1); + } + break; + case 2: + if ((strlen(hex1)==16) && (strlen(hex2)==16)) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s", + tcpdatabuf, hex1, hex2); + } + break; + case 3: + if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16)) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", + tcpdatabuf, hex1, hex2, hex3); + } + break; + default: + if ((strlen(hex1)==16) && (strlen(hex2)==16) && (strlen(hex3)==16) && (strlen(hex4)==16)) + { + g_snprintf (workbuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", + tcpdatabuf, hex1, hex2, hex3, hex4); + } + } + memcpy (tcpdatabuf, workbuf, ISERIES_PKT_ALLOC_SIZE); + } + } /* * If we see the identifier for the next packet then rewind and set * isCurrentPacket FALSE */ - ascii_strup_inplace(data); - /* If packet header found return the offset */ - num_items_scanned = - sscanf (data+78, - "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); + ascii_strup_inplace(data); + /* If packet header found return the offset */ + num_items_scanned = + sscanf (data+78, + "%*[ \n\t]ETHV2%*[ .:\n\t]TYPE%*[ .:\n\t]%4s",type); if ((num_items_scanned == 1) && pktline > 1) - { - isCurrentPacket = FALSE; - cur_off = file_tell (fh); - if (cur_off == -1) - { - /* Error. */ - *err = file_error (fh, err_info); - return -1; - } - if (file_seek (fh, cur_off - buflen, SEEK_SET, err) == -1) - { - return -1; - } - } + { + isCurrentPacket = FALSE; + cur_off = file_tell (fh); + if (cur_off == -1) + { + /* Error. */ + *err = file_error (fh, err_info); + return -1; + } + if (file_seek (fh, cur_off - buflen, SEEK_SET, err) == -1) + { + return -1; + } + } } - /* - * For a IPV4 formated trace ensure we have read at least the IP and TCP headers otherwise - * exit and pass error message to user. - */ - if ((iseries->tcp_formatted) && (iseries->ipv6_trace == FALSE)) - { - if (!IPread) - { - *err = WTAP_ERR_BAD_FILE; - *err_info = g_strdup ("iseries: IP header isn't valid"); - return -1; - } - if (!TCPread) - { - *err = WTAP_ERR_BAD_FILE; - *err_info = g_strdup ("iseries: TCP header isn't valid"); - return -1; - } - } + /* + * For a IPV4 formated trace ensure we have read at least the IP and TCP headers otherwise + * exit and pass error message to user. + */ + if ((iseries->tcp_formatted) && (iseries->ipv6_trace == FALSE)) + { + if (!IPread) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup ("iseries: IP header isn't valid"); + return -1; + } + if (!TCPread) + { + *err = WTAP_ERR_BAD_FILE; + *err_info = g_strdup ("iseries: TCP header isn't valid"); + return -1; + } + } /* * Create a buffer to hold all the ASCII Hex data and populate with all the @@ -925,23 +925,23 @@ iseries_parse_packet (wtap * wth, FILE_T fh, { /* packet contained data */ if ((iseries->tcp_formatted) && (iseries->ipv6_trace == FALSE)) - { - /* build string for formatted fields */ - g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s%s", - destmac, srcmac, type, ipheader, tcpheader, tcpdatabuf); - } + { + /* build string for formatted fields */ + g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s%s", + destmac, srcmac, type, ipheader, tcpheader, tcpdatabuf); + } else - { - /* build string for unformatted data fields and IPV6 data*/ - g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", destmac, - srcmac, type, tcpdatabuf); - } + { + /* build string for unformatted data fields and IPV6 data*/ + g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s", destmac, + srcmac, type, tcpdatabuf); + } } else { /* No data in the packet */ g_snprintf (asciibuf, ISERIES_PKT_ALLOC_SIZE, "%s%s%s%s%s", destmac, - srcmac, type, ipheader, tcpheader); + srcmac, type, ipheader, tcpheader); } /* @@ -952,15 +952,15 @@ iseries_parse_packet (wtap * wth, FILE_T fh, * read from the correct location. */ if (!iseries->ipv6_trace) - { - sscanf (asciibuf + 32, "%4x", &pkt_len); - wth->phdr.len = pkt_len + 14; - } + { + sscanf (asciibuf + 32, "%4x", &pkt_len); + wth->phdr.len = pkt_len + 14; + } else - { - sscanf (asciibuf + 36, "%4x", &pkt_len); - wth->phdr.len = pkt_len + 14; - } + { + sscanf (asciibuf + 36, "%4x", &pkt_len); + wth->phdr.len = pkt_len + 14; + } if (wth->phdr.caplen > wth->phdr.len) wth->phdr.len = wth->phdr.caplen; @@ -1001,17 +1001,17 @@ iseries_UNICODE_to_ASCII (guint8 * buf, guint bytes) for (i = 0; i < bytes; i++) { switch (buf[i]) - { - case 0xFE: - case 0xFF: - case 0x00: - break; - default: - *bufptr = buf[i]; - bufptr++; - } + { + case 0xFE: + case 0xFF: + case 0x00: + break; + default: + *bufptr = buf[i]; + bufptr++; + } if (buf[i] == 0x0A) - return i; + return i; } return i; } @@ -1036,14 +1036,14 @@ iseries_parse_hex_string (const char * ascii, guint8 * buf, int len) hexvalue = g_ascii_xdigit_value(ascii[i]); i++; if (hexvalue == -1) - return FALSE; /* not a valid hex digit */ + return FALSE; /* not a valid hex digit */ bytevalue = (guint8)(hexvalue << 4); if (i >= len) - return FALSE; /* only one hex digit of the byte is present */ + return FALSE; /* only one hex digit of the byte is present */ hexvalue = g_ascii_xdigit_value(ascii[i]); i++; if (hexvalue == -1) - return FALSE; /* not a valid hex digit */ + return FALSE; /* not a valid hex digit */ bytevalue |= (guint8) hexvalue; buf[byte] = bytevalue; byte++;