diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-05-23 14:03:42 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-05-23 21:04:06 +0000 |
commit | f635efb6a63e10c03713cfae75490dda7cd1092e (patch) | |
tree | 4bc91c54e68ab5b2e8943b50d3de16eaba8344a0 /editcap.c | |
parent | 285405a0d754d14cd276b83227a55d504b3cda82 (diff) | |
download | wireshark-f635efb6a63e10c03713cfae75490dda7cd1092e.tar.gz |
More checks for the presence of a time stamp.
And make sure we have a pointer to the struct wtap_pkthdr for the packet
before we check it for a time stamp.
Change-Id: I26b205e5467a3a1236e9fd1f7633e86ece5e9040
Reviewed-on: https://code.wireshark.org/review/1762
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'editcap.c')
-rw-r--r-- | editcap.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -192,17 +192,20 @@ abs_time_to_str_with_sec_resolution(const nstime_t *abs_time) } static gchar * -fileset_get_filename_by_pattern(guint idx, const nstime_t *time_val, +fileset_get_filename_by_pattern(guint idx, const struct wtap_pkthdr *phdr, gchar *fprefix, gchar *fsuffix) { gchar filenum[5+1]; gchar *timestr; gchar *abs_str; - timestr = abs_time_to_str_with_sec_resolution(time_val); g_snprintf(filenum, sizeof(filenum), "%05u", idx % RINGBUFFER_MAX_NUM_FILES); - abs_str = g_strconcat(fprefix, "_", filenum, "_", timestr, fsuffix, NULL); - g_free(timestr); + if (phdr->presence_flags & WTAP_HAS_TS) { + timestr = abs_time_to_str_with_sec_resolution(&phdr->ts); + abs_str = g_strconcat(fprefix, "_", filenum, "_", timestr, fsuffix, NULL); + g_free(timestr); + } else + abs_str = g_strconcat(fprefix, "_", filenum, fsuffix, NULL); return abs_str; } @@ -1186,12 +1189,14 @@ main(int argc, char *argv[]) while (wtap_read(wth, &err, &err_info, &data_offset)) { read_count++; + phdr = wtap_phdr(wth); + if (read_count == 1) { /* the first packet */ if (split_packet_count > 0 || secs_per_block > 0) { if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix)) exit(2); - filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); + filename = fileset_get_filename_by_pattern(block_cnt++, phdr, fprefix, fsuffix); } else { filename = g_strdup(argv[optind+1]); } @@ -1213,7 +1218,6 @@ main(int argc, char *argv[]) } } - phdr = wtap_phdr(wth); buf = wtap_buf_ptr(wth); /* @@ -1238,7 +1242,7 @@ main(int argc, char *argv[]) } block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */ g_free(filename); - filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); + filename = fileset_get_filename_by_pattern(block_cnt++, phdr, fprefix, fsuffix); g_assert(filename); if (verbose) @@ -1267,7 +1271,7 @@ main(int argc, char *argv[]) } g_free(filename); - filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix); + filename = fileset_get_filename_by_pattern(block_cnt++, phdr, fprefix, fsuffix); g_assert(filename); if (verbose) |