WinPcap + Dev-cpp == misserfolg



  • hi,

    Ein Misserfolg nach dem Anderen...

    Ich pack es nicht winpcap in devcpp zu compilieren, ich bin völlig am verzweifeln... versuche das jetzt schon länger.

    ich habe die *.a eingebunden, header files alle in std ordner getan, dann include <pcap.h> und compile + run..

    fehlermeldung krieg ich immer:

    ---------
    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\socktest\Makefile.win"
    Executing make...
    make.exe -f "C:\Dev-Cpp\socktest\Makefile.win" all
    gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"

    In file included from C:/Dev-Cpp/include/pcap-stdinc.h:53,
    from C:/Dev-Cpp/include/pcap.h:41,
    from main.c:1:
    C:/Dev-Cpp/include/bittypes.h:36: error: redefinition of typedef 'int8_t'
    C:/Dev-Cpp/include/stdint.h:27: error: previous declaration of 'int8_t' was here
    C:/Dev-Cpp/include/bittypes.h:52: error: redefinition of typedef 'int16_t'
    C:/Dev-Cpp/include/stdint.h:29: error: previous declaration of 'int16_t' was here
    C:/Dev-Cpp/include/bittypes.h:71: error: redefinition of typedef 'int32_t'
    C:/Dev-Cpp/include/stdint.h:31: error: previous declaration of 'int32_t' was here

    make.exe: *** [main.o] Error 1

    Execution terminated
    ---------

    Die Source ist:

    #include <pcap.h>
    #include <stdio.h>
    #include <stdlib.h>
    //oder hier pcap.h ... habe beides getestet...
    
    int main(int argc, char *argv[])
    {
    
      system("PAUSE");	
      return 0;
    }
    

    Danke.. nur ihr könnt mir helfen, google half nicht. DANKEEE!!!!

    greezzZz vom winpcap-devcpp-er



  • da ist ein konflikt, wer von den beiden headern die typen deklarieren soll. die machen das beide, obwohls nur einer machen sollte.

    es gibt viele loesungen, zwei seien hier genannt:
    - deinstalliere dev-cpp und nimm dir code::blocks
    - kille die deklarationen aus dem header, der spaeter inkludiert wird



  • Also ich weiß ja nicht, ob das nen Unterschied macht. Als Compiler nutzen doch beide den MinGW, oder?

    Aaber zumindest soll code::blocks nicht so buggy sein 😉
    Ich persönlich nutze den DevCpp eigentlich nur noch zum Anschauen von code und zum Installieren von Bibliotheken, etc. Den Rest macht Eclipse(wobei mich code::blocks irgendwie stark an Eclipse erinnert ;)).



  • Hallo,

    Vielen Dank, das geht jetzt, nun musste ich aber noch #define HAVE_REMOTE am Anfang setzen.

    BITTE HELFT MIR!!! Danke!!

    Ich habe (beispielsource halt):

    #define HAVE_REMOTE
    
    #include <pcap.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    /* 4 bytes IP address */
    typedef struct ip_address{
        u_char byte1;
        u_char byte2;
        u_char byte3;
        u_char byte4;
    }ip_address;
    
    /* IPv4 header */
    typedef struct ip_header{
        u_char  ver_ihl;        // Version (4 bits) + Internet header length (4 bits)
        u_char  tos;            // Type of service
        u_short tlen;           // Total length
        u_short identification; // Identification
        u_short flags_fo;       // Flags (3 bits) + Fragment offset (13 bits)
        u_char  ttl;            // Time to live
        u_char  proto;          // Protocol
        u_short crc;            // Header checksum
        ip_address  saddr;      // Source address
        ip_address  daddr;      // Destination address
        u_int   op_pad;         // Option + Padding
    }ip_header;
    
    /* UDP header*/
    typedef struct udp_header{
        u_short sport;          // Source port
        u_short dport;          // Destination port
        u_short len;            // Datagram length
        u_short crc;            // Checksum
    }udp_header;
    
    /* prototype of the packet handler */
    void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
    
    main()
    {
    pcap_if_t *alldevs;
    pcap_if_t *d;
    int inum;
    int i=0;
    pcap_t *adhandle;
    char errbuf[PCAP_ERRBUF_SIZE];
    u_int netmask;
    char packet_filter[] = "ip and udp";
    struct bpf_program fcode;
    
        /* Retrieve the device list */
        if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
        {
            fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
            exit(1);
        }
    
        /* Print the list */
        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");
            /* Free the device list */
            pcap_freealldevs(alldevs);
            return -1;
        }
    
        /* Jump to the selected adapter */
        for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
    
        /* Open the adapter */
        if ( (adhandle= pcap_open(d->name,  // name of the device
                                 65536,     // portion of the packet to capture.
                                            // 65536 grants that the whole packet will be captured on all the MACs.
                                 PCAP_OPENFLAG_PROMISCUOUS,         // promiscuous mode
                                 1000,      // read timeout
                                 NULL,      // remote authentication
                                 errbuf     // error buffer
                                 ) ) == NULL)
        {
            fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n");
            /* Free the device list */
            pcap_freealldevs(alldevs);
            return -1;
        }
    
        /* Check the link layer. We support only Ethernet for simplicity. */
        if(pcap_datalink(adhandle) != DLT_EN10MB)
        {
            fprintf(stderr,"\nThis program works only on Ethernet networks.\n");
            /* Free the device list */
            pcap_freealldevs(alldevs);
            return -1;
        }
    
        if(d->addresses != NULL)
            /* Retrieve the mask of the first address of the interface */
            netmask=((struct sockaddr_in *)(d->addresses->netmask))->sin_addr.S_un.S_addr;
        else
            /* If the interface is without addresses we suppose to be in a C class network */
            netmask=0xffffff;
    
        //compile the filter
        if (pcap_compile(adhandle, &fcode, packet_filter, 1, netmask) <0 )
        {
            fprintf(stderr,"\nUnable to compile the packet filter. Check the syntax.\n");
            /* Free the device list */
            pcap_freealldevs(alldevs);
            return -1;
        }
    
        //set the filter
        if (pcap_setfilter(adhandle, &fcode)<0)
        {
            fprintf(stderr,"\nError setting the filter.\n");
            /* Free the device list */
            pcap_freealldevs(alldevs);
            return -1;
        }
    
        printf("\nlistening on %s...\n", d->description);
    
        /* At this point, we don't need any more the device list. Free it */
        pcap_freealldevs(alldevs);
    
        /* start the capture */
        pcap_loop(adhandle, 0, packet_handler, NULL);
    
        return 0;
    }
    
    /* Callback function invoked by libpcap for every incoming packet */
    void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
    {
        struct tm *ltime;
        char timestr[16];
        ip_header *ih;
        udp_header *uh;
        u_int ip_len;
        u_short sport,dport;
    
        /* convert the timestamp to readable format */
        ltime=localtime(&header->ts.tv_sec);
        strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);
    
        /* print timestamp and length of the packet */
        printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len);
    
        /* retireve the position of the ip header */
        ih = (ip_header *) (pkt_data +
            14); //length of ethernet header
    
        /* retireve the position of the udp header */
        ip_len = (ih->ver_ihl & 0xf) * 4;
        uh = (udp_header *) ((u_char*)ih + ip_len);
    
        /* convert from network byte order to host byte order */
        sport = ntohs( uh->sport );
        dport = ntohs( uh->dport );
    
        /* print ip addresses and udp ports */
        printf("%d.%d.%d.%d.%d -> %d.%d.%d.%d.%d\n",
            ih->saddr.byte1,
            ih->saddr.byte2,
            ih->saddr.byte3,
            ih->saddr.byte4,
            sport,
            ih->daddr.byte1,
            ih->daddr.byte2,
            ih->daddr.byte3,
            ih->daddr.byte4,
            dport);
    }
    

    und krieg:

    Project   : Console application
    Compiler  : GNU GCC Compiler (called directly)
    Directory : C:\Dokumente und Einstellungen\ichpfeiffe\Eigene Dateien\code-blocks\
    --------------------------------------------------------------------------------
    Switching to target: default
    Compiling: main.c
    Linking console executable: C:\Dokumente und Einstellungen\ichpfeiffe\Eigene Dateien\code-blocks\libpcaptest.exe
    .objs\main.o:main.c:(.text+0x433): undefined reference to `ntohs@4'
    .objs\main.o:main.c:(.text+0x449): undefined reference to `ntohs@4'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 0 seconds)
    

    obwohl ich doch alle libraries eingebunden habe.. und die include files in den selben include-ordner kopiert habe. Ist der vielleicht bescheuert...

    Danke für die Hilfe...

    greEzZZz



  • Ich denke, Dir fehlt noch die ws2_32.lib...



  • ja danke... geht jetzt echt.. aber kann ich die via pragma auch einfügen? ich habe einfach libwsock... lib eingebunden. was is cooler?


Log in to reply