[Winpcap-users] Code for unhandled exceptation error

Golnaz Honarpisheh golak_h at yahoo.com
Fri Apr 18 19:37:39 GMT 2008


Here is my code,However i think problem is not from code because even when i make it short to open only the file i will get same error.Another thing is that evrytime i open my file in a project i have to go to project menu and settings to set manually the wincap.lib ,in this way there is no error in buil process but in run time i will get myfilename.exe error and in reports shows that message;unhandled exceptation

#include "pcap.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define LINE_LEN 16
void find_device(pcap_if_t **all_devices);
 main(int argc, char **argv) {
        int res,i=0;
  struct pcap{};
        char errbuf[PCAP_ERRBUF_SIZE];    /* Error string */
        
  struct pcap_pkthdr *header; /* The header that pcap gives us */
  struct pcap_pkthdr *pcap_header;
  const u_char *packet;  /* The actual packet */
  pcap_t *handle;   /* Session handle */
        char error[PCAP_ERRBUF_SIZE];
        FILE *capfile;
        char *capture_file;
  char *pkt_data;
        int caplen;
         
         pcap_t *pcap_open_offline(char *scapturefile,char *errbuf);
          
    /* Grab a packet
        int code  = pcap_next_ex(handle,&header,&packet);
        if (code < 0)
                cout << "Error in pcap_next_ex\n";
        /* Print its length
        cout << "length of packet is" << header->len << " bytes\n"; 
        printf("%ld: \n", header->len);

        /* And close the session 
        pcap_close(handle);
        return(0); */
  /* Retrieve the packets from the file */
    while((res = pcap_next_ex( handle, &header, &packet)) >= 0){
        /* print pkt timestamp and pkt len */
        printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);          
        
        /* Print the packet */
        for (i=1; (i < header->caplen + 1 ) ; i++)
        {
            printf("%.2x ", pkt_data[i-1]);
            if ( (i % LINE_LEN) == 0) printf("\n");
        }        
        printf("\n\n");     
    }    
    if(res == -1){
        printf("Error reading the packets: %s\n", pcap_geterr(handle));
    }
    
    return 0;
}
       


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20080418/29edd1d3/attachment.htm


More information about the Winpcap-users mailing list