Commit cbcef1e2 authored by Arne Øslebø's avatar Arne Øslebø
Browse files

improved timestamp conversion

git-svn-id: file:///home/svn/mapi/trunk@797 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 2b637217
......@@ -166,8 +166,8 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in
mhdr.caplen = rec->caplen;
mhdr.ifindex = 0;
mhdr.wlen = rec->len;
mhdr.ts = (((unsigned long long)rec->ts.tv_sec)<<32)+((rec->ts.tv_usec*4295) & 0xffffffff);
//TODO: Need to check accuracy of timestamp. Rounding errors?
mhdr.ts = (((unsigned long long)rec->ts.tv_sec)<<32)+(((rec->ts.tv_usec << 12) + (rec->ts.tv_usec<<8) - ((rec->ts.tv_usec*1825)>>5)) & 0xffffffff);
// increase counter for packets seen so far
i->hwinfo.pkts++;
......@@ -312,8 +312,8 @@ mapidrv_proc_loop (int devid)
// This is only for backward compatibility
mhdr.caplen = phdr.caplen;
mhdr.wlen = phdr.len;
mhdr.ts = (((unsigned long long)phdr.ts.tv_sec)<<32)+((phdr.ts.tv_usec*4295) & 0xffffffff);
// mhdr.ts = (((unsigned long long)phdr.ts.tv_sec)<<32)+((phdr.ts.tv_usec*4295) & 0xffffffff);
mhdr.ts = (((unsigned long long)phdr.ts.tv_sec)<<32)+((((phdr.ts.tv_usec << 12) + (phdr.ts.tv_usec<<8) - ((phdr.ts.tv_usec*1825)>>5))) & 0xffffffff);
// increase counter for packets seen so far
i->hwinfo.pkts++;
......
......@@ -95,6 +95,7 @@ static int to_tcpdump_process(mapidflib_function_instance_t *instance,MAPI_UNUSE
struct pcap_pkthdr phdr;
struct to_tcpdump_data *i=instance->internal_data;
int *res=instance->result.data;
unsigned long long ts;
if(i->pkts >= i->maxpkts && i->maxpkts!=0) {
*res=0;
......@@ -103,8 +104,16 @@ static int to_tcpdump_process(mapidflib_function_instance_t *instance,MAPI_UNUSE
phdr.caplen=pkthdr->caplen;
phdr.len=pkthdr->wlen;
phdr.ts.tv_sec=pkthdr->ts >> 32;
phdr.ts.tv_usec=(pkthdr->ts & 0xffffffff) / 4295;
ts=pkthdr->ts;
phdr.ts.tv_sec = (long)(ts >> 32);
ts = ((ts & 0xffffffffULL) * 1000 * 1000);
ts += (ts & 0x80000000ULL) << 1; /* rounding */
phdr.ts.tv_usec = (long)(ts >> 32);
if(phdr.ts.tv_usec >= 1000000) {
phdr.ts.tv_usec -= 1000000;
phdr.ts.tv_sec += 1;
}
write(i->file,&phdr,sizeof(struct pcap_pkthdr));
write(i->file,link_pkt,pkthdr->caplen);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment