int *err_fileno)
{
int i, j;
- int files_size = in_file_count * sizeof(merge_in_file_t);
+ size_t files_size = in_file_count * sizeof(merge_in_file_t);
merge_in_file_t *files;
gint64 size;
- files = g_malloc(files_size);
+ files = (merge_in_file_t *)g_malloc(files_size);
*in_files = files;
for (i = 0; i < in_file_count; i++) {
files[i].wth = wtap_open_offline(in_file_names[i], err, err_info, FALSE);
files[i].data_offset = 0;
files[i].state = PACKET_NOT_PRESENT;
+ files[i].packet_num = 0;
if (!files[i].wth) {
/* Close the files we've already opened. */
for (j = 0; j < i; j++)
/*
* Read the next packet, in chronological order, from the set of files
* to be merged.
+ *
+ * On success, set *err to 0 and return a pointer to the merge_in_file_t
+ * for the file from which the packet was read.
+ *
+ * On a read error, set *err to the error and return a pointer to the
+ * merge_in_file_t for the file on which we got an error.
+ *
+ * On an EOF (meaning all the files are at EOF), set *err to 0 and return
+ * NULL.
*/
-wtap *
-merge_read_packet(int in_file_count, merge_in_file_t in_files[], int *err,
- gchar **err_info)
+merge_in_file_t *
+merge_read_packet(int in_file_count, merge_in_file_t in_files[],
+ int *err, gchar **err_info)
{
int i;
int ei = -1;
- struct wtap_nstime tv = {(time_t)LONG_MAX, INT_MAX};
+ struct wtap_nstime tv = { sizeof(time_t) > sizeof(int) ? LONG_MAX : INT_MAX, INT_MAX };
struct wtap_pkthdr *phdr;
/*
/* We'll need to read another packet from this file. */
in_files[ei].state = PACKET_NOT_PRESENT;
- /* Return a pointer to the wtap structure for the file with that frame. */
- return in_files[ei].wth;
+ /* Count this packet. */
+ in_files[ei].packet_num++;
+
+ /* Return the ordinal of the file from which the packet was read. */
+ return &in_files[ei];
}
/*
* Read the next packet, in file sequence order, from the set of files
* to be merged.
+ *
+ * On success, set *err to 0 and return a pointer to the merge_in_file_t
+ * for the file from which the packet was read.
+ *
+ * On a read error, set *err to the error and return a pointer to the
+ * merge_in_file_t for the file on which we got an error.
+ *
+ * On an EOF (meaning all the files are at EOF), set *err to 0 and return
+ * NULL.
*/
-wtap *
+merge_in_file_t *
merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
int *err, gchar **err_info)
{
if (*err != 0) {
/* Read error - quit immediately. */
in_files[i].state = GOT_ERROR;
- return NULL;
+ return &in_files[i];
}
/* EOF - flag this file as being at EOF, and try the next one. */
in_files[i].state = AT_EOF;
return NULL;
}
- /* Return a pointer to the wtap structure for the file with that frame. */
- return in_files[i].wth;
+ /* Return the ordinal of the file from which the packet was read. */
+ *err = 0;
+ return &in_files[i];
}