tcpdump mailing list archives
small program compile failed when using pcap, "undefined reference to `pcap_set"
From: "Arthur Chen" <iamarthur60 () hotmail com>
Date: Thu, 27 Nov 2003 23:00:02 +0000
this small trying program can not compile, It said undefined reference to `pcap_set_datalink', but this function prototype was included in pcap.h and was implemented in pcap.c! Any idea?
This is the error message: [root@ arthur]# gcc -lpcap -o pcap_test.o pcap_test.c /tmp/ccViVFVU.o(.text+0xbb): In function `main': : undefined reference to `pcap_set_datalink' collect2: ld returned 1 exit status [root@ arthur]# the source file is: #include <stdio.h> #include <pcap.h> //#include <pcap_int.h> extern int pcap_set_datalink(pcap_t *, int); int main() { pcap_t *handle; /* Session handle */ // char *dev; /* The device to sniff on */ char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */ struct bpf_program filter; /* The compiled filter */ // char filter_app[] = "port 23"; /* The filter expression */ char filter_app[] = "ether[11]=0xcb || (ether[5]=0xcb)"; bpf_u_int32 mask; /* Our netmask */ bpf_u_int32 net; /* Our IP */struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */ /* Define the device */ // dev = pcap_lookupdev(errbuf); char dev[]="eth0"; int errCode=0; bpf_u_int32 counter=0; printf("the dev=%s\n",dev); /* Find the properties for the device */ pcap_lookupnet(dev, &net, &mask, errbuf); /* Open the session in promiscuous mode */ handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf); //printf("The data link is %d",(pcap_datalink(handle))); pcap_set_datalink(handle, DLT_PPP_ETHER); if (errCode) printf("Set data link failed, error code=%d",errCode); else printf("Set data link succeeded, "); /* Compile and apply the filter */ // pcap_compile(handle, &filter, filter_app, 0, net); pcap_compile(handle, &filter, filter_app, 0, net); pcap_setfilter(handle, &filter); /* Grab a packet */ packet = pcap_next(handle, &header); /* Print its length */ printf("Jacked a packet with length of [%d]\n", header.len); /* And close the session */ for (; counter<header.len; counter++) printf("%3x", *(packet+counter)); pcap_close(handle); return(0); } _________________________________________________________________Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail
- This is the TCPDUMP workers list. It is archived at http://www.tcpdump.org/lists/workers/index.html To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe
Current thread:
- small program compile failed when using pcap, "undefined reference to `pcap_set" Arthur Chen (Nov 27)