tcpdump mailing list archives

Re: problem with including pcap.h


From: Guy Harris <guy () netapp com>
Date: Tue, 11 Mar 2003 11:19:08 -0800

On Tue, Mar 11, 2003 at 11:25:31AM -0500, Marc-André Breton wrote:
Hi all,

I am a new pcap worker and I have some problems to include pcap.h in my c++ 
program. I am working on a Linux - Red Hat 7.3 machine

I'm sorry to hear that.  You have my sympathy.

with libpcap-0.6.2-12 
and my compiler is gcc-2.96-110. I had two problems:

Firts, when I want to include pcap.h, I had the following error:

#include <pcap.h>
main.cpp:24:18: pcap.h: No such file or directory

Somebody at Red Hat had the bright idea that libpcap's header files
really belong in their own subdirectory.

They're correct - they do.

Unfortunately, the people at Lawrence Berkeley Laboratory didn't put
them in a "pcap" subdirectory, so it's too late to fix that problem, as
doing so would cause source-code incompatibility.

Equally unfortunately, that person at Red Hat didn't let that stop them.

Both the current version of tcpdump, and Ethereal, handle this by having
their configuration files check whether "pcap.h" is in a "pcap"
subdirectory of "/usr/local/include" or "/usr/include" and, if so,
adding a "-I/usr/local/include/pcap" or "-I/usr/include/pcap" flag to
the compile, so that they can just include <pcap.h>.

Now I have the following error:
In file included from main.cpp:24:
/usr/include/pcap/pcap.h:42:21: net/bpf.h: No such file or directory

The Red Hat people also cleverly installed "net/bpf.h" under
"/usr/include/pcap".  A "-I/usr/include/pcap" flag would handle that
problem as well.

So I decided to copy the folder /usr/include/pcap in my project and errors for 
the include seems gone but now I have the following errors:

g++ -DHAVE_CONFIG_H -I. -I. -I.. -O2 -O0 -g3 -Wall -fno-exceptions 
-fno-check-new -c main.cpp 
In file included from main.cpp:24: 
net/bpf.h:369: previous declaration of `u_int bpf_filter (bpf_insn *, 
u_char *, unsigned int, unsigned int)' with C++ linkage 
pcap.h:169: conflicts with new declaration with C linkage 
net/bpf.h:368: previous declaration of `int bpf_validate (bpf_insn *, 
int)' with C++ linkage 
pcap.h:170: conflicts with new declaration with C linkage 
gmake: *** [main.o] Error 1 
*** failed ***

Unfortunately, older versions of the libpcap header files didn't have

        #ifdef __cplusplus
        extern "C" {
        #endif

                ...

        #ifdef __cplusplus
        }
        #endif

around the declarations in the header files, so they can't be used with
C++.

Is there someone who know what can I do for it??

You might try downloading libpcap from tcpdump.org - get the current CVS
version - and compiling and installing that.  Then, when compiling and
linking your program, use

        -I/usr/local/include

and

        -L/usr/local/lib

as libpcap from tcpdump.org will, by default, be installed in
"/usr/local/include" and "/usr/local/lib".

You will also not need "-I/usr/local/include/pcap" or
"-I/usr/include/pcap", as tcpdump.org's libpcap doesn't include that
particular Red Hat "improvement".
-
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: