(WinPcap 3.1 beta 4+VC++.net2003)
在WinPcap中的Handling offline dump files中的最后一个例子:“Writing packets to a dump file with pcap_live_dump”
编译后运行(输入sample6_4 test.cap 0 30)老是提示“Unable to start the dump, Error setting dump mode”,无法解决,望高手指点。

解决方案 »

  1.   

    为了方便分析,我将源代码贴出来:
    // sample6_4.cpp : Defines the entry point for the console application.
    #include "stdafx.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <pcap.h>
    #define error At the moment the kernel dump feature is not supported in the driver
    int _tmain(int argc, _TCHAR* argv[])
    {    
        pcap_if_t *alldevs, *d;
        pcap_t *fp;
        u_int inum, i=0;
        char errbuf[PCAP_ERRBUF_SIZE];
        printf("kdump: saves the network traffic to file using WinPcap kernel-level dump faeature.\n");
        printf("\t Usage: %s [adapter] | dump_file_name max_size max_packs\n", argv[0]);
        printf("\t Where: max_size is the maximum size that the dump file will reach (0 means no limit)\n");
        printf("\t Where: max_packs is the maximum number of packets that will be saved (0 means no limit)\n\n");
        if(argc < 5)
    {
            if (pcap_findalldevs(&alldevs, errbuf) == -1)
            {
                fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
                exit(1);
            }
            for(d=alldevs; d; d=d->next)
            {
                printf("%d. %s", ++i, d->name);
                if (d->description)
                    printf(" (%s)\n", d->description);
                else
                    printf(" (No description available)\n");
            }      
            if(i==0)
            {
                printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
                return -1;
            }     
            printf("Enter the interface number (1-%d):",i);
            scanf("%d", &inum);
            
            if(inum < 1 || inum > i)
            {
                printf("\nInterface number out of range.\n");
                return -1;
            }
            for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
            if ( (fp = pcap_open_live(d->name, 100, PCAP_OPENFLAG_PROMISCUOUS, 20, errbuf) ) == NULL)
            {
                fprintf(stderr,"\nError opening adapter\n");
                return -1;
            }
            pcap_freealldevs(alldevs);
            if(pcap_live_dump(fp, argv[1], atoi(argv[2]), atoi(argv[3]))==-1){
                printf("Unable to start the dump, %s\n", pcap_geterr(fp));
                return -1;
            }
        }
        else{
            if ( (fp= pcap_open_live(argv[1], 100, 1, 20, errbuf) ) == NULL)
            {
                fprintf(stderr,"\nError opening adapter\n");
                return -1;
            }
            if(pcap_live_dump(fp, argv[0], atoi(argv[1]), atoi(argv[2]))==-1){
                printf("Unable to start the dump, %s\n", pcap_geterr(fp));
                return -1;
            }
        }
        pcap_live_dump_ended(fp, TRUE);
        pcap_close(fp);
        return 0;
    }
      

  2.   

    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=204183参考一下
      

  3.   

    我使用pcap_dump函数就正常,但是用pcap_live_dump就不行。