This patch makes nepenthes-200508005 compile on FreeBSD 5.4 with gcc 3.4 --Maximillian Dornseif diff -rubBN --exclude=Entries* nepenthes-orig/Makefile nepenthes/Makefile --- nepenthes-orig/Makefile Sat Aug 6 12:58:59 2005 +++ nepenthes/Makefile Sat Aug 6 20:03:27 2005 @@ -7,18 +7,23 @@ # CXX = g++ -CXXFLAGS += -Icore/include -CXXFLAGS += -D _GNU_SOURCE -Wall -Werror +CXXFLAGS += -I/usr/local/include -Icore/include -I/usr/local/include/ +CXXFLAGS += -I/usr/local/include -D _GNU_SOURCE -Wall -Werror ifndef NDEBUG -CXXFLAGS += -g +CXXFLAGS += -I/usr/local/include-g endif # # linker flags # -LDFLAGS = -ldl -lmagic -ladns +LDFLAGS = -L/usr/local/lib -ldl -lmagic -ladns + +ifdef FreeBSD +LDFLAGS = -L/usr/local/lib -lmagic -ladns -lz +MAKE = gmake +endif # # what makes a complete nepenthes build? @@ -41,7 +46,7 @@ VERSION := $(shell if test -d .svn; then svnversion .; fi) ifndef VERSION -VERSION := unknown +VERSION := $(shell date "+%Y%m%dT%H%m%s") endif ifdef RELEASE @@ -79,6 +84,7 @@ # nepenthes: $(CORE_OBJ) + mkdir -p ./bin $(CXX) $(CXXFLAGS) -o bin/$@ $(CORE_OBJ) $(LDFLAGS) # @@ -89,6 +95,6 @@ rm -f core/src/*.o bin/nepenthes clean_modules: - $(foreach mod, $(MODULES), make clean -C modules/$(mod);) + $(foreach mod, $(MODULES), $(MAKE) clean -C modules/$(mod);) clean: clean_core clean_modules +++ nepenthes/compat/magic.h Sat Aug 6 11:24:53 2005 @@ -0,0 +1,71 @@ +/* copied over from FreeBSD 5.4 /usr/src/contrib/file/magic.h */ + +/* + * Copyright (c) Christos Zoulas 2003. + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice immediately at the beginning of the file, without modification, + * this list of conditions, and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#ifndef _MAGIC_H +#define _MAGIC_H + +#include + +#define MAGIC_NONE 0x000 /* No flags */ +#define MAGIC_DEBUG 0x001 /* Turn on debugging */ +#define MAGIC_SYMLINK 0x002 /* Follow symlinks */ +#define MAGIC_COMPRESS 0x004 /* Check inside compressed files */ +#define MAGIC_DEVICES 0x008 /* Look at the contents of devices */ +#define MAGIC_MIME 0x010 /* Return a mime string */ +#define MAGIC_CONTINUE 0x020 /* Return all matches */ +#define MAGIC_CHECK 0x040 /* Print warnings to stderr */ +#define MAGIC_PRESERVE_ATIME 0x080 /* Restore access time on exit */ +#define MAGIC_RAW 0x100 /* Don't translate unprintable chars */ +#define MAGIC_ERROR 0x200 /* Handle ENOENT etc as real errors */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct magic_set *magic_t; +magic_t magic_open(int); +void magic_close(magic_t); + +const char *magic_file(magic_t, const char *); +const char *magic_buffer(magic_t, const void *, size_t); + +const char *magic_error(magic_t); +int magic_setflags(magic_t, int); + +int magic_load(magic_t, const char *); +int magic_compile(magic_t, const char *); +int magic_check(magic_t, const char *); +int magic_errno(magic_t); + +#ifdef __cplusplus +}; +#endif + +#endif /* _MAGIC_H */ diff -rubBN --exclude=Entries* nepenthes-orig/core/include/DNSManager.hpp nepenthes/core/include/DNSManager.hpp --- nepenthes-orig/core/include/DNSManager.hpp Tue Jul 12 23:48:10 2005 +++ nepenthes/core/include/DNSManager.hpp Sat Aug 6 11:11:34 2005 @@ -33,6 +33,10 @@ #include #endif +#ifdef __FreeBSD__ +#include +#endif + #include "Manager.hpp" #include "EventHandler.hpp" diff -rubBN --exclude=Entries* nepenthes-orig/core/include/DownloadManager.hpp nepenthes/core/include/DownloadManager.hpp --- nepenthes-orig/core/include/DownloadManager.hpp Tue Jul 12 23:48:10 2005 +++ nepenthes/core/include/DownloadManager.hpp Sat Aug 6 11:11:34 2005 @@ -36,6 +36,10 @@ #include #endif +#if __FreeBSD__ +#include +#endif + #include #include diff -rubBN --exclude=Entries* nepenthes-orig/core/include/Nepenthes.hpp nepenthes/core/include/Nepenthes.hpp --- nepenthes-orig/core/include/Nepenthes.hpp Tue Jul 12 23:48:10 2005 +++ nepenthes/core/include/Nepenthes.hpp Sat Aug 6 11:11:34 2005 @@ -36,6 +36,10 @@ #include #endif +#ifdef __FreeBSD__ +#include +#endif + typedef unsigned int uint; typedef unsigned char byte; diff -rubBN --exclude=Entries* nepenthes-orig/core/include/Socket.hpp nepenthes/core/include/Socket.hpp --- nepenthes-orig/core/include/Socket.hpp Tue Jul 12 23:48:10 2005 +++ nepenthes/core/include/Socket.hpp Sat Aug 6 12:16:02 2005 @@ -34,6 +34,10 @@ #define socklen_t int #endif +#ifdef __FreeBSD__ + #include +#endif + #include #include using namespace std; diff -rubBN --exclude=Entries* nepenthes-orig/core/include/SubmitManager.hpp nepenthes/core/include/SubmitManager.hpp --- nepenthes-orig/core/include/SubmitManager.hpp Tue Jul 12 23:48:10 2005 +++ nepenthes/core/include/SubmitManager.hpp Sat Aug 6 11:27:40 2005 @@ -33,7 +33,11 @@ #ifdef WIN32 #else -#include + #ifdef __FreeBSD__ + #include "../../compat/magic.h" + #else + #include + #endif #endif #include "Manager.hpp" diff -rubBN --exclude=Entries* nepenthes-orig/core/include/TCPSocket.hpp nepenthes/core/include/TCPSocket.hpp --- nepenthes-orig/core/include/TCPSocket.hpp Tue Jul 12 23:48:10 2005 +++ nepenthes/core/include/TCPSocket.hpp Sat Aug 6 12:22:31 2005 @@ -40,7 +40,7 @@ public: TCPSocket(Nepenthes *nepenthes, unsigned long localaddress, int port, time_t bindtimeout, time_t accepttimeout); // bind socket TCPSocket(Nepenthes *nepenthes, int socket, unsigned long localhost, int localport, unsigned long remotehost,int remoteport, time_t accepttimeout); // accept socket - TCPSocket(Nepenthes *nepenthes,unsigned long localhost, unsigned long remotehost, int remoteport, time_t connectiontimeout); // connect with timeout + TCPSocket(Nepenthes *nepenthes, unsigned long localhost, unsigned long remotehost, int remoteport, time_t connectiontimeout); // connect with timeout ~TCPSocket(); bool bindPort(); bool Init(); diff -rubBN --exclude=Entries* nepenthes-orig/core/src/Nepenthes.cpp nepenthes/core/src/Nepenthes.cpp --- nepenthes-orig/core/src/Nepenthes.cpp Tue Jul 12 23:48:11 2005 +++ nepenthes/core/src/Nepenthes.cpp Sat Aug 6 11:59:07 2005 @@ -38,6 +38,10 @@ #include #include +#ifdef __FreeBSD__ +#include +#endif + #include "Nepenthes.hpp" #include "SocketManager.hpp" #include "EventManager.hpp" @@ -460,7 +464,6 @@ */ signal(SIGBUS, SignalHandler); // 10,7,10 Core Bus error (bad memory access) - signal(SIGPOLL, SignalHandler); // Term Pollable event (Sys V). Synonym of SIGIO signal(SIGPROF, SignalHandler); // 27,27,29 Term Profiling timer expired signal(SIGSYS, SignalHandler); // 12,-,12 Core Bad argument to routine (SVID) signal(SIGTRAP, SignalHandler); // 5 Core Trace/breakpoint trap @@ -474,14 +477,19 @@ */ signal(SIGIOT, SignalHandler); // 6 Core IOT trap. A synonym for SIGABRT // signal(SIGEMT, SignalHandler); // 7,-,7 Term - signal(SIGSTKFLT,SignalHandler); // -,16,- Term Stack fault on coprocessor (unused) signal(SIGIO, SignalHandler); // 23,29,22 Term I/O now possible (4.2 BSD) - signal(SIGCLD, SignalHandler); // -,-,18 Ign A synonym for SIGCHLD - signal(SIGPWR, SignalHandler); // 29,30,19 Term Power failure (System V) -// signal(SIGINFO, SignalHandler); // 29,-,- A synonym for SIGPWR +// signal(SIGINFO, SignalHandler); // 29,-,- // signal(SIGLOST, SignalHandler); // -,-,- Term File lock lost signal(SIGWINCH, SIG_IGN ); // 28,28,20 Ign Window resize signal (4.3 BSD, Sun) + #ifdef __FreeBSD__ + #else + // This seems Linux specific + signal(SIGPOLL, SignalHandler); // Term Pollable event (Sys V). Synonym of SIGIO + signal(SIGSTKFLT,SignalHandler); // -,16,- Term Stack fault on coprocessor (unused) + signal(SIGCLD, SignalHandler); // -,-,18 Ign A synonym for SIGCHLD + signal(SIGPWR, SignalHandler); // 29,30,19 Term Power failure (System V) signal(SIGUNUSED,SignalHandler); // -,31,- Term Unused signal (will be SIGSYS) + #endif #endif show_logo(); --- nepenthes-orig/core/src/SocketManager.cpp Tue Jul 12 23:48:11 2005 +++ nepenthes/core/src/SocketManager.cpp Sat Aug 6 12:31:11 2005 @@ -38,9 +38,13 @@ #include #include #include -#include #include #include + #ifdef __FreeBSD__ + #include + #else + #include + #endif #endif @@ -786,7 +790,9 @@ if(sock == NULL) { - if ((sock = new TCPSocket(getNepenthes(), localhost, port, bindtimeout, accepttimeout)) == NULL ) + // This can bee seen as ambiguous - at least on FreeBSD. We want this: + // TCPSocket(Nepenthes *nepenthes, unsigned long localaddress, int port, time_t bindtimeout, time_t accepttimeout) + if ((sock = new TCPSocket(getNepenthes(), localhost, (int) port, (time_t) bindtimeout, (time_t) accepttimeout)) == NULL ) { logCrit("ERROR Binding %s:%i failed\n","",port); return NULL; @@ -824,7 +830,7 @@ if(sock == NULL) { - if ((sock = new TCPSocket(getNepenthes(), localhost, port, bindtimeout, accepttimeout)) == NULL ) + if ((sock = new TCPSocket(getNepenthes(), localhost, (int) port, bindtimeout, accepttimeout)) == NULL ) { logCrit("ERROR Binding %s:%i failed\n","",port); return NULL; @@ -863,7 +869,7 @@ if(sock == NULL) { - if ((sock = new UDPSocket(getNepenthes(), localhost, port, bindtimeout, accepttimeout)) == NULL ) + if ((sock = new UDPSocket(getNepenthes(), localhost, (int) port, bindtimeout, accepttimeout)) == NULL ) { logCrit("ERROR Binding %s:%i failed\n","",port); return NULL; Binary files nepenthes-orig/core/src/SubmitHandler.o and nepenthes/core/src/SubmitHandler.o differ diff -rubBN --exclude=Entries* nepenthes-orig/core/src/TCPSocket.cpp nepenthes/core/src/TCPSocket.cpp --- nepenthes-orig/core/src/TCPSocket.cpp Tue Jul 12 23:48:11 2005 +++ nepenthes/core/src/TCPSocket.cpp Sat Aug 6 12:19:50 2005 @@ -388,7 +388,11 @@ #ifdef WIN32 int sended = send(m_Socket,packet->getData(), packet->getLength(), 0); #else + #if __FreeBSD__ + int sended = send(m_Socket,packet->getData(), packet->getLength(), SO_NOSIGPIPE); + #else int sended = send(m_Socket,packet->getData(), packet->getLength(), MSG_NOSIGNAL); + #endif #endif if(sended > 0) diff -rubBN --exclude=Entries* nepenthes-orig/doc/README nepenthes/doc/README --- nepenthes-orig/doc/README Thu Jun 9 22:16:18 2005 +++ nepenthes/doc/README Sat Aug 6 11:11:34 2005 @@ -111,7 +111,7 @@ - libmagic - libpcre - On debien just do + On debian just do apt-get install libcurl3-dev apt-get install libmagic-dev apt-get install libpcre3-dev diff -rubBN --exclude=Entries* nepenthes-orig/doc/README.freebsd nepenthes/doc/README.freebsd --- nepenthes-orig/doc/README.freebsd Thu Jan 1 01:00:00 1970 +++ nepenthes/doc/README.freebsd Sat Aug 6 12:42:27 2005 @@ -0,0 +1,19 @@ +The port of nepenthes to FreeBSD was done by Maximillian Dornseif. +Some notes: + +The nephentis build process does not use POSIX Makefiles, so it +requires GNU make. In addition it needs a bunch of libraries. You +can get all you need by typing (as root): + +(cd /usr/ports/ ; sudo make package) +(cd /usr/ports/dns/adns ; make package) +(cd /usr/ports/devel/pcre ; make package) +(cd /usr/ports/ftp/curl ; make package) +(cd /usr/ports/databases/postgresql80-client ; make package) + +It also needs libmagic.This is somewhat tricky since libmagic is part +of the FreeBSD base system but not the header file required to compile +nepenthes. For now we have just copied over the file from the kernel +source tree to compat/magic.h + +To compile type: gmake FreeBSD=1 diff -rubBN --exclude=Entries* nepenthes-orig/modules/x-7/x-7.cpp nepenthes/modules/x-7/x-7.cpp --- nepenthes-orig/modules/x-7/x-7.cpp Sat Aug 6 12:57:52 2005 +++ nepenthes/modules/x-7/x-7.cpp Sat Aug 6 19:52:17 2005 @@ -210,9 +210,9 @@ case DNS_QRFLAG_RESPONSE: logSpam("%s","DNS Packet is a Response\n"); { - dns_rr_t *rr = (dns_rr_t *)dns; - (char *)rr +=12; - dns_rr_t *header = rr; + char *rr = (char *)dns; + rr +=12; + dns_rr_t *header = (dns_rr_t *)rr; g_Nepenthes->getUtilities()->hexdump((byte *)rr,msg->getMsgLen()-12); char name[256]; @@ -220,17 +220,17 @@ { dns_decode_name(name,(char **)&rr); logSpam("Question %02i/%02i %s \n",i,ntohs(dns->number_questions),name); - (char *)rr +=2; // type - (char *)rr +=2; // class + rr +=2; // type + rr +=2; // class } for (unsigned int i=1;i<=ntohs(dns->number_answers);i++) { - if ( *(char *)rr & 0xC0) + if ( *rr & 0xC0) {// compressed reply dns_rr_t *rrh = header; dns_decode_name(name,(char **)&rrh); - (char *)rr +=2;// ((char *)rrh - (char *)header); + rr +=2;// ((char *)rrh - (char *)header); }else { dns_decode_name(name,(char **)&rr); @@ -239,28 +239,28 @@ unsigned short int type = *(unsigned short int *)rr;; - (char *)rr +=2; // type + rr +=2; // type - (char *)rr +=2; // class - (char *)rr +=4; // ttl + rr +=2; // class + rr +=4; // ttl short unsigned int datalen = *(short unsigned int *)rr; - (char *)rr +=2; // datalen + rr +=2; // datalen if (ntohs(type) == DNS_QUERYTYPE_A) { logSpam("Answer %02i/%02i %s datalen %i ip %s len \n",i,ntohs(dns->number_answers),name, ntohs(datalen), inet_ntoa(*(in_addr *)rr)); - (char *)rr +=ntohs(datalen); // the datalen + rr +=ntohs(datalen); // the datalen } else if (ntohs(type) == DNS_QUERYTYPE_CNAME) { char cname[256]; - dns_rr_t *rrh = rr; + char *rrh = rr; dns_decode_name(cname,(char **)&rrh); logSpam("Answer %02i/%02i %s datalen %i cname %s len \n",i,ntohs(dns->number_answers),name, ntohs(datalen), cname); - (char *)rr +=ntohs(datalen); // the datalen + rr +=ntohs(datalen); // the datalen }