Fixed Win32 compilation, unit tests now compile.

remotes/origin/master-1.0.x
Jan Jezek 16 years ago committed by Victor Julien
parent d6c53b68bf
commit 4e72ccf987

@ -2956,7 +2956,7 @@ static int StreamTcpTest02 (void) {
Flow f;
ThreadVars tv;
StreamTcpThread stt;
u_int8_t payload[4];
uint8_t payload[4];
TCPHdr tcph;
memset (&p, 0, sizeof(Packet));
memset (&f, 0, sizeof(Flow));
@ -3173,7 +3173,7 @@ static int StreamTcpTest05 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[4];
uint8_t payload[4];
memset (&p, 0, sizeof(Packet));
memset (&f, 0, sizeof(Flow));
memset(&tv, 0, sizeof (ThreadVars));
@ -3319,7 +3319,7 @@ static int StreamTcpTest07 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[1] = {0x42};
uint8_t payload[1] = {0x42};
TCPVars tcpvars;
TCPOpt ts;
uint32_t data[2];
@ -3405,7 +3405,7 @@ static int StreamTcpTest08 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[1] = {0x42};
uint8_t payload[1] = {0x42};
TCPVars tcpvars;
TCPOpt ts;
uint32_t data[2];
@ -3493,7 +3493,7 @@ static int StreamTcpTest09 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[1] = {0x42};
uint8_t payload[1] = {0x42};
memset (&p, 0, sizeof(Packet));
memset (&f, 0, sizeof(Flow));
@ -4036,7 +4036,7 @@ static int StreamTcpTest14 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[4];
uint8_t payload[4];
struct in_addr addr;
IPV4Hdr ipv4h;
char os_policy_name[10] = "windows";
@ -4412,7 +4412,7 @@ static int StreamTcpTest15 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[4];
uint8_t payload[4];
struct in_addr addr;
IPV4Hdr ipv4h;
char os_policy_name[10] = "windows";
@ -4578,7 +4578,7 @@ static int StreamTcpTest16 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[4];
uint8_t payload[4];
struct in_addr addr;
IPV4Hdr ipv4h;
char os_policy_name[10] = "windows";
@ -4745,7 +4745,7 @@ static int StreamTcpTest17 (void) {
ThreadVars tv;
StreamTcpThread stt;
TCPHdr tcph;
u_int8_t payload[4];
uint8_t payload[4];
struct in_addr addr;
IPV4Hdr ipv4h;
char os_policy_name[10] = "windows";

@ -634,12 +634,20 @@ TmEcode TmThreadSetThreadPriority(ThreadVars *tv, int prio) {
void TmThreadSetPrio(ThreadVars *tv)
{
SCEnter();
#ifdef OS_WIN32
if (0 == SetThreadPriority(GetCurrentThread(), tv->thread_priority)) {
SCLogError(SC_ERR_THREAD_NICE_PRIO, "Error setting priority for thread %s: %s", tv->name, strerror(errno));
} else {
SCLogDebug("Priority set to %"PRId32" for thread %s", tv->thread_priority, tv->name);
}
#else
int ret = nice(tv->thread_priority);
if (ret == -1) {
SCLogError(SC_ERR_THREAD_NICE_PRIO, "Error setting nice value for thread %s: %s", tv->name, strerror(errno));
} else {
SCLogDebug("Nice value set to %"PRId32" for thread %s", tv->thread_priority, tv->name);
}
#endif /* OS_WIN32 */
}

@ -12,6 +12,8 @@
#include "util-fmemopen.h"
#include "suricata-common.h"
#ifdef OS_DARWIN
#define USE_FMEM_WRAPPER 1
#endif
@ -22,6 +24,33 @@
#ifdef USE_FMEM_WRAPPER
#ifdef OS_WIN32
/**
* \brief portable version of SCFmemopen for Windows works on top of real temp files
* \param buffer that holds the file content
* \param size of the file buffer
* \param mode mode of the file to open
* \retval pointer to the file; NULL if something is wrong
*/
FILE *SCFmemopen(void *buf, size_t size, const char *mode) {
char temppath[MAX_PATH - 13];
if (0 == GetTempPath(sizeof(temppath), temppath))
return NULL;
char filename[MAX_PATH + 1];
if (0 == GetTempFileName(temppath, "SC", 0, filename))
return NULL;
FILE *f = fopen(filename, "wb");
fwrite(buf, size, 1, f);
fclose(f);
return fopen(filename, mode);
}
#else
typedef struct SCFmem_ {
size_t pos;
size_t size;
@ -130,4 +159,6 @@ FILE *SCFmemopen(void *buf, size_t size, const char *mode) {
return funopen(mem, ReadFn, WriteFn, SeekFn, CloseFn);
}
#endif
#endif /* OS_WIN32 */
#endif /* USE_FMEM_WRAPPER */

@ -13,6 +13,10 @@
#define USE_FMEM_WRAPPER 1
#endif
#ifdef OS_WIN32
#define USE_FMEM_WRAPPER 1
#endif
#ifdef USE_FMEM_WRAPPER
FILE *SCFmemopen(void *, size_t, const char *);
#else

@ -3,6 +3,24 @@
#include "suricata-common.h"
#include "win32-misc.h"
int setenv(const char *name, const char *value, int overwrite)
{
if (overwrite || NULL == getenv(name)) {
char *str = malloc(strlen(name) + strlen(value) + 2);
sprintf(str, "%s=%s", name, value);
putenv(str);
free(str);
}
}
int unsetenv(const char *name)
{
char *str = malloc(strlen(name) + 2);
sprintf(str, "%s=", name);
putenv(str);
free(str);
}
const char* inet_ntop(int af, const void *src, char *dst, uint32_t cnt)
{
if (af == AF_INET)

@ -4,7 +4,12 @@
#define index strchr
#define rindex strrchr
#define strtok_r(s,d,p) strtok(s,d)
#define strtok_r(s, d, p) strtok(s, d)
#define bzero(s, n) memset(s, 0, n)
int setenv(const char *name, const char *value, int overwrite);
int 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