int iseries_open (wtap * wth, int *err, gchar ** err_info) { int bytes_read; gint offset; char magic[ISERIES_LINE_LENGTH]; char unicodemagic[] = { '\x43', '\x00', '\x4F', '\x00', '\x4D', '\x00', '\x4D', '\x00', '\x55', '\x00', '\x4E', '\x00', '\x49', '\x00', '\x43', '\x00', '\x41' }; /* * Check that file starts with a valid iSeries COMMS TRACE header * by scanning for it in the first line */ errno = WTAP_ERR_CANT_READ; bytes_read = file_read (&magic, sizeof magic, wth->fh); if (bytes_read != sizeof magic) { *err = file_error (wth->fh, err_info); if (*err != 0 && *err != WTAP_ERR_SHORT_READ) return -1; return 0; } /* * Check if this is a UNICODE formatted file by scanning for the magic string */ offset=0; while ((unsigned)offset < (ISERIES_LINE_LENGTH - (sizeof unicodemagic))) { if (memcmp (magic + offset, unicodemagic, sizeof unicodemagic) == 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->file_encap = WTAP_ENCAP_ETHERNET; wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_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->file_encap = WTAP_ENCAP_ETHERNET; wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_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; }
/* * XXX - it would probably be cleaner to use a UCS-2 flavor of file_gets(), * rather than file_gets(), if we're reading a UCS-2 file. */ wtap_open_return_val iseries_open (wtap * wth, int *err, gchar ** err_info) { gint offset; char magic[ISERIES_LINE_LENGTH]; /* * Check that file starts with a valid iSeries COMMS TRACE header * by scanning for it in the first line */ if (!wtap_read_bytes (wth->fh, &magic, sizeof magic, err, err_info)) { if (*err != WTAP_ERR_SHORT_READ) return WTAP_OPEN_ERROR; return WTAP_OPEN_NOT_MINE; } /* * Check if this is a little-endian UCS-2 Unicode formatted file by scanning * for the magic string */ offset=0; while ((unsigned int)offset < (ISERIES_LINE_LENGTH - (sizeof iseries_hdr_magic_le_ucs_2))) { if (memcmp (magic + offset, iseries_hdr_magic_le_ucs_2, sizeof iseries_hdr_magic_le_ucs_2) == 0) { if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) { return WTAP_OPEN_ERROR; } /* * 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 WTAP_OPEN_NOT_MINE; else return WTAP_OPEN_ERROR; } wth->file_encap = WTAP_ENCAP_ETHERNET; wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ISERIES; wth->snapshot_length = 0; wth->subtype_read = iseries_read; wth->subtype_seek_read = iseries_seek_read; wth->file_tsprec = WTAP_TSPREC_USEC; if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) { return WTAP_OPEN_ERROR; } return WTAP_OPEN_MINE; } offset += 1; } /* * Check if this is a ASCII formatted file by scanning for the magic string */ offset=0; while ((unsigned int)offset < (ISERIES_LINE_LENGTH - sizeof iseries_hdr_magic_ascii)) { if (memcmp (magic + offset, iseries_hdr_magic_ascii, sizeof iseries_hdr_magic_ascii) == 0) { if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) { return WTAP_OPEN_ERROR; } /* * 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 WTAP_OPEN_NOT_MINE; else return WTAP_OPEN_ERROR; } wth->file_encap = WTAP_ENCAP_ETHERNET; wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_ISERIES; wth->snapshot_length = 0; wth->subtype_read = iseries_read; wth->subtype_seek_read = iseries_seek_read; wth->file_tsprec = WTAP_TSPREC_USEC; if (file_seek (wth->fh, 0, SEEK_SET, err) == -1) { return WTAP_OPEN_ERROR; } return WTAP_OPEN_MINE; } offset += 1; } /* Neither ASCII or UNICODE so not supported */ return WTAP_OPEN_NOT_MINE; }