airmonインストールとvariable ‘xxx’ set but not usedの回避
自宅のwifiの脆弱度を調べるためにairmon-ngのインストール。
libpcapのインストール
$sudo aptitude install libpcap
ビルド
ソースからbuildしようとmakeしたら、以下のエラーが出て停止。
$gcc -g -W -Wall -Werror -O3 -D_FILE_OFFSET_BITS=64 -D_REVISION=0 -fPIC -I.. -c -o linux.o linux.c linux.c: In function ‘is_ndiswrapper’: linux.c:165:17: <span class="deco" style="color:#FF0000;">error: variable ‘unused’ set but not used [-Werror=unused-but-set-variable]</span> linux.c: In function ‘linux_set_rate’: linux.c:334:22: <span class="deco" style="color:#FF0000;">error: variable ‘unused’ set but not used [-Werror=unused-but-set-variable]</span> linux.c: In function ‘linux_set_channel’: linux.c:807:22: <span class="deco" style="color:#FF0000;">error: variable ‘unused’ set but not used [-Werror=unused-but-set-variable]</span> linux.c: In function ‘linux_set_freq’: linux.c:896:22: <span class="deco" style="color:#FF0000;">error: variable ‘unused’ set but not used [-Werror=unused-but-set-variable]</span> linux.c: In function ‘set_monitor’: linux.c:1022:22: <span class="deco" style="color:#FF0000;">error: variable ‘unused’ set but not used [-Werror=unused-but-set-variable]</span> linux.c: In function ‘do_linux_open’: linux.c:1366:12: <span class="deco" style="color:#FF0000;">error: variable ‘unused_str’ set but not used [-Werror=unused-but-set-variable]</span> linux.c:1352:15: <span class="deco" style="color:#FF0000;">error: variable ‘unused’ set but not used [-Werror=unused-but-set-variable]</span> linux.c: In function ‘get_battery_state’: linux.c:1982:35: <span class="deco" style="color:#FF0000;">error: variable ‘current’ set but not used [-Werror=unused-but-set-variable]</span> cc1: all warnings being treated as errors
gccのマニュアルによれば,gcc4.2から-Werror=で特定の警告を明示してエラーにすることができる。単に-Werrorオプションを付けると、すべての警告がエラーとして扱われる。
このオプションのためmakeが停止したので、common.pakを編集して-Werror=unused-but-set-variableを削除。一応ソースを見てみると、確かに変数に値は格納されているけど、どこからも参照されていない模様。
Werror
Make all warnings into errors.Werror=
Make the specified warning into an error. The specifier for a warning is appended,
for example -Werror=switch turns the warnings controlled by -Wswitch into errors.
This switch takes a negative form, to be used to negate -Werror for specific warnings,
for example -Wno-error=switch makes -Wswitch warnings not be errors, even when -Werror is in effect.The warning message for each controllable warning includes the option that controls the warning.
That option can then be used with -Werror= and -Wno-error= as described above.
(Printing of the option in the warning message can be disabled using the -fno-diagnostics-show-option flag.)Note that specifying -Werror=foo automatically implies -Wfoo. However, -Wno-error=foo does not imply anything.
//Check if the driver is ndiswrapper */ static int is_ndiswrapper(const char * iface, const char * path) { int n, pid, <span class="deco" style="color:#FF0000;">unused</span>; if ( ( pid = fork() )==0 ) { close( 0 ); close( 1 ); close( 2 ); <span class="deco" style="color:#FF0000;">unused = chdir( "/" );</span> execl(path, "iwpriv",iface, "ndis_reset", NULL); exit( 1 ); } waitpid( pid, &n, 0 ); return ( ( WIFEXITED(n) && WEXITSTATUS(n) == 0 )); }
というか,unusedといういかにもな変数名で定義しておきながら、-Werror=のコンパイルオプション付けるのもなんなんだろうとか思いながらも再びビルド。
$install -d /usr/local/man/man1 $install -m 644 aircrack-ng.1 airdecap-ng.1 airdriver-ng.1 aireplay-ng.1 airmon-ng.1 airodump-ng.1 airserv-ng.1 airtun-ng.1 ivstools.1 kstats.1 makeivs-ng.1 airbase-ng.1 packetforge-ng.1 airdecloak-ng.1 /usr/local/man/man1 make[1]: Leaving directory `/home/pdkz/aircrack-ng-1.1/manpages' [*] Run 'airodump-ng-oui-update' as root (or with sudo) to install or update Airodump-ng OUI file (Internet connection required).
完了。