Mohammad Dadashzadeh(deleted)
|
|
Mohammad Dadashzadeh(deleted)
07/24/2009 11:09 AM
post34520
|
Dear all,
I am a beginner in using QNX. I would like to use pcap.h to capture MAC packets. I am using bellow code to read all the
network devices. Code complies without any error. However, when I want to build the project it gives me below error. I
would be very thankful if someone helps me.
Description Resource Path Location Type
make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o-g/packetcapture2_g] Error 1 packetcapture2 line 0 C/C++ Problem
make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o/packetcapture2] Error 1 packetcapture2 line 0 C/C++ Problem
packetcapture2.c: undefined reference to `pcap_findalldevs' packetcapture2 line 0 C/C++ Problem
packetcapture2.c: undefined reference to `pcap_freealldevs' packetcapture2 line 0 C/C++ Problem
undefined reference to `pcap_findalldevs' packetcapture2.c packetcapture2 line 15 C/C++ Problem
undefined reference to `pcap_freealldevs' packetcapture2.c packetcapture2 line 38 C/C++ Problem
My code
#include <stdlib.h>
#include <stdio.h>
#include "pcap.h"
int main(int argc, char *argv[]) {
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
printf("Welcome to the QNX Momentics IDE\n");
/* Retrieve the device list from the local machine */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
/* Print the list */
for(d= alldevs; d != NULL; 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;
}
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
return EXIT_SUCCESS;
}
|
|
|
Sean Boudreau(deleted)
07/24/2009 11:12 AM
post34521
|
On Fri, Jul 24, 2009 at 11:09:39AM -0400, Mohammad Dadashzadeh wrote:
> Dear all,
>
> I am a beginner in using QNX. I would like to use pcap.h to capture MAC packets. I am using bellow code to read all
the network devices. Code complies without any error. However, when I want to build the project it gives me below error
. I would be very thankful if someone helps me.
>
> Description Resource Path Location Type
> make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o-g/packetcapture2_g] Error 1 packetcapture2 line 0 C/C++
Problem
> make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o/packetcapture2] Error 1 packetcapture2 line 0 C/C++ Problem
> packetcapture2.c: undefined reference to `pcap_findalldevs' packetcapture2 line 0 C/C++ Problem
> packetcapture2.c: undefined reference to `pcap_freealldevs' packetcapture2 line 0 C/C++ Problem
> undefined reference to `pcap_findalldevs' packetcapture2.c packetcapture2 line 15 C/C++ Problem
> undefined reference to `pcap_freealldevs' packetcapture2.c packetcapture2 line 38 C/C++ Problem
You need to link against libpcap.
Regards,
-seanb
|
|
|
Andrew Boyd(deleted)
07/24/2009 11:13 AM
post34522
|
|
|
|
Mohammad Dadashzadeh(deleted)
|
|
Mohammad Dadashzadeh(deleted)
07/24/2009 11:26 AM
post34524
|
thanks for yor reply
the link does not work
Mohammad
|
|
|
Mohammad Dadashzadeh(deleted)
|
|
Mohammad Dadashzadeh(deleted)
07/24/2009 11:24 AM
post34523
|
> On Fri, Jul 24, 2009 at 11:09:39AM -0400, Mohammad Dadashzadeh wrote:
> > Dear all,
> >
> > I am a beginner in using QNX. I would like to use pcap.h to capture MAC
> packets. I am using bellow code to read all the network devices. Code complies
> without any error. However, when I want to build the project it gives me
> below error. I would be very thankful if someone helps me.
> >
> > Description Resource Path Location Type
> > make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o-g/packetcapture2_g]
> Error 1 packetcapture2 line 0 C/C++ Problem
> > make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o/packetcapture2]
> Error 1 packetcapture2 line 0 C/C++ Problem
> > packetcapture2.c: undefined reference to `pcap_findalldevs' packetcapture2
> line 0 C/C++ Problem
> > packetcapture2.c: undefined reference to `pcap_freealldevs' packetcapture2
> line 0 C/C++ Problem
> > undefined reference to `pcap_findalldevs' packetcapture2.c packetcapture2
> line 15 C/C++ Problem
> > undefined reference to `pcap_freealldevs' packetcapture2.c packetcapture2
> line 38 C/C++ Problem
>
> You need to link against libpcap.
>
> Regards,
>
> -seanb
You mean I have to add libpcap in Project\linker\Extra library\pcap
I did that it gives me more error.
Description Resource Path Location Type
undefined reference to `ether_hostton' packetcapture2 line 0 C/C++ Problem
undefined reference to `freeaddrinfo' packetcapture2 line 0 C/C++ Problem
undefined reference to `freeifaddrs' packetcapture2 line 0 C/C++ Problem
undefined reference to `getaddrinfo' packetcapture2 line 0 C/C++ Problem
undefined reference to `gethostbyname' packetcapture2 line 0 C/C++ Problem
undefined reference to `getifaddrs' packetcapture2 line 0 C/C++ Problem
undefined reference to `getnetbyname' packetcapture2 line 0 C/C++ Problem
undefined reference to `getprotobyname' packetcapture2 line 0 C/C++ Problem
undefined reference to `getservbyname' packetcapture2 line 0 C/C++ Problem
undefined reference to `ioctl_socket' packetcapture2 line 0 C/C++ Problem
undefined reference to `socket' packetcapture2 line 0 C/C++ Problem
C:/QNX641/target/qnx6/x86/usr/lib\libpcap.a(pcap-bpf.o): more undefined references to `ioctl_socket' follow
packetcapture2 line 0 C/C++ Problem
make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o-g/packetcapture2_g] Error 1 packetcapture2 line 0 C/C++ Problem
make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o/packetcapture2] Error 1 packetcapture2 line 0 C/C++ Problem
|
|
|
Sean Boudreau(deleted)
07/24/2009 11:27 AM
post34525
|
>
> You mean I have to add libpcap in Project\linker\Extra library\pcap
I guess so. However the ide lets you do it :)
>
> I did that it gives me more error.
>
>
> Description Resource Path Location Type
> undefined reference to `ether_hostton' packetcapture2 line 0 C/C++ Problem
> undefined reference to `freeaddrinfo' packetcapture2 line 0 C/C++ Problem
> undefined reference to `freeifaddrs' packetcapture2 line 0 C/C++ Problem
> undefined reference to `getaddrinfo' packetcapture2 line 0 C/C++ Problem
> undefined reference to `gethostbyname' packetcapture2 line 0 C/C++ Problem
> undefined reference to `getifaddrs' packetcapture2 line 0 C/C++ Problem
> undefined reference to `getnetbyname' packetcapture2 line 0 C/C++ Problem
> undefined reference to `getprotobyname' packetcapture2 line 0 C/C++ Problem
> undefined reference to `getservbyname' packetcapture2 line 0 C/C++ Problem
> undefined reference to `ioctl_socket' packetcapture2 line 0 C/C++ Problem
> undefined reference to `socket' packetcapture2 line 0 C/C++ Problem
> C:/QNX641/target/qnx6/x86/usr/lib\libpcap.a(pcap-bpf.o): more undefined references to `ioctl_socket' follow
packetcapture2 line 0 C/C++ Problem
> make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o-g/packetcapture2_g] Error 1 packetcapture2 line 0 C/C++
Problem
> make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o/packetcapture2] Error 1 packetcapture2 line 0 C/C++ Problem
>
These are in libsocket.
-seanb
|
|
|
Mohammad Dadashzadeh(deleted)
|
|
Mohammad Dadashzadeh(deleted)
07/24/2009 12:02 PM
post34529
|
Thak you for your help. this helped to solve the problem. Now 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() "
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);
}
|
|
|
Sean Boudreau(deleted)
07/24/2009 12:20 PM
post34532
|
Congratulations, you've now moved onto a tools issue :)
I'd check that you've compiled a debug variant and
maybe ask for help in the tools project.
Regards,
-seanb
On Fri, Jul 24, 2009 at 12:02:18PM -0400, Mohammad Dadashzadeh wrote:
> Thak you for your help. this helped to solve the problem. Now 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() "
>
>
> 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
>
|
|
|
Mohammad Dadashzadeh(deleted)
|
|
Mohammad Dadashzadeh(deleted)
07/24/2009 2:24 PM
post34549
|
I attached the project file maybe you find the problem. I also posted the problem under build section.
Regards,
Mohammad
|
|
|
Sean Boudreau(deleted)
07/24/2009 2:29 PM
post34550
|
On Fri, Jul 24, 2009 at 02:25:00PM -0400, Mohammad Dadashzadeh wrote:
> I attached the project file maybe you find the problem. I also posted the problem under build section.
This isn't really a networking issue, rather a debugging one.
IIRC you're using the ide? Maybe try in the ide group:
http://community.qnx.com/sf/projects/ide
Regards,
-seanb
|
|
|
Mohammad Dadashzadeh(deleted)
|
|
Mohammad Dadashzadeh(deleted)
07/24/2009 12:19 PM
post34531
|
> >
> > You mean I have to add libpcap in Project\linker\Extra library\pcap
>
> I guess so. However the ide lets you do it :)
>
> >
> > I did that it gives me more error.
> >
> >
> > Description Resource Path Location Type
> > undefined reference to `ether_hostton' packetcapture2 line 0 C/C++ Problem
>
> > undefined reference to `freeaddrinfo' packetcapture2 line 0 C/C++ Problem
> > undefined reference to `freeifaddrs' packetcapture2 line 0 C/C++ Problem
> > undefined reference to `getaddrinfo' packetcapture2 line 0 C/C++ Problem
> > undefined reference to `gethostbyname' packetcapture2 line 0 C/C++ Problem
>
> > undefined reference to `getifaddrs' packetcapture2 line 0 C/C++ Problem
> > undefined reference to `getnetbyname' packetcapture2 line 0 C/C++ Problem
> > undefined reference to `getprotobyname' packetcapture2 line 0 C/C++
> Problem
> > undefined reference to `getservbyname' packetcapture2 line 0 C/C++ Problem
>
> > undefined reference to `ioctl_socket' packetcapture2 line 0 C/C++ Problem
> > undefined reference to `socket' packetcapture2 line 0 C/C++ Problem
> > C:/QNX641/target/qnx6/x86/usr/lib\libpcap.a(pcap-bpf.o): more undefined
> references to `ioctl_socket' follow packetcapture2 line 0 C/C++ Problem
> > make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o-g/packetcapture2_g]
> Error 1 packetcapture2 line 0 C/C++ Problem
> > make[2]: *** [C:/ide-4.6-workspace/packetcapture2/x86/o/packetcapture2]
> Error 1 packetcapture2 line 0 C/C++ Problem
> >
>
> These are in libsocket.
>
> -seanb
Re: using pcap.h
Thak you for your help. this helped to solve the problem. Now 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() "
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);
/*...
View Full Message
|
|
|
|