Win32 compile fixes.

remotes/origin/master-1.1.x
Victor Julien 15 years ago
parent d070869c48
commit 55da9787a4

@ -224,13 +224,13 @@ static int EventToImpact(PacketAlert *pa, Packet *p, idmef_alert_t *alert)
if ( ret < 0 )
SCReturnInt(ret);
if ( (uint)pa->s->prio < mid_priority )
if ( (unsigned int)pa->s->prio < mid_priority )
severity = IDMEF_IMPACT_SEVERITY_HIGH;
else if ( (uint)pa->s->prio < low_priority )
else if ( (unsigned int)pa->s->prio < low_priority )
severity = IDMEF_IMPACT_SEVERITY_MEDIUM;
else if ( (uint)pa->s->prio < info_priority )
else if ( (unsigned int)pa->s->prio < info_priority )
severity = IDMEF_IMPACT_SEVERITY_LOW;
else

@ -55,7 +55,9 @@
#define MODULE_NAME "AlertSyslog"
extern uint8_t engine_mode;
#ifndef OS_WIN32
static int alert_syslog_level = DEFAULT_ALERT_SYSLOG_LEVEL;
#endif /* OS_WIN32 */
typedef struct AlertSyslogThread_ {
/** LogFileCtx has the pointer to the file and a mutex to allow multithreading */
@ -70,7 +72,9 @@ TmEcode AlertSyslogThreadDeinit(ThreadVars *, void *);
void AlertSyslogExitPrintStats(ThreadVars *, void *);
void AlertSyslogRegisterTests(void);
OutputCtx *AlertSyslogInitCtx(ConfNode *);
#ifndef OS_WIN32
static void AlertSyslogDeInitCtx(OutputCtx *);
#endif /* OS_WIN32 */
/** \brief Function to register the AlertSyslog module */
void TmModuleAlertSyslogRegister (void) {

@ -63,7 +63,7 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq)
while (!done) {
if (!yaml_parser_parse(parser, &event)) {
fprintf(stderr,
"Failed to parse configuration file at line %zu: %s\n",
"Failed to parse configuration file at line %" PRIu32 ": %s\n",
parser->problem_mark.line, parser->problem);
return -1;
}

@ -121,18 +121,29 @@ ConfNode *
ConfGetNode(char *key)
{
ConfNode *node = root;
#if !defined(__WIN32) && !defined(_WIN32)
char *saveptr = NULL;
#endif /* __WIN32 */
char *token;
/* Need to dup the key for tokenization... */
char *tokstr = SCStrdup(key);
#if defined(__WIN32) || defined(_WIN32)
token = strtok(tokstr, ".");
#else
token = strtok_r(tokstr, ".", &saveptr);
#endif /* __WIN32 */
for (;;) {
node = ConfNodeLookupChild(node, token);
if (node == NULL)
break;
#if defined(__WIN32) || defined(_WIN32)
token = strtok(NULL, ".");
#else
token = strtok_r(NULL, ".", &saveptr);
#endif /* __WIN32 */
if (token == NULL)
break;
}
@ -164,8 +175,9 @@ ConfSet(char *name, char *val, int allow_override)
ConfNode *parent = root;
ConfNode *node;
char *token;
#if !defined(__WIN32) && !defined(_WIN32)
char *saveptr = NULL;
#endif /* __WIN32 */
/* First check if the node already exists. */
node = ConfGetNode(name);
if (node != NULL) {
@ -182,7 +194,11 @@ ConfSet(char *name, char *val, int allow_override)
}
else {
char *tokstr = SCStrdup(name);
#if defined(__WIN32) || defined(_WIN32)
token = strtok(tokstr, ".");
#else
token = strtok_r(tokstr, ".", &saveptr);
#endif /* __WIN32 */
node = ConfNodeLookupChild(parent, token);
for (;;) {
if (node == NULL) {
@ -195,7 +211,11 @@ ConfSet(char *name, char *val, int allow_override)
else {
parent = node;
}
#if defined(__WIN32) || defined(_WIN32)
token = strtok(NULL, ".");
#else
token = strtok_r(NULL, ".", &saveptr);
#endif /* __WIN32 */
if (token == NULL) {
if (!node->allow_override)
break;

@ -45,7 +45,11 @@ typedef struct ConfNode_ {
/**
* The default log directory.
*/
#ifdef OS_WIN32
#define DEFAULT_LOG_DIR "C:\\WINDOWS\\Temp"
#else
#define DEFAULT_LOG_DIR "/var/log/suricata"
#endif /* OS_WIN32 */
void ConfInit(void);
void ConfDeInit(void);

@ -1024,7 +1024,7 @@ DefragTimeoutTracker(ThreadVars *tv, DecodeThreadVars *dtv, DefragContext *dc,
while (next != NULL) {
tracker = HashListTableGetListData(next);
if (tracker->timeout < (uint)p->ts.tv_sec) {
if (tracker->timeout < (unsigned int)p->ts.tv_sec) {
/* Tracker has timeout out. */
HashListTableRemove(dc->frag_table, tracker, sizeof(tracker));
DefragTrackerReset(tracker);

@ -154,6 +154,15 @@
#endif
#endif
/** Windows does not define __WORDSIZE, but it uses __X86__ */
#if defined(__X86__) || defined(_X86_)
#define __WORDSIZE 32
#else
#if defined(__X86_64__) || defined(_X86_64_)
#define __WORDSIZE 64
#endif
#endif
#ifndef __WORDSIZE
#warning Defaulting to __WORDSIZE 32
#define __WORDSIZE 32

@ -327,11 +327,19 @@ static void SetBpfStringFromFile(char *filename) {
char *bpf_comment_tmp = NULL;
char *bpf_comment_start = NULL;
uint32_t bpf_len = 0;
#ifdef OS_WIN32
struct _stat st;
#else
struct stat st;
#endif /* OS_WIN32 */
FILE *fp = NULL;
size_t nm = 0;
#ifdef OS_WIN32
if(_stat(filename, &st) != 0) {
#else
if(stat(filename, &st) != 0) {
#endif /* OS_WIN32 */
SCLogError(SC_ERR_FOPEN, "Failed to stat file %s", filename);
exit(EXIT_FAILURE);
}
@ -579,16 +587,22 @@ int main(int argc, char **argv)
int list_runmodes = 0;
const char *runmode_custom_mode = NULL;
int daemon = 0;
#ifndef OS_WIN32
char *user_name = NULL;
char *group_name = NULL;
uint8_t do_setuid = FALSE;
uint8_t do_setgid = FALSE;
uint32_t userid = 0;
uint32_t groupid = 0;
#endif /* OS_WIN32 */
int build_info = 0;
char *log_dir;
#ifdef OS_WIN32
struct _stat buf;
#else
struct stat buf;
#endif /* OS_WIN32 */
sc_set_caps = FALSE;
@ -1083,9 +1097,21 @@ int main(int argc, char **argv)
/* Check for the existance of the default logging directory which we pick
* from suricata.yaml. If not found, shut the engine down */
if (ConfGet("default-log-dir", &log_dir) != 1)
if (ConfGet("default-log-dir", &log_dir) != 1) {
#ifdef OS_WIN32
log_dir = _getcwd(NULL, 0);
if (log_dir == NULL) {
log_dir = DEFAULT_LOG_DIR;
}
#else
log_dir = DEFAULT_LOG_DIR;
#endif /* OS_WIN32 */
}
#ifdef OS_WIN32
if (_stat(log_dir, &buf) != 0) {
#else
if (stat(log_dir, &buf) != 0) {
#endif /* OS_WIN32 */
SCLogError(SC_ERR_LOGDIR_CONFIG, "The logging directory \"%s\" "
"supplied by %s (default-log-dir) doesn't exist. "
"Shutting down the engine", log_dir, conf_filename);

@ -292,9 +292,9 @@ void AffinitySetupLoadFromConfig()
int AffinityGetNextCPU(ThreadsAffinityType *taf)
{
int ncpu = 0;
int iter = 0;
#if !defined OS_WIN32 && !defined __OpenBSD__
int iter = 0;
SCMutexLock(&taf->taf_mutex);
ncpu = taf->lcpu;
while (!CPU_ISSET(ncpu, &taf->cpu_set) && iter < 2) {

@ -45,7 +45,7 @@
#define SCByteSwap16(x) OSSwapInt16(x)
#define SCByteSwap32(x) OSSwapInt32(x)
#define SCByteSwap64(x) OSSwapInt64(x)
#elif OS_WIN32
#elif defined(__WIN32) || defined(_WIN32)
/* Quick & dirty solution, nothing seems to exist for this in Win32 API */
#define SCByteSwap16(x) \
((((x) & 0xff00) >> 8) \

@ -31,6 +31,11 @@
#define __UTIL_MEM_H__
#include "util-atomic.h"
#if defined(_WIN32) || defined(__WIN32)
#include "mm_malloc.h"
#endif
SC_ATOMIC_EXTERN(unsigned int, engine_stage);
/* Use this only if you want to debug memory allocation and free()
@ -207,6 +212,12 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
(void*)ptrmem; \
})
#define SCFree(a) ({ \
free(a); \
})
#if defined(__WIN32) || defined(_WIN32)
/** \brief wrapper for allocing aligned mem
* \param a size
* \param b alignement
@ -214,7 +225,8 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
#define SCMallocAligned(a, b) ({ \
void *ptrmem = NULL; \
\
if (posix_memalign(&ptrmem, (b), (a)) != 0) { \
ptrmem = _mm_malloc((a), (b)); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCMallocAligned(posix_memalign) failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)(a), (uintmax_t)(b)); \
@ -225,8 +237,35 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
(void*)ptrmem; \
})
#define SCFree(a) ({ \
free((a)); \
/** \brief Free aligned memory
*
* Not needed for mem alloc'd by posix_memalign,
* but for possible future use of _mm_malloc needing
* _mm_free.
*/
#define SCFreeAligned(a) ({ \
_mm_free(a); \
})
#else /* !win */
/** \brief wrapper for allocing aligned mem
* \param a size
* \param b alignement
*/
#define SCMallocAligned(a, b) ({ \
void *ptrmem = NULL; \
\
ptrmem = _mm_malloc((a), (b)); \
if (ptrmem == NULL) { \
if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\
SCLogError(SC_ERR_MEM_ALLOC, "SCMallocAligned(posix_memalign) failed: %s, while trying " \
"to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)a, (uintmax_t)b); \
SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \
exit(EXIT_FAILURE); \
} \
} \
(void*)ptrmem; \
})
/** \brief Free aligned memory
@ -239,6 +278,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage);
free((a)); \
})
#endif /* __WIN32 */
#endif /* DBG_MEM_ALLOC */

@ -37,17 +37,27 @@ void SCProtoNameInit()
FILE *fp = fopen(PROTO_FILE,"r");
if (fp != NULL) {
char line[200];
#if !defined(__WIN32) && !defined(_WIN32)
char *ptr = NULL;
#endif /* __WIN32 */
while(fgets(line, sizeof(line), fp) != NULL) {
if (line[0] == '#')
continue;
char *name = strtok_r(line," \t", &ptr);
if (name == NULL)
#if defined(__WIN32) || defined(_WIN32)
char *name = strtok(line," \t");
#else
char *name = strtok_r(line," \t", &ptr);
#endif /* __WIN32 */
if (name == NULL)
continue;
char *proto_ch = strtok_r(NULL," \t", &ptr);
#if defined(__WIN32) || defined(_WIN32)
char *proto_ch = strtok(NULL," \t");
#else
char *proto_ch = strtok_r(NULL," \t", &ptr);
#endif /* __WIN32 */
if (proto_ch == NULL)
continue;
@ -55,7 +65,12 @@ void SCProtoNameInit()
if (proto >= 255)
continue;
char *cname = strtok_r(NULL, " \t", &ptr);
#if defined(__WIN32) || defined(_WIN32)
char *cname = strtok(NULL, " \t");
#else
char *cname = strtok_r(NULL, " \t", &ptr);
#endif /* __WIN32 */
if (cname != NULL) {
known_proto[proto] = SCStrdup(cname);
} else {

@ -24,7 +24,11 @@
#ifndef __UTIL_PROTO_NAME_H__
#define __UTIL_PROTO_NAME_H__
#define PROTO_FILE "/etc/protocols"
#ifndef OS_WIN32
#define PROTO_FILE "/etc/protocols"
#else
#define PROTO_FILE "C:\\Windows\\system32\\drivers\\etc\\protocol"
#endif /* OS_WIN32 */
/** Lookup array to hold the information related to known protocol
* in /etc/protocols */

@ -27,8 +27,9 @@
#include "suricata-common.h"
#include "win32-misc.h"
#include "direct.h"
int setenv(const char *name, const char *value, int overwrite)
void setenv(const char *name, const char *value, int overwrite)
{
if (overwrite || NULL == getenv(name)) {
char *str = SCMalloc(strlen(name) + strlen(value) + 2);
@ -38,7 +39,7 @@ int setenv(const char *name, const char *value, int overwrite)
}
}
int unsetenv(const char *name)
void unsetenv(const char *name)
{
char *str = SCMalloc(strlen(name) + 2);
snprintf(str, strlen(name) + 1, "%s=", name);

@ -27,16 +27,14 @@
#define index strchr
#define rindex strrchr
#define strtok_r(s, d, p) strtok(s, d)
#define bzero(s, n) memset(s, 0, n)
#ifndef O_NOFOLLOW
#define O_NOFOLLOW 0
#endif /* O_NOFOLLOW */
int setenv(const char *name, const char *value, int overwrite);
int unsetenv(const char *name);
void setenv(const char *name, const char *value, int overwrite);
void unsetenv(const char *name);
const char* inet_ntop(int af, const void *src, char *dst, uint32_t cnt);
int inet_pton(int af, const char *src, void *dst);

Loading…
Cancel
Save