1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#ifndef NESSUS_NT_COMPAT__
#define NESSUS_NT_COMPAT__
/*
* This file is subject to the GPL
*
* (c) 1998 Renaud Deraison <deraison@worldnet.fr>
*
* ntcompat.h : redefinition of several system calls to provide
* NT compatibility to Nessus
*
*/
#ifdef NESSUSNT
#include <windows.h>
#endif
/*
* Thread management
*/
typedef int(*thread_func_t)(void *);
#ifdef USE_NT_THREADS
typedef HANDLE nthread_t;
#define EXIT(x) ExitThread(x)
#define _EXIT(x) ExitThread(x)
#define DO_EXIT(x) exit(x)
#define TERMINATE_THREAD(x) TerminateThread(x,0)
#endif /* US_NT_THREADS */
#ifdef USE_FORK_THREADS
typedef int nthread_t;
#define EXIT(x) exit(x)
#define _EXIT(x) _exit(x)
#define DO_EXIT(x) exit(x)
#define TERMINATE_THREAD(x) kill(x, SIGTERM)
#endif /* USE_FORK_THREADS */
#ifdef USE_PTHREADS
/*
* I hate pthreads
*/
typedef struct {
pthread_t thread;
pthread_mutex_t mutex;
int ready;
} _nthread_t,*nthread_t;
struct thread_args {
void * arg;
pthread_mutex_t * mutex;
thread_func_t func;
nthread_t thread;
};
#define EXIT(x) exit_pthread(x)
#define _EXIT(x) EXIT(x)
#define DO_EXIT(x) exit(x)
#ifdef HAVE_PTHREAD_CANCEL
#define TERMINATE_THREAD(x) {pthread_cancel(x->thread);pthread_detach(x->thread);}
#else
#warning "Your system lacks pthread_cancel() ! Using the pthreads is not recommanded"
#define TERMINATE_THREAD(x)
#endif /* HAVE_PTHREAD_CANCEL */
#endif /* USE_PTHREADS */
/*
* External libraries management
*/
#ifdef NESSUSNT
typedef HMODULE ext_library_t;
#define LOAD_FUNCTION(x,y) GetProcAddress(x,y)
#define LOAD_LIBRARY(x) LoadLibrary(x)
#define LIB_LAST_ERROR WSAGetLastError
#define CLOSE_LIBRARY(x) FreeLibrary(x)
#else
typedef void * ext_library_t;
#define LOAD_FUNCTION(x,y) dlsym(x,y)
#ifdef RTLD_NOW
#define LOAD_LIBRARY(x) dlopen(x,RTLD_NOW)
#else
#define LOAD_LIBRARY(x) dlopen(x, 1)
#endif /* not defined(RTLD_NOW) */
#define LIB_LAST_ERROR dlerror
#define CLOSE_LIBRARY(x) dlclose(x)
#endif /* defined(NESSUSNT) */
/*
* Misc. functions
*/
#ifdef NESSUSNT
#define getpid GetCurrentProcessId
#define ioctl(x,y,z) ioctlsocket(x,y,z)
#define signal(x,y)
#define alarm(x)
#define chmod(x,y)
#define getopt(x,y,z) <*error*> unless you define optarg, as well
typedef unsigned int u_int32_t;
typedef unsigned short n_short;
typedef unsigned short u_short;
typedef unsigned short u_int16_t;
typedef unsigned long n_time;
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#else
#define closesocket(x) close (x)
#endif /* defined(NESSUSNT) */
#ifndef NESSUSNT
#define print_error printf
#endif
#ifdef NESSUSNT
#define DllExport __declspec (dllexport)
#define DllImport __declspec (dllimport)
#define PlugExport DllExport
#ifdef EXPORTING
#define ExtFunc DllExport
#else
#define ExtFunc DllImport
#endif /* defined(EXPORTING) */
#else /* !NESSUSNT */
#define PlugExport
#define DllExport
#define DllImport
#define ExtFunc
#endif /* defined(NESSUSNT) */
#endif /* defined(NESSUS_NT_COMPAT_H) */
|