2 * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
3 * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino, CACE Technologies
16 * nor the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 main(int argc
, char **argv
)
43 pcap_if_t
*alldevs
, *d
;
46 char errbuf
[PCAP_ERRBUF_SIZE
];
48 struct pcap_pkthdr
*header
;
49 const u_char
*pkt_data
;
50 struct pcap_pkthdr old
;
55 printf("\nThis program tests the WinPcap kernel driver on SMP machines.\n");
56 printf("The program tests that timestamps on the captured packets are consistent,\n");
57 printf("and that the caplen is equal to the packet length.\n");
58 printf("If there is an error, it will print out a message saying \"Inconsistent XXX\"\n");
60 if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING
, NULL
, &alldevs
, errbuf
) == -1)
62 fprintf(stderr
,"Error in pcap_findalldevs: %s\n", errbuf
);
67 for(d
=alldevs
; d
; d
=d
->next
)
69 printf("%d. %s", ++i
, d
->name
);
71 printf(" (%s)\n", d
->description
);
73 printf(" (No description available)\n");
78 printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
82 printf("Enter the interface number (1-%d):",i
);
85 if(inum
< 1 || inum
> i
)
87 printf("\nInterface number out of range.\n");
88 /* Free the device list */
89 pcap_freealldevs(alldevs
);
93 /* Jump to the selected adapter */
94 for(d
=alldevs
, i
=0; i
< inum
-1 ;d
=d
->next
, i
++);
97 if ( (fp
= pcap_open(d
->name
, 65536, PCAP_OPENFLAG_PROMISCUOUS
, 1000, NULL
, errbuf
) ) == NULL
)
99 fprintf(stderr
,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d
->name
);
100 /* Free the device list */
101 pcap_freealldevs(alldevs
);
109 /* Read the packets */
110 while((res
= pcap_next_ex( fp
, &header
, &pkt_data
)) >= 0){
115 //check that caplen is equal to packet length
116 if (header
->caplen
!=header
->len
)
117 printf("Inconsistent header: CapLen %d\t Len %d\n",header
->caplen
,header
->len
);
119 //check that timestamps always grow
120 if ( old
.ts
.tv_sec
> header
->ts
.tv_sec
|| (old
.ts
.tv_sec
== header
->ts
.tv_sec
&& old
.ts
.tv_usec
> header
->ts
.tv_usec
))
121 printf("Inconsistent Timestamps! Old was %d.%.06d - New is %d.%.06d\n",old
.ts
.tv_sec
,old
.ts
.tv_usec
, header
->ts
.tv_sec
,header
->ts
.tv_usec
);
128 printf("Error reading the packets: %s\n", pcap_geterr(fp
));