the-tcpdump-group / libpcap

the LIBpcap interface to various kernel packet capture mechanism
https://www.tcpdump.org/
Other
2.64k stars 841 forks source link

fails to compile on Solaris 11 SPARC (x86 is OK) #465

Closed infrastation closed 8 years ago

infrastation commented 8 years ago

/usr/include/net/bpf.h exists on the x86 host but does not exist on the SPARC host. No idea if this is a problem with the host itself, but in this case it would be better to detect the missing header at the configure phase.

With default compiler (gcc):

./configure && make
checking build system type... sparc-sun-solaris2.11
checking host system type... sparc-sun-solaris2.11
checking target system type... sparc-sun-solaris2.11
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for inline... inline
checking for __attribute__... yes
checking whether __attribute__((unused)) can be used without warnings... yes
checking whether __attribute__((format)) can be used without warnings... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/ggrep
checking for egrep... /usr/bin/ggrep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking sys/bitypes.h usability... no
checking sys/bitypes.h presence... no
checking for sys/bitypes.h... no
checking for int8_t... yes
checking for u_int8_t... no
checking for int16_t... yes
checking for u_int16_t... no
checking for int32_t... yes
checking for u_int32_t... no
checking for int64_t... yes
checking for u_int64_t... no
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for _LARGEFILE_SOURCE value needed for large files... no
checking sys/ioccom.h usability... yes
checking sys/ioccom.h presence... yes
checking for sys/ioccom.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/sockio.h usability... yes
checking sys/sockio.h presence... yes
checking for sys/sockio.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking linux/types.h usability... no
checking linux/types.h presence... no
checking for linux/types.h... no
checking linux/if_packet.h usability... no
checking linux/if_packet.h presence... no
checking for linux/if_packet.h... no
checking netpacket/packet.h usability... no
checking netpacket/packet.h presence... no
checking for netpacket/packet.h... no
checking netpacket/if_packet.h usability... no
checking netpacket/if_packet.h presence... no
checking for netpacket/if_packet.h... no
checking for net/pfvar.h... no
checking for netinet/if_ether.h... no
configure: Rechecking with some additional includes
checking for netinet/if_ether.h... yes
checking for ANSI ioctl definitions... yes
checking for strerror... yes
checking for strlcpy... yes
checking for vsnprintf... yes
checking for snprintf... yes
checking for library containing gethostbyname... -lnsl
checking for library containing socket... -lsocket
checking for library containing putmsg... none required
checking for ether_hostton... yes
checking whether ether_hostton is declared... yes
checking if --disable-protochain option is specified... enabled
checking packet capture type... bpf
checking net/if_media.h usability... no
checking net/if_media.h presence... no
checking for net/if_media.h... no
checking whether the system supports zerocopy BPF... no
checking for struct BPF_TIMEVAL... no
checking for getifaddrs... yes
checking ifaddrs.h usability... yes
checking ifaddrs.h presence... yes
checking for ifaddrs.h... yes
checking for socklen_t... yes
checking for getaddrinfo... yes
checking whether to build optimizer debugging code... no
checking whether to build parser debugging code... no
checking whether we have DAG API headers... no
checking whether we have Septel API headers... no
checking whether we have Myricom Sniffer API... no
checking whether TurboCap is supported... no
checking for flex... flex
checking lex output file root... lex.yy
checking lex library... -ll
checking whether yytext is a pointer... yes
checking for capable lex... yes
checking for bison... bison -y
checking for capable yacc/bison... yes
checking for ranlib... ranlib
checking for ar... ar
checking whether ln -s works... yes
checking whether the compiler fails when given an unknown warning option... yes
checking whether the compiler supports the -Wall option... yes
checking whether the compiler supports the -Wmissing-prototypes option... yes
checking whether the compiler supports the -Wstrict-prototypes option... yes
checking whether the compiler supports the -Wdeclaration-after-statement option... yes
checking whether the compiler supports generating dependencies... yes, with -M
checking if sockaddr struct has the sa_len member... no
checking if sockaddr_storage struct exists... yes
checking if dl_hp_ppa_info_t struct has dl_module_id_1 member... no
checking if unaligned accesses fail... yes
checking for USB sniffing support... no
checking whether the platform could support netfilter sniffing... no
configure: no Bluetooth sniffing support implemented for solaris2.11
configure: no canusb support implemented for solaris2.11
configure: no CAN sniffing support implemented for solaris2.11
checking for pkg-config... pkg-config
checking for D-Bus... yes
checking whether the D-Bus library defines dbus_connection_read_write... yes
configure: no hardware timestamp support implemented for solaris2.11
checking for a BSD-compatible install... /usr/bin/ginstall -c
configure: creating ./config.status
config.status: creating Makefile
config.status: creating pcap-filter.manmisc
config.status: creating pcap-linktype.manmisc
config.status: creating pcap-tstamp.manmisc
config.status: creating pcap-savefile.manfile
config.status: creating pcap.3pcap
config.status: creating pcap_compile.3pcap
config.status: creating pcap_datalink.3pcap
config.status: creating pcap_dump_open.3pcap
config.status: creating pcap_get_tstamp_precision.3pcap
config.status: creating pcap_list_datalinks.3pcap
config.status: creating pcap_list_tstamp_types.3pcap
config.status: creating pcap_open_dead.3pcap
config.status: creating pcap_open_offline.3pcap
config.status: creating pcap_set_tstamp_precision.3pcap
config.status: creating pcap_set_tstamp_type.3pcap
config.status: creating config.h
config.status: executing default-1 commands
flex -P pcap_ --header-file=scanner.h --nounput -o scanner.c scanner.l
bison -y -p pcap_ -o grammar.c -d grammar.y
grammar.y: warning: 38 shift/reduce conflicts [-Wconflicts-sr]
rm -f bpf_filter.c
ln -s ./bpf/net/bpf_filter.c bpf_filter.c
if grep GIT ./VERSION >/dev/null; then \
        read ver <./VERSION; \
        echo $ver | tr -d '\012'; \
        date +_%Y_%m_%d; \
else \
        cat ./VERSION; \
fi | sed -e 's/.*/char pcap_version[] = "&";/' > version.c
if grep GIT ./VERSION >/dev/null; then \
        read ver <./VERSION; \
        echo $ver | tr -d '\012'; \
        date +_%Y_%m_%d; \
else \
        cat ./VERSION; \
fi | sed -e 's/.*/static const char pcap_version_string[] = "libpcap version &";/' > version.h
./mkdep -c gcc -m -g -O2    -M -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -I.  -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include pcap-bpf.c       pcap-dbus.c fad-getad.c pcap.c inet.c gencode.c optimize.c nametoaddr.c etherent.c  savefile.c sf-pcap.c sf-pcap-ng.c pcap-common.c  bpf_image.c bpf_dump.c  scanner.c grammar.c bpf_filter.c version.c
pcap-bpf.c:102:21: fatal error: net/bpf.h: No such file or directory
 #include <net/bpf.h>
                     ^
compilation terminated.
gcc -fpic -Wall -Wmissing-prototypes -Wstrict-prototypes -Wdeclaration-after-statement -I.  -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -g -O2    -c ./pcap-bpf.c
./pcap-bpf.c:102:21: fatal error: net/bpf.h: No such file or directory
 #include <net/bpf.h>
                     ^
compilation terminated.
*** Error code 1
make: Fatal error: Command failed for target `pcap-bpf.o'

With Sun Studio compiler:

CC=/opt/solarisstudio12.3/bin/cc ./configure && make clean all
[...]
./mkdep -c /opt/solarisstudio12.3/bin/cc -m -g    -xM -DHAVE_CONFIG_H  -D_U_="" -I.  -I/usr/local/include -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include pcap-bpf.c       pcap-dbus.c fad-getad.c pcap.c inet.c gencode.c optimize.c nametoaddr.c etherent.c  savefile.c sf-pcap.c sf-pcap-ng.c pcap-common.c  bpf_image.c bpf_dump.c  scanner.c grammar.c bpf_filter.c version.c
pcap-bpf.c:
"pcap-bpf.c", line 102: cannot find include file: <net/bpf.h>
cc: acomp failed for pcap-bpf.c
pcap-dbus.c:
fad-getad.c:
pcap.c:
inet.c:
gencode.c:
optimize.c:
nametoaddr.c:
etherent.c:
savefile.c:
sf-pcap.c:
sf-pcap-ng.c:
pcap-common.c:
bpf_image.c:
bpf_dump.c:
scanner.c:
grammar.c:
bpf_filter.c:
version.c:
rm -f pcap-bpf.o       pcap-dbus.o fad-getad.o pcap.o inet.o gencode.o optimize.o nametoaddr.o etherent.o  savefile.o sf-pcap.o sf-pcap-ng.o pcap-common.o  bpf_image.o bpf_dump.o  scanner.o grammar.o bpf_filter.o version.o  libpcap.* capturetest  can_set_rfmon_test  filtertest  findalldevstest  opentest  selpolltest  valgrindtest  libpcap-`cat ./VERSION`.tar.gz scanner.c grammar.c bpf_filter.c version.c scanner.h grammar.h version.h  lex.yy.c pcap-config
/opt/solarisstudio12.3/bin/cc -O -Kpic -I.  -I/usr/local/include -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -DHAVE_CONFIG_H  -D_U_="" -g    -c ./pcap-bpf.c
"./pcap-bpf.c", line 102: cannot find include file: <net/bpf.h>
"./pcap-bpf.c", line 792: incomplete struct/union/enum bpf_stat: s
"./pcap-bpf.c", line 807: undefined symbol: BIOCGSTATS
"./pcap-bpf.c", line 813: undefined struct/union member: bs_recv
"./pcap-bpf.c", line 814: undefined struct/union member: bs_drop
"./pcap-bpf.c", line 990: undefined struct/union member: bh_caplen
"./pcap-bpf.c", line 991: undefined struct/union member: bh_hdrlen
"./pcap-bpf.c", line 1007: undefined struct/union member: bh_datalen
"./pcap-bpf.c", line 1010: undefined struct/union member: bh_tstamp
"./pcap-bpf.c", line 1010: warning: left operand of "." must be struct/union object
"./pcap-bpf.c", line 1018: improper member use: bh_tstamp
"./pcap-bpf.c", line 1018: warning: left operand of "." must be struct/union object
"./pcap-bpf.c", line 1018: cannot access member of non-struct/union object
"./pcap-bpf.c", line 1032: improper member use: bh_datalen
"./pcap-bpf.c", line 1493: incomplete struct/union/enum bpf_version: bv
"./pcap-bpf.c", line 1525: undefined symbol: BIOCVERSION
"./pcap-bpf.c", line 1531: undefined struct/union member: bv_major
"./pcap-bpf.c", line 1531: undefined symbol: BPF_MAJOR_VERSION
"./pcap-bpf.c", line 1532: undefined struct/union member: bv_minor
"./pcap-bpf.c", line 1532: undefined symbol: BPF_MINOR_VERSION
"./pcap-bpf.c", line 1771: undefined symbol: BIOCSBLEN
"./pcap-bpf.c", line 1787: undefined symbol: BIOCSETIF
"./pcap-bpf.c", line 1803: undefined symbol: BIOCGBLEN
"./pcap-bpf.c", line 1814: undefined symbol: BIOCSBLEN
"./pcap-bpf.c", line 1820: undefined symbol: BIOCSETIF
"./pcap-bpf.c", line 1841: undefined symbol: BIOCGDLT
"./pcap-bpf.c", line 2138: undefined symbol: BIOCSRTIMEOUT
"./pcap-bpf.c", line 2195: undefined symbol: BIOCPROMISC
"./pcap-bpf.c", line 2202: undefined symbol: BIOCGBLEN
"./pcap-bpf.c", line 2244: undefined symbol: BIOCSETF
"./pcap-bpf.c", line 2650: undefined symbol: BIOCSETF
cc: acomp failed for ./pcap-bpf.c
*** Error code 2
make: Fatal error: Command failed for target `pcap-bpf.o'
guyharris commented 8 years ago

OK, so Solaris 11, as far as I know, has BPF. Is there a bpf.h anywhere under /usr/include on the SPARC host? Perhaps either there's something wrong or incomplete with the Solaris installation on that host, or it's running a different version of Solaris 11 which moved the bpf.h header somewhere else.

infrastation commented 8 years ago

On SPARC:

/usr/include/pcap/bpf.h
/opt/csw/include/pcap/bpf.h

On x86:

/usr/include/pcap/bpf.h
/usr/include/net/bpf.h
/opt/csw/include/pcap/bpf.h
guyharris commented 8 years ago

Are they running the same version of Solaris 11? What happens if you run man bpf on both of them?

infrastation commented 8 years ago
SunOS unstable11x 5.11 11.2 i86pc i386 i86pc
SunOS unstable11s 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise
infrastation commented 8 years ago

"bpf - Berkeley Packet Filter raw network interface" from bpf(7D) on x86; no such man page on SPARC.

guyharris commented 8 years ago

Is the system/network/bpf package installed on both machines? (See the Oracle® Solaris 11.2 Package Group Lists document.)

What does ls -ld /dev/bpf* print on both machines?

infrastation commented 8 years ago

x86:

> pkg list system/network/bpf
NAME (PUBLISHER)                                  VERSION                    IFO
system/network/bpf                                0.5.11-0.175.2.8.0.1.2     i--
> ls -ld /dev/bpf*
lrwxrwxrwx   1 root     root          27 Aug 28 11:03 /dev/bpf -> ../devices/pseudo/bpf@0:bpf
> ls -l /devices/pseudo/bpf*
crw-rw-rw-   1 root     sys       53,  0 Aug 28 16:20 /devices/pseudo/bpf@0:bpf

/devices/pseudo/bpf@0:
total 0

SPARC:

> pkg list system/network/bpf
pkg list: No packages matching 'system/network/bpf' installed
> ls -ld /dev/bpf*
crw-rw-rw-   1 root     sys       16,  0 Jan 22  2015 /dev/bpf

Device major numbers are different, not sure if that matters. Is the package the only way to compile libpcap in Solaris?

guyharris commented 8 years ago

Well, that's weird. On the system with the package installed, the /dev/bpf device is a symlink to an item in the /devices tree, which I think is what most entries in /dev are on Solaris; on the other system, it's a character special file directly planted in the /dev directory.

Major device numbers are, I think, assigned dynamically, so I'm not sure that's an issue.

Is there a version of tcpdump installed, and what happens if you try to run it? There's a diagnostic/tcpdump package; is it installed on either of the machines? If not, can you install it on whatever machines don't have it installed, and try it?

If you can't get the tcpdump package installed, is there a libpcap shared library on the system in a system library directory? If so, what happens if you try to build one of the libpcap test programs, such as opentest.c, and run it?

infrastation commented 8 years ago

x86:

> pkg list | grep tcpdump
diagnostic/tcpdump                                4.7.4-0.175.2.12.0.4.0     i--
> tcpdump -h
tcpdump version 4.7.4
libpcap version 1.5.1
[...]
> tcpdump -D
>
> make opentest
> ./opentest 
opentest: (null): You don't have permission to capture on that device ((cannot open device) /dev/bpf: Permission denied)

SPARC:

> pkg list | grep tcpdump
diagnostic/tcpdump                                4.5.1-0.175.2.0.0.42.1     i--
> tcpdump -h
tcpdump version 4.5.1
libpcap version 1.5.1
[...]
> tcpdump -D
>
> gcc -D_U_="" -o opentest opentest.c -lpcap
> ./opentest 
opentest: (null): You don't have permission to capture on that device ((cannot open device) /dev/bpf: Permission denied)

Looks like I am hitting the limits of a user account.

guyharris commented 8 years ago

Same OS version, different versions of diagnostic/tcpdump? That's, umm, interesting.

Can you run either tcpdump or opentest as root? (opentest takes a -i flag to specify the interface to open. I should probably tweak it to pick a default if none was explicitly specified. I guess Sun^WOracle decided that, as everybody else's printf prints "(null)" for null-pointer arguments to %s, they should do the same thing, rather than dumping core as they used to do, legitimate though dumping core might be.)

infrastation commented 8 years ago

I can only yield to @dago to obtain that additional diagnostics on those hosts.

guyharris commented 8 years ago

I.e., this is happening on one of the OpenCSW build farm hosts, other than the ones doing the regular buildbot (Solaris 10) builds? If so, I'll ask Dagobert what's going on.

infrastation commented 8 years ago

Yes, exactly.

dago commented 8 years ago

I think the difference originates from the fact that unstable11s is a zone whereas unstable11x is the global instance. This is necessary for us as zones are the way to virtualize Sparc while we use plain VMware for x86.

The major numbers does not really matter as long as it is consistent across your horizon (usually "system", but may be "within cluster" when using NFS).

h0lzi commented 8 years ago

Hi I'm a college from @dago and checked the problem. The bpf package was not installed on the unstable11s zone. Did this know. So you have /usr/include/net/bpf.h now. The difference for /dev/bpf is that unstable11s is a zone and unstable11x is not. Anyway please check is it works now for you

infrastation commented 8 years ago

Let me confirm libpcap now builds OK on the server. Thank you.