Search code examples
cwiresharkpcaplibpcapepoch

time difference in microseconds


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.


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.