Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - No source available for "pcap_loop() " : (1 Item)
   
No source available for "pcap_loop() "  
I am using pcap_loop to capture packets. The project 
compiles and builds but during debugging when I run pcap_loop function the program stops and shows 
> 
> No source available for "pcap_loop() " 
> 
Regards,
Mohammad
> 
> my code
> 
> 
> #include <stdlib.h>
> #include <stdio.h>
> #include "pcap.h"
> 
> /* prototype of the packet handler */
> void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
> 
> int main(int argc, char *argv[]) {
> 	pcap_if_t *alldevs;
> 	pcap_if_t *d;
> 	int inum;
> 	int i=0;
> 	pcap_t *adhandle;
> 	char errbuf[PCAP_ERRBUF_SIZE];
> 
> 	    /* Retrieve the device list on the local machine */
> 	    if (pcap_findalldevs(&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);
> 	    inum=1;
> 
> 	    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 device */
> 
> 	    adhandle=pcap_open_live(d->name, 65536, 1, 20, errbuf);
> 
> 	    if (adhandle=NULL)
> 	    {
> 	        fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
> 	        /* 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 EXIT_SUCCESS;
> }
> 
> /* 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];
>     time_t local_tv_sec;
> 
>     /* convert the timestamp to readable format */
>     local_tv_sec = header->ts.tv_sec;
>     ltime=localtime(&local_tv_sec);
>     strftime( timestr, sizeof timestr, "%H:%M:%S", ltime);
> 
>     printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
> 
> }
> 
> 
> 
> 
> _______________________________________________
> 
> io-net migration
> http://community.qnx.com/sf/go/post34529
>