Skip to content

Commit c39d40a

Browse files
committed
On Solaris, for 64-bit builds, use the 64-bit pcap-config.
There are two versions of pcap-config supplied on Solaris (or, at least, on 64-bit Solaris) - a version that has the right --libs output to find the 32-bit libraries and a version that has the right --libs output to find the 64-bit libraries. Try to figure out whether we're doing a 32-bit or 64-bit build (based on the pointer size) and, for 64-bit builds, run the 64-bit version of pcap-config.
1 parent 780f86b commit c39d40a

File tree

5 files changed

+374
-18
lines changed

5 files changed

+374
-18
lines changed

CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
3232

3333
project(tcpdump)
3434

35+
#
36+
# OK, this is a royal pain.
37+
#
38+
# CMake will try to determine the sizes of some data types, including
39+
# void *, early in the process of configuration; apparently, it's done
40+
# as part of processing the project() command.
41+
#
42+
# At least as of CMake 2.8.6, it does so by checking the size of
43+
# "void *" in C, setting CMAKE_C_SIZEOF_DATA_PTR based on that,
44+
# setting CMAKE_SIZEOF_VOID_P to that, and then checking the size
45+
# of "void *" in C++, setting CMAKE_CXX_SIZEOF_DATA_PTR based on
46+
# that, and then setting CMAKE_SIZEOF_VOID_P to *that*.
47+
#
48+
# The compile tests include whatever C flags may have been provided
49+
# to CMake in the CFLAGS and CXXFLAGS environment variables.
50+
#
51+
# If you set an architecture flag such as -m32 or -m64 in CFLAGS
52+
# but *not* in CXXFLAGS, the size for C++ will win, and hilarity
53+
# will ensue.
54+
#
55+
# Make sure CMAKE_C_SIZEOF_DATA_PTR and CMAKE_CXX_SIZEOF_DATA_PTR
56+
# have the same value, and warn if they don't.
57+
#
58+
# Yes, we have to do this even though there is currently *NO* C++
59+
# code in tcpdump....
60+
#
61+
if(NOT "${CMAKE_C_SIZEOF_DATA_PTR}" EQUAL "${CMAKE_CXX_SIZEOF_DATA_PTR}")
62+
message(FATAL_ERROR "Architecture flags must be set in both CFLAGS and CXXFLAGS")
63+
endif()
64+
3565
#
3666
# For checking if a compiler flag works and adding it if it does.
3767
#

aclocal.m4

+39-5
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,16 @@ AC_DEFUN(AC_LBL_LIBPCAP,
575575
# Found - use it to get the include flags for
576576
# libpcap and the flags to link with libpcap.
577577
#
578-
# If this is a system-supplied pcap-config, which
579-
# we define as being "a pcap-config in /usr/bin",
580-
# there are some issues. Work around them.
578+
# If this is a vendor-supplied pcap-config, which
579+
# we define as being "a pcap-config in /usr/bin
580+
# or /usr/ccs/bin" (the latter is for Solaris and
581+
# Sun/Oracle Studio), there are some issues. Work
582+
# around them.
581583
#
582-
if test "$PCAP_CONFIG" = "/usr/bin/pcap-config" ; then
584+
if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \
585+
\( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then
583586
#
584-
# It's /usr/bin/pcap-config.
587+
# It's vendor-supplied.
585588
#
586589
case "$host_os" in
587590
@@ -598,6 +601,37 @@ AC_DEFUN(AC_LBL_LIBPCAP,
598601
#
599602
_broken_apple_pcap_config=yes
600603
;;
604+
605+
solaris*)
606+
#
607+
# This is Solaris 2 or later, i.e. SunOS 5.x.
608+
#
609+
# At least on Solaris 11; there's /usr/bin/pcap-config,
610+
# which reports -L/usr/lib with --libs, causing
611+
# the 32-bit libraries to be found, and there's
612+
# /usr/bin/{64bitarch}/pcap-config, where {64bitarch}
613+
# is a name for the 64-bit version of the instruction
614+
# set, which reports -L /usr/lib/{64bitarch}, causing
615+
# the 64-bit libraries to be found.
616+
#
617+
# So if we're building 64-bit targets, we replace
618+
# PCAP_CONFIG with /usr/bin/{64bitarch}; we get
619+
# {64bitarch} as the output of "isainfo -n".
620+
#
621+
# Are we building 32-bit or 64-bit? Get the
622+
# size of void *, and check that.
623+
#
624+
AC_CHECK_SIZEOF([void *])
625+
if test ac_cv_sizeof_void_p -eq 8 ; then
626+
isainfo_output=`isainfo -n`
627+
if test ! -z "$isainfo_output" ; then
628+
#
629+
# Success - change PCAP_CONFIG.
630+
#
631+
PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"`
632+
fi
633+
fi
634+
;;
601635
esac
602636
fi
603637
#

cmake/Modules/FindPCAP.cmake

+48-8
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,57 @@ else(WIN32)
194194
endif()
195195

196196
#
197-
# if this is macOS or some other Darwin-based OS, check whether
198-
# it's the system-supplied one.
197+
# If this is a vendor-supplied pcap-config, which we define as
198+
# being "a pcap-config in /usr/bin or /usr/ccs/bin" (the latter
199+
# is for Solaris and Sun/Oracle Studio), there are some issues.
200+
# Work around them.
199201
#
200-
if(APPLE AND "${PCAP_CONFIG}" STREQUAL /usr/bin/pcap-config)
202+
if("${PCAP_CONFIG}" STREQUAL /usr/bin/pcap-config OR
203+
"${PCAP_CONFIG}" STREQUAL /usr/ccs/bin/pcap-config)
201204
#
202-
# It is - remember that, so that if it provides -I/usr/local/include
203-
# with --cflags, or -L/usr/local/lib with --libs, we ignore it;
204-
# the macOS pcap-config does that even though the headers aren't
205-
# under /usr/local/include and the library isn't in /usr/local/lib.
205+
# It's vendor-supplied.
206206
#
207-
set(_broken_apple_pcap_config TRUE)
207+
if(APPLE)
208+
#
209+
# This is macOS or another Darwin-based OS.
210+
#
211+
# That means that /usr/bin/pcap-config it may provide
212+
# -I/usr/local/include with --cflags and -L/usr/local/lib
213+
# with --libs; if there's no pcap installed under /usr/local,
214+
# that will cause the build to fail, and if there is a pcap
215+
# installed there, you'll get that pcap even if you don't
216+
# want it. Remember that, so we ignore those values.
217+
#
218+
set(_broken_apple_pcap_config TRUE)
219+
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND CMAKE_SYSTEM_VERSION MATCHES "5[.][0-9.]*")
220+
#
221+
# This is Solaris 2 or later, i.e. SunOS 5.x.
222+
#
223+
# At least on Solaris 11; there's /usr/bin/pcap-config, which
224+
# reports -L/usr/lib with --libs, causing the 32-bit libraries
225+
# to be found, and there's /usr/bin/{64bitarch}/pcap-config,
226+
# where {64bitarch} is a name for the 64-bit version of the
227+
# instruction set, which reports -L /usr/lib/{64bitarch},
228+
# causing the 64-bit libraries to be found.
229+
#
230+
# So if we're building 64-bit targets, we replace PCAP_CONFIG
231+
# with /usr/bin/{64bitarch}; we get {64bitarch} as the
232+
# output of "isainfo -n".
233+
#
234+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
235+
execute_process(COMMAND "isainfo" "-n"
236+
RESULT_VARIABLE ISAINFO_RESULT
237+
OUTPUT_VARIABLE ISAINFO_OUTPUT
238+
OUTPUT_STRIP_TRAILING_WHITESPACE
239+
)
240+
if(ISAINFO_RESULT EQUAL 0)
241+
#
242+
# Success - change PCAP_CONFIG.
243+
#
244+
string(REPLACE "/bin/" "/bin/${ISAINFO_OUTPUT}/" PCAP_CONFIG "${PCAP_CONFIG}")
245+
endif()
246+
endif()
247+
endif()
208248
endif()
209249

210250
#

config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@
252252
/* Define to the version of this package. */
253253
#undef PACKAGE_VERSION
254254

255+
/* The size of `void *', as computed by sizeof. */
256+
#undef SIZEOF_VOID_P
257+
255258
/* Define to 1 if you have the ANSI C header files. */
256259
#undef STDC_HEADERS
257260

0 commit comments

Comments
 (0)