gamelinux / passivedns

A network sniffer that logs all DNS server replies for use in a passive DNS setup
http://gamelinux.org/
1.67k stars 374 forks source link

Building on macOS Sierra (10.12) #89

Closed waynemoore closed 7 years ago

waynemoore commented 7 years ago

I've had some trouble building on macOS Sierra. Where I end up with this error:

$ ./configure
#
# ... snipped ...
#
checking openssl/ssl.h usability... no
checking openssl/ssl.h presence... no
checking for openssl/ssl.h... no
-e
  ERROR! OpenSSL headers not found

I definitely have the dependencies installed via homebrew. It seems to be related to Apple deprecating openssl:

$ brew info openssl
#
# ... snipped ...
#
This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

I managed to work around this by setting variables to one of the homebrew installed libraries:

$ brew info openssl
openssl: stable 1.0.2k (bottled) [keg-only]
SSL/TLS cryptography library
https://openssl.org/
/usr/local/Cellar/openssl/1.0.2a-1 (1,633 files, 12.3M)
  Poured from bottle on 2015-03-19 at 16:33:54
/usr/local/Cellar/openssl/1.0.2d_1 (1,638 files, 12.1M)
  Poured from bottle on 2015-07-13 at 19:46:23
/usr/local/Cellar/openssl/1.0.2e (1,646 files, 11.9M)
  Poured from bottle on 2015-12-29 at 19:30:01
/usr/local/Cellar/openssl/1.0.2g (1,678 files, 12.0M)
  Poured from bottle on 2016-04-10 at 09:39:16
/usr/local/Cellar/openssl/1.0.2h_1 (1,691 files, 12M)
  Poured from bottle on 2016-08-27 at 20:58:30
/usr/local/Cellar/openssl/1.0.2j (1,695 files, 12M)
  Poured from bottle on 2016-09-26 at 20:42:09
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl.rb
# ... snipped ...

$ export LDFLAGS="-L/usr/local/Cellar/openssl/1.0.2j/lib"
$ export CPPFLAGS="-I/usr/local/Cellar/openssl/1.0.2j/include/"
$ export PKG_CONFIG_PATH="/usr/local/Cellar/openssl/1.0.2j/lib/pkgconfig"

Then configure works. However, during make I end up with an error relating to a missing constant:

$ make
Making all in src
gcc -O3 -I/usr/local/Cellar/openssl/1.0.2j/include/ -c passivedns.c -o passivedns.o
passivedns.c:1353:38: error: use of undeclared identifier 'HOST_NAME_MAX'
            config.hostname = malloc(HOST_NAME_MAX + 1);
                                     ^
passivedns.c:1354:42: error: use of undeclared identifier 'HOST_NAME_MAX'
            gethostname(config.hostname, HOST_NAME_MAX);
                                         ^
2 errors generated.
make[1]: *** [passivedns.o] Error 1
make: *** [all-recursive] Error 1

I Googled around to see what this value typically is for macOS and it appeared to be 255, so I hacked it at this point just to get it to compile by sticking it into src/passivedns.h:

/*  D E F I N E S  ************************************************************/
#define HOST_NAME_MAX                 255
#define TIMEOUT                       60

This got me a compiled binary. As I said, this was a hack and I'm not a C programmer so I didn't spend much more time on this but I'm recording it here in case it's helpful for someone else who can turn it into a proper fix.

gamelinux commented 7 years ago

Could you try out this:

`#ifndef HOST_NAME_MAX

if defined(APPLE)

define HOST_NAME_MAX 255

else

define HOST_NAME_MAX 64

endif / APPLE /

endif / HOST_NAME_MAX /`

If it works for you, I can add that to passivedns.h I dont have a Mac to test on.

waynemoore commented 7 years ago

Thanks @gamelinux I can confirm that works from a fresh clone of the repo, but you have to format it like so:

#ifndef HOST_NAME_MAX
#if defined(__APPLE__)
#define HOST_NAME_MAX 255
#else #define HOST_NAME_MAX 64
#endif /* __APPLE__ */
#endif /* HOST_NAME_MAX */

i.e. not all on one line.

gamelinux commented 7 years ago

LoL - that did not have all in one line when I pasted it here. Added in commit 2bed37beb73527ba8549b9cac4a8ac010a4fb4b3

Thanks!