pynetwork / pypcap

pypcap - python libpcap module, forked from code.google.com/p/pypcap
Other
299 stars 74 forks source link

Compile Errors on OSX with libpcap 1.7.4 #17

Closed brifordwylie closed 8 years ago

brifordwylie commented 8 years ago
python setup.py develop
Found pcap headers in /usr/local/Cellar/libpcap/1.7.4/include/pcap.h
Found libraries in /usr/lib/libpcap.dylib
...
clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -I/usr/local/Cellar/libpcap/1.7.4/include -I/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c pcap_ex.c -o build/temp.macosx-10.10-x86_64-2.7/pcap_ex.o
pcap_ex.c:165:16: error: incomplete definition of type 'struct pcap'
        FILE *f = pcap->sf.rfile;
                  ~~~~^
/usr/local/Cellar/libpcap/1.7.4/include/pcap/pcap.h:79:16: note: forward declaration of 'struct pcap'
typedef struct pcap pcap_t;
               ^
pcap_ex.c:263:12: error: incomplete definition of type 'struct pcap'
                        if (pcap->sf.rfile != NULL)
                            ~~~~^
/usr/local/Cellar/libpcap/1.7.4/include/pcap/pcap.h:79:16: note: forward declaration of 'struct pcap'
typedef struct pcap pcap_t;
               ^
2 errors generated.
error: command 'clang' failed with exit status 1`
hellais commented 8 years ago

I checked and it seems like libpcap 1.7.4 does indeed have the pcap_file function.

From the looks of the output of the setup.py it is finding the pcap.h header inside of include/pcap.h as opposed to include/pcap/pcap.h. The former header is only a wrapper around the inclusion of the actual pcap.h header located in pcap/pcap.h, which means that when we look inside of it for the pcap_file function we don't find it and end up not defining HAVE_PCAP_FILE.

How are you running the setup.py script? In theory it shouldn't be looking inside of /usr/local/Cellar unless you have it inside of your sys.prefix.

If we want to support looking for the headers in there too some reworking of the setup.py is needed to give priority to the header in pcap/pcap.h.

guyharris commented 8 years ago

I checked and it seems like libpcap 1.7.4 does indeed have the pcap_file function.

pcap_file dates back at least as far as libpcap 0.4, so you probably don't even need to check for it, unless you want to be able to support versions of libpcap prior to a version released in July 1998.

The former header is only a wrapper around the inclusion of the actual pcap.h header located in pcap/pcap.h, which means that when we look inside of it for the pcap_file function we don't find it and end up not defining HAVE_PCAP_FILE.

Yes - do not rely on pcap.h in the top-level include directory being the include file declaring the functions. We created the pcap directory to hold additional libpcap header files, and put pcap.h there, with a top-level pcap.h file left for source compatibility (unlike, for example, some versions of Red Hat, which moved it and didn't leave behind anything for source compatibility).

brifordwylie commented 8 years ago

@hellais so I finally got a chance to revisit this. So it's been a while but I think I was running into issue #20, and then installed libpcap 1.7.4 (installed with brew) so the setup.py found that version. After fully removing the brew installed libpcap, and fixing the issue with #20 (see that ticket for more info). Everything is working once again.

Now having said that @guyharris does seem to have some good observations about the possibly outdated logic in setup.py. @guyharris would you mind posting a PR with changes? I'd like to keep this ticket open until we address his comments.

guyharris commented 8 years ago

I've created a pull request #22 for changes to remove the test for pcap_file().

As for finding pcap.h, it appears that the current code searches recursively for them (pcap_h = recursive_search_dirs(search_dirs, ['pcap.h'])), and, at least in my test on OS X, it found it in pcap/pcap.h ("Found pcap headers in /usr/include/pcap/pcap.h"), so that problem appears to be fixed.