Results 1 to 3 of 3

Thread: Generate time stamp like pcap

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2019

    Generate time stamp like pcap


    I am trying to generate a time stamp in the same format as winPcap does which is:

    seconds = number of seconds since 1/1/1970
    uSeconds = number of uSecs since seconds

    I THINK I tracked down in the WinPcap source how it does this but I am a bit lost converting the c++ to VB

    I know to use GetSystemTimeAsFileTime & QueryPerformanceFrequency instead of the ke calls below and I understand that they are adding back the number of seconds between 1/1/1601 and 1/1/1970 (thats 11644473600) but I am getting lost on the Systemtime.Quadpart bit and then what they are doing with the current value of the performance counter returned by KeQueryPerformanceCounter

    Any ideas on how to convert the below code? I did search the forum. My c++ is not strong.


    // struct timeval *start = (struct timeval*)Data;

    struct timeval tmp;
    LARGE_INTEGER SystemTime;
    ULONG tmp2;
    LARGE_INTEGER TimeFreq,PTime;

    // get the absolute value of the system boot time.

    PTime = KeQueryPerformanceCounter(&TimeFreq);

    start->tv_sec = (LONG)(SystemTime.QuadPart/10000000-11644473600);

    start->tv_usec = (LONG)((SystemTime.QuadPart%10000000)/10);

    start->tv_sec -= (ULONG)(PTime.QuadPart/TimeFreq.QuadPart);

    start->tv_usec -= (LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);

    if (start->tv_usec < 0)
    start->tv_sec --;
    start->tv_usec += 1000000;

    Link to full c++ source

    Last edited by vbwins; Aug 13th, 2019 at 05:13 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Mar 2019

    Re: Generate time stamp like pcap

    Came up with a solution. Will post it tomorrow. Might help someone else.

  3. #3
    Join Date
    Dec 2004

    Re: Generate time stamp like pcap

    you could try like
    seconds = DateDiff("s", "01/01/1970", Now)
    usecs = DateDiff("s", "01/01/1970", Now) - seconds
    or if you want the number of seconds to be to a more precise value
    secs = DateDiff("s", "01/01/1970", Date) + Timer
    usecs = DateDiff("s", "01/01/1970", Date) + Timer - secs
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width