Code is now compilable on the Win32 platform

remotes/origin/master-1.0.x
Jan Jezek 16 years ago committed by Victor Julien
parent f0b9ad3f1f
commit fe6a72befc

@ -56,13 +56,22 @@
/* Define to 1 if you have the `memset' function. */
#undef HAVE_MEMSET
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if you have the <poll.h> header file. */
#undef HAVE_POLL_H
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#undef HAVE_REALLOC
/* Define to 1 if you have the <signal.h> header file. */
#undef HAVE_SIGNAL_H
/* Define to 1 if stdbool.h conforms to C99. */
#undef HAVE_STDBOOL_H
@ -99,12 +108,18 @@
/* Define to 1 if you have the `strtoul' function. */
#undef HAVE_STRTOUL
/* Define to 1 if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/syscall.h> header file. */
#undef HAVE_SYS_SYSCALL_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
@ -114,6 +129,15 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <windows.h> header file. */
#undef HAVE_WINDOWS_H
/* Define to 1 if you have the <winsock2.h> header file. */
#undef HAVE_WINSOCK2_H
/* Define to 1 if you have the <ws2tcpip.h> header file. */
#undef HAVE_WS2TCPIP_H
/* Define to 1 if the system has the type `_Bool'. */
#undef HAVE__BOOL
@ -136,9 +160,6 @@
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
@ -151,19 +172,19 @@
/* Version number of package */
#undef VERSION
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
#define below would cause a syntax error. */
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
#define below would cause a syntax error. */
#undef _UINT32_T
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
#define below would cause a syntax error. */
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
#define below would cause a syntax error. */
#undef _UINT64_T
/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
#define below would cause a syntax error. */
/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef was allowed, the
#define below would cause a syntax error. */
#undef _UINT8_T
/* Define to `__inline__' or `__inline' if that's what the C compiler
@ -172,7 +193,7 @@
#undef inline
#endif
/* Define to the type of a signed integer type of width exactly 32 bits if
/* Define to the type of a signed integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#undef int32_t
@ -188,18 +209,18 @@
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
/* Define to the type of an unsigned integer type of width exactly 16 bits if
/* Define to the type of an unsigned integer type of width exactly 16 bits if
such a type exists and the standard includes do not define it. */
#undef uint16_t
/* Define to the type of an unsigned integer type of width exactly 32 bits if
/* Define to the type of an unsigned integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
#undef uint32_t
/* Define to the type of an unsigned integer type of width exactly 64 bits if
/* Define to the type of an unsigned integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */
#undef uint64_t
/* Define to the type of an unsigned integer type of width exactly 8 bits if
/* Define to the type of an unsigned integer type of width exactly 8 bits if
such a type exists and the standard includes do not define it. */
#undef uint8_t

@ -53,7 +53,7 @@ AC_INIT(configure.in)
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h inttypes.h limits.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
AC_CHECK_HEADERS([arpa/inet.h inttypes.h limits.h netdb.h netinet/in.h poll.h signal.h stdint.h stdlib.h string.h syslog.h sys/socket.h sys/syscall.h sys/time.h unistd.h windows.h winsock2.h ws2tcpip.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
@ -94,6 +94,10 @@ AC_INIT(configure.in)
*-*-linux*)
#for now do nothing
;;
*-*-mingw32*)
CFLAGS="${CFLAGS} -DOS_WIN32"
LDFLAGS="${LDFLAGS} -lws2_32"
;;
*)
AC_MSG_WARN([unsupported OS this may or may not work])
;;

File diff suppressed because it is too large Load Diff

@ -180,7 +180,9 @@ app-layer-smb2.c app-layer-smb2.h \
app-layer-dcerpc.c app-layer-dcerpc.h \
app-layer-ftp.c app-layer-ftp.h \
defrag.c defrag.h \
output.c output.h
output.c output.h \
win32-misc.c win32-misc.h \
win32-syslog.h
# set the include path found by configure
INCLUDES= $(all_includes)

@ -5,8 +5,6 @@
* \author Brian Rectanus <brectanu@gmail.com>
*/
#include <netdb.h>
#include "suricata-common.h"
#include "debug.h"
#include "decode.h"

@ -91,6 +91,13 @@
/*
* Singly-linked List definitions.
*/
/*
* The following macros are not used and are in conflict with Win32 API
*/
#if 0
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
@ -161,6 +168,8 @@ struct { \
} \
} while (0)
#endif /* 0 */
/*
* List definitions.
*/

@ -14,11 +14,8 @@
* to be the default in flexresp and iptables
*/
#include "suricata-common.h"
#include <libnet.h>
#include "decode.h"
#include "decode-ipv4.h"
#include "decode-tcp.h"
@ -32,6 +29,11 @@
#include "respond-reject.h"
#include "respond-reject-libnet11.h"
#ifndef OS_WIN32
#include <libnet.h>
typedef struct Libnet11Packet_
{
uint32_t ack, seq;
@ -234,3 +236,16 @@ cleanup:
return 0;
}
#else /* ifndef OS_WIN32 */
int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir) {
printf("RejectSendLibnet11L3IPv4TCP not implemented for OS_WIN32\n");
return 0;
}
int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir) {
printf("RejectSendLibnet11L3IPv4ICMP not implemented for OS_WIN32\n");
return 0;
}
#endif /*ifndef OS_WIN32 */

@ -4,8 +4,6 @@
* \author Nick Rogness <nick@rogness.net>
*/
#include <poll.h>
#include <signal.h>
#include "suricata-common.h"
#include "suricata.h"
#include "decode.h"

@ -15,7 +15,11 @@
#include <sys/types.h> /* for gettid(2) */
#define _GNU_SOURCE
#define __USE_GNU
#if HAVE_SYS_SYSCALL_H
#include <sys/syscall.h>
#endif
#include <sched.h> /* for sched_setaffinity(2) */
#include <stdio.h>
@ -31,18 +35,64 @@
#include <pcre.h>
#include "threads.h"
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#else
#include "win32-syslog.h"
#endif /* HAVE_SYSLOG_H */
#ifdef OS_WIN32
#include "win32-misc.h"
#endif /* OS_WIN32 */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/time.h>
#if HAVE_POLL_H
#include <poll.h>
#endif
#if HAVE_SYS_SIGNAL_H
#include <sys/signal.h>
#endif
#include <sys/types.h>
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <sys/stat.h>
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_WINDOWS_H
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#ifdef HAVE_WS2TCPIP_H
#include <ws2tcpip.h>
#endif
#include <assert.h>
#define BUG_ON(x) assert(!(x))

@ -137,6 +137,7 @@ static void SignalHandlerSigint(/*@unused@*/ int sig) { sigint_count = 1; sigfla
static void SignalHandlerSigterm(/*@unused@*/ int sig) { sigterm_count = 1; sigflags |= SURICATA_SIGTERM; }
static void SignalHandlerSighup(/*@unused@*/ int sig) { sighup_count = 1; sigflags |= SURICATA_SIGHUP; }
#ifndef OS_WIN32
static void
SignalHandlerSetup(int sig, void (*handler)())
{
@ -148,6 +149,7 @@ SignalHandlerSetup(int sig, void (*handler)())
action.sa_flags = 0;
sigaction(sig, &action, 0);
}
#endif /* OS_WIN32 */
Packet *SetupPktWait (void)
{
@ -384,6 +386,14 @@ int main(int argc, char **argv)
char *log_dir;
struct stat buf;
#ifdef OS_WIN32
WSADATA wsaData;
if (0 != WSAStartup(MAKEWORD(2, 2), &wsaData)) {
fprintf(stderr, "ERROR: Failed to initialize Windows sockets.\n");
exit(EXIT_FAILURE);
}
#endif
/* initialize the logging subsys */
SCLogInitLogModule(NULL);
@ -756,10 +766,12 @@ int main(int argc, char **argv)
if (daemon) Daemonize();
#ifndef OS_WIN32
/* registering signals we use */
SignalHandlerSetup(SIGINT, SignalHandlerSigint);
SignalHandlerSetup(SIGTERM, SignalHandlerSigterm);
SignalHandlerSetup(SIGHUP, SignalHandlerSighup);
#endif /* OS_WIN32 */
/* pre allocate packets */
SCLogDebug("preallocating packets... packet size %" PRIuMAX "", (uintmax_t)sizeof(Packet));

@ -50,8 +50,12 @@
u_long tid = (u_long)tmpthid; \
tid; \
})
#else
#ifdef OS_DARWIN
#elif OS_WIN32
#define SCGetThreadIdLong(...) ({ \
u_long tid = (u_long)GetCurrentThreadId(); \
tid; \
})
#elif OS_DARWIN
#define SCGetThreadIdLong(...) ({ \
thread_port_t tpid; \
tpid = mach_thread_self(); \
@ -65,7 +69,6 @@
u_long tid = (u_long)tmpthid; \
tid; \
})
#endif /* OS DARWIN*/
#endif /* OS FREEBSD */
/** Mutex Functions */

@ -587,15 +587,21 @@ static int SetCPUAffinity(uint16_t cpuid) {
int cpu = (int)cpuid;
#ifdef OS_WIN32
DWORD cs = 1 << cpu;
#else
cpu_set_t cs;
CPU_ZERO(&cs);
CPU_SET(cpu,&cs);
#endif /* OS_WIN32 */
#ifdef OS_FREEBSD
int r = cpuset_setaffinity(CPU_LEVEL_WHICH,CPU_WHICH_TID,SCGetThreadIdLong(),sizeof(cpu_set_t),&cs);
#elif OS_DARWIN
int r = thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (void*)&cs, THREAD_AFFINITY_POLICY_COUNT);
#elif OS_WIN32
int r = (0 == SetThreadAffinityMask(GetCurrentThread(), cs));
#else
pid_t tid = syscall(SYS_gettid);
int r = sched_setaffinity(tid,sizeof(cpu_set_t),&cs);

@ -22,6 +22,25 @@
#define SCByteSwap16(x) OSSwapInt16(x)
#define SCByteSwap32(x) OSSwapInt32(x)
#define SCByteSwap64(x) OSSwapInt64(x)
#elif OS_WIN32
/* Quick & dirty solution, nothing seems to exist for this in Win32 API */
#define SCByteSwap16(x) \
((((x) & 0xff00) >> 8) \
| (((x) & 0x00ff) << 8))
#define SCByteSwap32(x) \
((((x) & 0xff000000) >> 24) \
| (((x) & 0x00ff0000) >> 8) \
| (((x) & 0x0000ff00) << 8) \
| (((x) & 0x000000ff) << 24))
#define SCByteSwap64(x) \
((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
#else
#include <byteswap.h>
#define SCByteSwap16(x) bswap_16(x)

@ -44,7 +44,7 @@
*/
uint16_t UtilCpuGetNumProcessorsConfigured() {
#ifdef SYSCONF_NPROCESSORS_CONF_COMPAT
long nprocs = -1;
long nprocs = -1;
nprocs = sysconf(_SC_NPROCESSORS_CONF);
if (nprocs < 1) {
SCLogError(SC_ERR_SYSCALL, "Couldn't retrieve the number of cpus "
@ -59,6 +59,16 @@ uint16_t UtilCpuGetNumProcessorsConfigured() {
return UINT16_MAX;
}
return (uint16_t)nprocs;
#elif OS_WIN32
long nprocs = -1;
const char* envvar = getenv("NUMBER_OF_PROCESSORS");
nprocs = (NULL != envvar) ? atoi(envvar) : 0;
if (nprocs < 1) {
SCLogError(SC_ERR_SYSCALL, "Couldn't retrieve the number of cpus "
"configured from the NUMBER_OF_PROCESSORS environment variable");
return 0;
}
return (uint16_t)nprocs;
#else
SCLogError(SC_ERR_SYSCONF, "Couldn't retrieve the number of cpus "
@ -90,6 +100,8 @@ uint16_t UtilCpuGetNumProcessorsOnline() {
}
return nprocs;
#elif OS_WIN32
return UtilCpuGetNumProcessorsConfigured();
#else
SCLogError(SC_ERR_SYSCONF, "Couldn't retrieve the number of cpus online, "
"synconf macro unavailable");

@ -7,15 +7,17 @@
* Daemonization process
*/
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "suricata.h"
#include "suricata-common.h"
#include "util-daemon.h"
#include "util-debug.h"
#ifndef OS_WIN32
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
static volatile sig_atomic_t sigflag = 0;
/**
@ -74,32 +76,6 @@ static void SetupLogging () {
fd2 = dup(0);
}
/**
* \brief Check for a valid combination daemon/mode
*
* \param daemon daemon on or off
* \param mode selected mode
*
* \retval 1 valid combination
* \retval 0 invalid combination
*/
int CheckValidDaemonModes (int daemon, int mode) {
if (daemon) {
switch (mode) {
case MODE_PCAP_FILE:
SCLogError(SC_ERR_INVALID_RUNMODE, "ERROR: pcap offline mode cannot run as daemon");
return 0;
case MODE_UNITTEST:
SCLogError(SC_ERR_INVALID_RUNMODE, "ERROR: unittests cannot run as daemon");
return 0;
default:
SCLogDebug("Allowed mode");
break;
}
}
return 1;
}
/**
* \brief Daemonize the process
*
@ -158,3 +134,31 @@ void Daemonize (void) {
exit(EXIT_SUCCESS);
}
#endif /* ifndef OS_WIN32 */
/**
* \brief Check for a valid combination daemon/mode
*
* \param daemon daemon on or off
* \param mode selected mode
*
* \retval 1 valid combination
* \retval 0 invalid combination
*/
int CheckValidDaemonModes (int daemon, int mode) {
if (daemon) {
switch (mode) {
case MODE_PCAP_FILE:
SCLogError(SC_ERR_INVALID_RUNMODE, "ERROR: pcap offline mode cannot run as daemon");
return 0;
case MODE_UNITTEST:
SCLogError(SC_ERR_INVALID_RUNMODE, "ERROR: unittests cannot run as daemon");
return 0;
default:
SCLogDebug("Allowed mode");
break;
}
}
return 1;
}

@ -12,7 +12,12 @@
/** \todo Adjust path */
#define DAEMON_WORKING_DIRECTORY "/"
int CheckValidDaemonModes (int, int);
#ifdef OS_WIN32
#define Daemonize()
#else
void Daemonize (void);
#endif
int CheckValidDaemonModes (int, int);
#endif /* __UTIL_DAEMON_H__ */

@ -6,7 +6,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include "threads.h"
#include "util-debug.h"

@ -9,8 +9,6 @@
#include <sys/types.h>
#include <stdarg.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <syslog.h>
#include "threads.h"
#include "util-debug.h"
#include "util-error.h"
@ -18,6 +16,7 @@
#include "util-debug-filters.h"
#include "suricata-common.h"
#include "decode.h"
#include "detect.h"
#include "packet-queue.h"

@ -5,7 +5,6 @@
#include <stdio.h>
#include "threads.h"
#include <stdint.h>
#include <syslog.h>
#include "util-enum.h"
#include "util-error.h"

@ -6,9 +6,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "suricata-common.h"
#ifdef OS_FREEBSD
#include <netinet/in.h>

Loading…
Cancel
Save