tcpdump mailing list archives
Re: about packet capture
From: Erik de Castro Lopo <erikd+tcpdump () sensorynetworks com>
Date: Tue, 3 Feb 2004 16:00:43 +1100
On Tue, 3 Feb 2004 15:44:41 +1100 (EST) Tao Peng <taop () ee mu oz au> wrote:
Dear All,
I am a rookie to network programming, and I am having troubles of compling
a single code.
The code is as follows:
******************************************************
#include <stdio.h>
#include <pcap.h>
int main()
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
printf("Device: %s\n", dev);
return(0);
}
******************************************************
when I complie it using gcc, it gives me an error as follows:
/var/tmp//cc95eETb.o: In function `main':
/var/tmp//cc95eETb.o(.text+0x1e): undefined reference to `pcap_lookupdev'
This is a linker message not a compiler message (you can tell from the /var/tmp//*.o). That means that the compiler had no problem with the C code, but that the linker was not able to find the object file that defined 'pcap_lookupdev'.
But I had my pcap.h included, and I don't know why. Can anyone help me about this?
You were probably doing something like:
gcc program.c -o program
What you need is:
gcc program.c -lpcap -o program
The "-lpcap" tells gcc to tell the linker to link to libpcap. If libpcap
is installed in a non-standard location you might need to do something
like this:
gcc procgram.c -L/some/path -lpcap -o program
HTH,
Erik
--
------------------------------------------------------
[N] Erik de Castro Lopo, Senior Computer Engineer
[E] erik.de.castro.lopo () sensorynetworks com
[W] http://www.sensorynetworks.com
[T] +61 2 83022726
[F] +61 2 94750316
[A] L4/140 William St, East Sydney NSW 2011, Australia
------------------------------------------------------
-
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:
- about packet capture Tao Peng (Feb 02)
- Re: about packet capture Erik de Castro Lopo (Feb 02)
- Re: about packet capture Tao Peng (Feb 03)
- Re: about packet capture Erik de Castro Lopo (Feb 02)
