6 int main(int argc
, char **argv
)
9 char errbuf
[PCAP_ERRBUF_SIZE
];
10 struct pcap_pkthdr
*header
;
11 const u_char
*pkt_data
;
17 printf("usage: %s filename", argv
[0]);
22 /* Open the capture file */
23 if ((fp
= pcap_open_offline(argv
[1], // name of the device
24 errbuf
// error buffer
27 fprintf(stderr
,"\nUnable to open the file %s.\n", argv
[1]);
31 /* Retrieve the packets from the file */
32 while((res
= pcap_next_ex(fp
, &header
, &pkt_data
)) >= 0)
34 /* print pkt timestamp and pkt len */
35 printf("%ld:%ld (%ld)\n", header
->ts
.tv_sec
, header
->ts
.tv_usec
, header
->len
);
37 /* Print the packet */
38 for (i
=1; (i
< header
->caplen
+ 1 ) ; i
++)
40 printf("%.2x ", pkt_data
[i
-1]);
41 if ( (i
% LINE_LEN
) == 0) printf("\n");
50 printf("Error reading the packets: %s\n", pcap_geterr(fp
));