#include <sys/time.h>
#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
#include <string.h>
#include "wtap.h"
#include "merge.h"
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;
- struct stat statb;
+ 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++)
*err_fileno = i;
return FALSE;
}
- if (fstat(wtap_fd(files[i].wth), &statb) < 0) {
- *err = errno;
+ size = wtap_file_size(files[i].wth, err);
+ if (size == -1) {
for (j = 0; j <= i; j++)
wtap_close(files[j].wth);
*err_fileno = i;
return FALSE;
}
- files[i].size = statb.st_size;
+ files[i].size = size;
}
return TRUE;
}
* returns TRUE if first argument is earlier than second
*/
static gboolean
-is_earlier(struct timeval *l, struct timeval *r) {
- if (l->tv_sec > r->tv_sec) { /* left is later */
+is_earlier(struct wtap_nstime *l, struct wtap_nstime *r) {
+ if (l->secs > r->secs) { /* left is later */
return FALSE;
- } else if (l->tv_sec < r->tv_sec) { /* left is earlier */
+ } else if (l->secs < r->secs) { /* left is earlier */
return TRUE;
- } else if (l->tv_usec > r->tv_usec) { /* tv_sec equal, l.usec later */
+ } else if (l->nsecs > r->nsecs) { /* tv_sec equal, l.usec later */
return FALSE;
}
/* either one < two or one == two
/*
* 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 timeval tv = {LONG_MAX, LONG_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];
}