Question

I have question about the EPOCH time.

I need to calculate the time difference between two packets. and I am not so sure how:

printf("Epoch Time: %d:%d seconds\n", header->ts.tv_sec, header->ts.tv_usec);

the first packet shows: 1396191661:164162

the second packet shows:  1396191661:164193

I need that variable u_int diff_time will contain the time difference between two packets- in microseconds. as you can see, the difference is between packet_1 and packet_2- only in the microseconds part.

how should I calculate it if the difference not only within the tv.u_sec?

thanks in advanced.

Was it helpful?

Solution

Just add the difference between seconds:

udiff = (second.tv_sec - first.tv_sec) * 1000000 + (second.tv_usec - first.tv_usec)

You just have to check that the difference between two packets is less than ~2000 seconds to stay in the size of a 32-bits int.

OTHER TIPS

Suppose you have two times t1.sec, t1.usec, t2.sec and t2.usec with t1 > t2, then I suppose you can calculate the difference by (t1.sec - t2.sec) * 1000000 + (t1.usec - t2.usec).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top