Note that there are some explanatory texts on larger screens.

plurals
  1. POcalculate time to receive/send data inorder to calculate bandwidth
    primarykey
    data
    text
    <p>I have a packet sniffer (see below). To measure bandwidth I think I need to start a timer at the beginning of receving data. Record the number of bytes that has been transmitted and then calculate the average bandwidth. To measure time time to receive/send data I did:</p> <pre><code>int main() { //usual packet sniffer staff up untill while loop struct pcap_pkthdr header; const unsigned char *packet; char errbuf[PCAP_ERRBUF_SIZE]; char *device; pcap_t *pcap_handle; int i; device = pcap_lookupdev(errbuf); if (device == NULL) perror("pcap_lookupdev failed"); printf("Sniffing on device %s\n", device); pcap_handle = pcap_open_live(device, 4096, 1, 0, errbuf); if (pcap_handle == NULL) perror("pcap_open_live failed"); while (1) { //starting the timer double diff = 0.0; time_t start; time_t stop; char buff[128]; time(&amp;start); //receiving packet packet = pcap_next(pcap_handle, &amp;header); //stopping the timer time(&amp;stop); //measuring time of receiving data diff = difftime(stop, start); process_packet(packet, header.len, diff); } } </code></pre> <p>diff turns out to always be 0.0000, which is probably wrong. Is my understanding correct, if yes, Is there any problems with code?</p> <p>I also tries using milliseconds:</p> <pre><code>float diff; clock_t start; clock_t stop; char buff[128]; start = clock(); packet = pcap_next(pcap_handle, &amp;header);//just creates a pointer in no time stop = clock(); diff = (((float)stop - (float)start) / 1000000.0F ) * 1000; </code></pre> <p>The same output...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload