Fix compilation on OS X

OS X doesn't implement SOL_TCP so workaround this the same way as on FreeBSD/Solaris.

(Strictly speaking the clang patches are also required for compilation on modern OS X)