summaryrefslogtreecommitdiff
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-04-20 00:13:55 -0700
committerGuy Harris <guy@alum.mit.edu>2015-04-21 02:05:03 +0000
commit5ca5704b62c3d8744f8caca7ad28f18a0707cb3d (patch)
tree4787f9a902641453801f627b278b8222281f91ef /wiretap
parent31c21be8df49d2348b282c3415e840544560cd11 (diff)
downloadwireshark-5ca5704b62c3d8744f8caca7ad28f18a0707cb3d.tar.gz
Simplify the calculation of the time stamp.
The time is calculated based on a 32-bit "seconds since the Epoch" value for the start time and a 32-bit delta from that time, in milliseconds. We can just split that delta into seconds and milliseconds, add the seconds to the start time to get the seconds part of the time stamp, and multiply the milliseconds by 1,000,000 to get the nanoseconds part of the time stamp. The only 64-bit arithmetic needed is adding the seconds to a 64-bit version of the start time (just in case seconds+start time goes past Y2.038K). Change-Id: Id7c4c6255870627f81fc99dae919abaf47efc710 Reviewed-on: https://code.wireshark.org/review/8132 Reviewed-by: Guy Harris <guy@alum.mit.edu> (cherry picked from commit ff4ca0adb9b9d5d03cb2d8a43b19c003267fc5fc) Reviewed-on: https://code.wireshark.org/review/8155
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/visual.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/wiretap/visual.c b/wiretap/visual.c
index 3c75a73af8..c9ff7887d8 100644
--- a/wiretap/visual.c
+++ b/wiretap/visual.c
@@ -142,14 +142,14 @@ struct visual_read_info
{
guint32 num_pkts; /* Number of pkts in the file */
guint32 current_pkt; /* Next packet to be read */
- guint64 start_time; /* Capture start time in microseconds */
+ guint32 start_time; /* Capture start time in seconds */
};
/* Additional information for writing Visual files */
struct visual_write_info
{
- guint start_time; /* Capture start time in seconds */
+ guint start_time; /* Capture start time in seconds */
int index_table_index; /* Index of the next index entry */
int index_table_size; /* Allocated size of the index table */
guint32 * index_table; /* File offsets for the packets */
@@ -270,7 +270,7 @@ int visual_open(wtap *wth, int *err, gchar **err_info)
visual = (struct visual_read_info *)g_malloc(sizeof(struct visual_read_info));
wth->priv = (void *)visual;
visual->num_pkts = pletoh32(&vfile_hdr.num_pkts);
- visual->start_time = ((guint64) pletoh32(&vfile_hdr.start_time)) * 1000000;
+ visual->start_time = pletoh32(&vfile_hdr.start_time);
visual->current_pkt = 1;
return 1;
@@ -328,9 +328,7 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
int bytes_read;
guint32 packet_size;
struct visual_atm_hdr vatm_hdr;
- guint64 t;
- time_t secs;
- guint32 usecs;
+ guint32 relmsecs;
guint32 packet_status;
guint8 *pd;
@@ -354,12 +352,9 @@ visual_read_packet(wtap *wth, FILE_T fh, struct wtap_pkthdr *phdr,
phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
/* Set the packet time and length. */
- t = visual->start_time;
- t += ((guint64)pletoh32(&vpkt_hdr.ts_delta))*1000;
- secs = (time_t)(t/1000000);
- usecs = (guint32)(t - secs*1000000);
- phdr->ts.secs = secs;
- phdr->ts.nsecs = usecs * 1000;
+ relmsecs = pletoh32(&vpkt_hdr.ts_delta);
+ phdr->ts.secs = (guint64)visual->start_time + relmsecs/1000;
+ phdr->ts.nsecs = (relmsecs % 1000)*1000000;
phdr->len = pletoh16(&vpkt_hdr.orig_len);