forked from mtnsat/PcapPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure-mac_os_x.sh
executable file
·177 lines (143 loc) · 5.52 KB
/
configure-mac_os_x.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
echo ""
echo "*******************************************"
echo "PcapPlusPlus Mac OS X configuration script "
echo "*******************************************"
echo ""
# set Script Name variable
SCRIPT=`basename ${BASH_SOURCE[0]}`
# help function
function HELP {
echo -e \\n"Help documentation for ${SCRIPT}."\\n
echo -e "Basic usage: $SCRIPT [-h] [--use-immediate-mode] [--set-direction-enabled] [--install-dir] [--libpcap-include-dir] [--libpcap-lib-dir] [--use-zstd]"\\n
echo "The following switches are recognized:"
echo "--use-immediate-mode --Use libpcap immediate mode which enables getting packets as fast as possible (supported on libpcap>=1.5)"
echo ""
echo "--set-direction-enabled --Set direction for capturing incoming packets or outgoing packets (supported on libpcap>=0.9.1)"
echo ""
echo "--install-dir --Set installation directory. Default is /usr/local"
echo ""
echo "--libpcap-include-dir --libpcap header files directory. This parameter is optional and if omitted PcapPlusPlus will look for"
echo " the header files in the default include paths"
echo "--libpcap-lib-dir --libpcap pre compiled lib directory. This parameter is optional and if omitted PcapPlusPlus will look for"
echo " the lib file in the default lib paths"
echo "--use-zstd --Use Zstd for pcapng files compression/decompression. This parameter is optional"
echo ""
echo -e "-h|--help --Displays this help message and exits. No further actions are performed"\\n
echo -e "Examples:"
echo -e " $SCRIPT"
echo -e " $SCRIPT --use-immediate-mode"
echo -e " $SCRIPT --set-direction-enabled"
echo -e " $SCRIPT --libpcap-include-dir /home/myuser/my-libpcap/include --libpcap-lib-dir /home/myuser/my-libpcap/lib"
echo -e " $SCRIPT --install-dir /home/myuser/my-install-dir"
echo ""
exit 1
}
HAS_PCAP_IMMEDIATE_MODE=0
HAS_SET_DIRECTION_ENABLED=0
# initializing libpcap include/lib dirs to an empty string
LIBPCAP_INLCUDE_DIR=""
LIBPCAP_LIB_DIR=""
# default installation directory
INSTALL_DIR=/usr/local
#Check the number of arguments. If none are passed, continue to wizard mode.
NUMARGS=$#
echo -e "Number of arguments: $NUMARGS"\\n
# if user put an illegal switch - print HELP and exit
if [ $? -ne 0 ]; then
HELP
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
# default switch - do nothing basically
--default)
shift ;;
# enable libpcap immediate mode
--use-immediate-mode)
HAS_PCAP_IMMEDIATE_MODE=1
shift ;;
# set direction enabled
--set-direction-enabled)
HAS_SET_DIRECTION_ENABLED=1
shift ;;
# non-default libpcap include dir
--libpcap-include-dir)
LIBPCAP_INLCUDE_DIR=$2
shift
shift ;;
# non-default libpcap lib dir
--libpcap-lib-dir)
LIBPCAP_LIB_DIR=$2
shift
shift ;;
# installation directory prefix
--install-dir)
INSTALL_DIR=$2
if [ ! -d "$INSTALL_DIR" ]; then
echo "Installation directory '$INSTALL_DIR' not found. Exiting..."
exit 1
fi
shift
shift ;;
# use Zstd
--use-zstd)
USE_ZSTD=1
shift ;;
# help switch - display help and exit
-h|--help)
HELP ;;
# empty switch - just go on
--)
break ;;
# illegal switch
*)
echo -e \\n"Option $key not allowed.";
HELP;
exit 1 ;;
esac
done
PLATFORM_MK="mk/platform.mk"
PCAPPLUSPLUS_MK="mk/PcapPlusPlus.mk"
cp -f mk/platform.mk.macosx $PLATFORM_MK
cp -f mk/PcapPlusPlus.mk.common $PCAPPLUSPLUS_MK
# set SDK home if MacOS verion >= 10.14
MACOS_MINOR_VERSION=`(sw_vers -productVersion) | awk -F '.' '{print $2}'`
if [[ $MACOS_MINOR_VERSION -ge 14 ]]; then
echo -e "\n# setting SDK home for MacOS version >= 10.14" >> $PCAPPLUSPLUS_MK
echo -e "MACOS_SDK_HOME := /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\n" >> $PCAPPLUSPLUS_MK
fi
cat mk/PcapPlusPlus.mk.macosx >> $PCAPPLUSPLUS_MK
echo -e "\n\nPCAPPLUSPLUS_HOME := "$PWD >> $PLATFORM_MK
sed -i -e '1s|^|PCAPPLUSPLUS_HOME := '$PWD'\'$'\n''\'$'\n''|' $PCAPPLUSPLUS_MK
if (( $HAS_PCAP_IMMEDIATE_MODE > 0 )) ; then
echo -e "HAS_PCAP_IMMEDIATE_MODE := 1\n\n" >> $PCAPPLUSPLUS_MK
fi
if (( $HAS_SET_DIRECTION_ENABLED > 0 )) ; then
echo -e "HAS_SET_DIRECTION_ENABLED := 1\n\n" >> $PCAPPLUSPLUS_MK
fi
# non-default libpcap include dir
if [ -n "$LIBPCAP_INLCUDE_DIR" ]; then
echo -e "# non-default libpcap include dir" >> $PCAPPLUSPLUS_MK
echo -e "LIBPCAP_INLCUDE_DIR := $LIBPCAP_INLCUDE_DIR" >> $PCAPPLUSPLUS_MK
echo -e "PCAPPP_INCLUDES += -I\$(LIBPCAP_INLCUDE_DIR)\n" >> $PCAPPLUSPLUS_MK
fi
# non-default libpcap lib dir
if [ -n "$LIBPCAP_LIB_DIR" ]; then
echo -e "# non-default libpcap lib dir" >> $PCAPPLUSPLUS_MK
echo -e "LIBPCAP_LIB_DIR := $LIBPCAP_LIB_DIR" >> $PCAPPLUSPLUS_MK
echo -e "PCAPPP_LIBS_DIR += -L\$(LIBPCAP_LIB_DIR)\n" >> $PCAPPLUSPLUS_MK
fi
if [ -n "$USE_ZSTD" ]; then
echo -e "DEFS += -DUSE_Z_STD" > 3rdParty/LightPcapNg/zstd.mk
cat mk/PcapPlusPlus.mk.zstd >> $PCAPPLUSPLUS_MK
fi
# generate installation and uninstallation scripts
cp mk/install.sh.template mk/install.sh
sed -i.bak "s|{{INSTALL_DIR}}|$INSTALL_DIR|g" mk/install.sh && rm mk/install.sh.bak
chmod +x mk/install.sh
cp mk/uninstall.sh.template mk/uninstall.sh
sed -i.bak "s|{{INSTALL_DIR}}|$INSTALL_DIR|g" mk/uninstall.sh && rm mk/uninstall.sh.bak
chmod +x mk/uninstall.sh
echo "PcapPlusPlus configuration is complete. Files created (or modified): $PLATFORM_MK, $PCAPPLUSPLUS_MK", mk/install.sh, mk/uninstall.sh