compiling hping2-rc2 on 10.2.3

sighup

Registered
Hi 2 all,

Did anyone had any luck compiling hping? ./configure seems to work (almost) fine, but running make results in a compiler error. Below is some terminal output:

[sighup:~/Desktop/nix_tools/hping2-rc2] sighup% sudo ./configure
build byteorder.c...
byteorder.c:3: undefined or invalid # directive
create byteorder.h...
--------------------------------------
system type: DARWIN

FORCE_LIBPCAP:
LIBPCAP : PCAP=-lpcap
PCAP_INCLUDE :
MANPATH : /sw/share/man

(to modify try configure --help)
--------------------------------------
creating Makefile...
now you can try `make'

[sighup:~/Desktop/nix_tools/hping2-rc2] sighup% sudo make
gcc -c -O2 -Wall -g getifname.c
getifname.c:27: #error Sorry, interface code not implemented.
cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
make: *** [getifname.o] Error 1

I removed the offending line(s) in getifname.c and when running make again, I get:

gcc -c -O2 -Wall -g getifname.c
getifname.c:308: warning: `get_output_if' defined but not used
gcc -c -O2 -Wall -g getlhs.c
gcc -c -O2 -Wall -g linux_sockpacket.c
gcc -c -O2 -Wall -g parseoptions.c
gcc -c -O2 -Wall -g datafiller.c
datafiller.c: In function `datafiller':
datafiller.c:67: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g datahandler.c
gcc -c -O2 -Wall -g gethostname.c
gcc -c -O2 -Wall -g binding.c
gcc -c -O2 -Wall -g getusec.c
gcc -c -O2 -Wall -g opensockraw.c
gcc -c -O2 -Wall -g logicmp.c
gcc -c -O2 -Wall -g waitpacket.c
waitpacket.c: In function `wait_packet':
waitpacket.c:46: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g resolve.c
resolve.c: In function `resolve':
resolve.c:37: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g sendip.c
gcc -c -O2 -Wall -g sendicmp.c
gcc -c -O2 -Wall -g sendudp.c
gcc -c -O2 -Wall -g sendtcp.c
gcc -c -O2 -Wall -g cksum.c
gcc -c -O2 -Wall -g statistics.c
statistics.c: In function `print_statistics':
statistics.c:46: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g usage.c
usage.c: In function `show_usage':
usage.c:94: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g version.c
version.c: In function `show_version':
version.c:24: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g antigetopt.c
gcc -c -O2 -Wall -g sockopt.c
gcc -c -O2 -Wall -g listen.c
listen.c: In function `listenmain':
listen.c:39: warning: implicit declaration of function `exit'
gcc -c -O2 -Wall -g sendhcmp.c
gcc -c -O2 -Wall -g memstr.c
gcc -c -O2 -Wall -g rtt.c
gcc -c -O2 -Wall -g relid.c
gcc -c -O2 -Wall -g sendip_handler.c
gcc -c -O2 -Wall -g libpcap_stuff.c
libpcap_stuff.c: In function `pcap_recv':
libpcap_stuff.c:70: warning: implicit declaration of function `memcpy'
gcc -c -O2 -Wall -g memlockall.c
gcc -c -O2 -Wall -g memunlockall.c
gcc -c -O2 -Wall -g memlock.c
gcc -c -O2 -Wall -g memunlock.c
gcc -c -O2 -Wall -g ip_opt_build.c
gcc -c -O2 -Wall -g display_ipopt.c
gcc -c -O2 -Wall -g sendrawip.c
gcc -c -O2 -Wall -g signal.c
gcc -c -O2 -Wall -g send.c
gcc -c -O2 -Wall -g strlcpy.c
gcc -o hping2 -O2 -Wall -g main.o getifname.o getlhs.o linux_sockpacket.o parseoptions.o datafiller.o datahandler.o gethostname.o binding.o getusec.o opensockraw.o logicmp.o waitpacket.o resolve.o sendip.o sendicmp.o sendudp.o sendtcp.o cksum.o statistics.o usage.o version.o antigetopt.o sockopt.o listen.o sendhcmp.o memstr.o rtt.o relid.o sendip_handler.o libpcap_stuff.o memlockall.o memunlockall.o memlock.o memunlock.o ip_opt_build.o display_ipopt.o sendrawip.o signal.o send.o strlcpy.o -lpcap
ld: warning multiple definitions of symbol _strlcpy
strlcpy.o definition of _strlcpy in section (__TEXT,__text)
/usr/lib/libSystem.dylib(strlcpy.So) definition of _strlcpy
ld: Undefined symbols:
_get_if_name
make: *** [hping2] Error 1

Now I don't know c++ so for me it ends here. Hope someone here knows a solution....

Thanks in advance.
 
Here's what I did to make it work... Looking at the code in getifname.c, it looks like there's no specific Darwin directives, so the trick is to get getifname.c to think that we're on a *BSD (given that so much of Darwin behaves like *BSD). Turns out that's really easy to do. One like of code (not really code, even, just compiler directive) needs to be be added to getifname.c:

Code:
#define __NetBSD__

I added this after the ./configure, but before make. The line itself can go just about anywhere in the first 20 lines or so of the code; I put it right after the comments block at the top of the file.

After that, it builds fine, although the warnings about 'exit' persist. I haven't done extensive testing, but a simple hping of another host works, indicating that it's at least talking to the interfaces correctly.
 
Thanks for your quick reaction Kenny :)

I just did what you mentioned and hping seems to be working fine now. You know your C!

thanks again!!!!!
 
Back
Top