added defines MIN/MAX (uppercase) as replacement for min/max (lowercase); started...
[public/netxms.git] / include / nms_common.h
CommitLineData
08f16c05 1/*
7ac71e60 2** NetXMS - Network Management System
120bfcdf 3** Copyright (C) 2003-2014 Victor Kirhenshtein
cbcaf8c8
VK
4**
5** This program is free software; you can redistribute it and/or modify
68f384ea
VK
6** it under the terms of the GNU Lesser General Public License as published by
7** the Free Software Foundation; either version 3 of the License, or
cbcaf8c8
VK
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
68f384ea 15** You should have received a copy of the GNU Lesser General Public License
cbcaf8c8
VK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
28c329e2 19** File: nms_common.h
cbcaf8c8
VK
20**
21**/
22
23#ifndef _nms_common_h_
24#define _nms_common_h_
25
a1cb335b
VK
26#ifdef WIN32
27#ifndef _WIN32
28#define _WIN32
29#endif
30#endif
31
b40371d4 32#if !defined(_WIN32) && !defined(UNDER_CE)
e647245b 33
f62b7eab 34#include <config.h>
9c3bf7f4 35#if defined(WITH_OPENSSL) || defined(WITH_COMMONCRYPTO)
779c2678
VK
36#define _WITH_ENCRYPTION 1
37#endif
e647245b 38
15cf5acc 39#else /* _WIN32 */
e647245b 40
2c12edfc 41#ifndef UNDER_CE
15cf5acc 42#define _WITH_ENCRYPTION 1
3c15eedb 43#define WITH_OPENSSL 1
6c352bb5 44#define WITH_LDAP 1
f00612ba 45#if !defined(WINDOWS_ONLY) && !defined(_CRT_SECURE_NO_DEPRECATE)
be460d82 46#define _CRT_SECURE_NO_DEPRECATE
2c12edfc 47#endif
f00612ba 48#endif
e647245b 49
82b4c558 50#endif /* _WIN32 */
e647245b 51
f92a016a
VK
52#if HAVE_JEMALLOC_JEMALLOC_H
53#include <jemalloc/jemalloc.h>
54#endif
55
6b42b6f1 56#ifdef HAVE_STDARG_H
e647245b 57#include <stdarg.h>
6b42b6f1
AK
58#endif
59
f2fdf1b5 60#include <unicode.h>
e647245b 61
f2fdf1b5
VK
62#include <stdio.h>
63#include <string.h>
b50f1100 64#include <limits.h>
93b18807 65
b900a78b 66#include <netxms-version.h>
8606bcf9 67
5a82ecc7 68#if HAVE_WIDEC_H
5c0258d5 69#include <widec.h>
82b4c558 70#endif /* HAVE_WIDEC */
9068a8c6 71
bde67a1f
VK
72/**
73 * Define __64BIT__ if compiling for 64bit platform with Visual C++
74 */
c3561262 75#if defined(_M_X64) || defined(_M_IA64) || defined(__LP64__) || defined(__PPC64__) || defined(__x86_64__)
a731ec52
VK
76#ifndef __64BIT__
77#define __64BIT__
78#endif
79#endif
80
0cdf79a3
VK
81/**
82 * Wrappers for 64-bit integer constants
83 */
3a5657b9 84#if defined(__GNUC__) || defined(__HP_aCC) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
c61f5190
VK
85#define _LL(x) (x ## LL)
86#define _ULL(x) (x ## ULL)
7946bd7c
VK
87#elif defined(_MSC_VER)
88#define _LL(x) (x ## i64)
89#define _ULL(x) (x ## ui64)
c61f5190
VK
90#else
91#define _LL(x) (x)
92#define _ULL(x) (x)
93#endif
94
480e036b
VK
95/**
96 * Common constants
97 */
fb52d37d 98#define MAX_SECRET_LENGTH 64
a7d07192 99#define MAX_DB_STRING 256
999812c7 100#define MAX_PARAM_NAME 256
2589cc10 101#define MAX_CONFIG_VALUE 2000
cc8ce218 102#define MAX_COLUMN_NAME 64
5ad2167d 103#define MAX_DNS_NAME 256
d41268ba 104#define MAX_HELPDESK_REF_LEN 64
f33d5471 105#define MAX_PASSWORD 256
241541f4
VK
106#define MAX_SSH_LOGIN_LEN 64
107#define MAX_SSH_PASSWORD_LEN 64
967893bb 108#define GROUP_FLAG ((UINT32)0x80000000)
e44ac467 109
d772d0dd 110#define NETXMS_MAX_CIPHERS 6
15cf5acc 111#define NETXMS_RSA_KEYLEN 2048
fb52d37d 112
b50f1100 113#ifndef LLONG_MAX
c61f5190 114#define LLONG_MAX _LL(9223372036854775807)
b50f1100
VK
115#endif
116
117#ifndef LLONG_MIN
118#define LLONG_MIN (-LLONG_MAX - 1)
119#endif
120
121#ifndef ULLONG_MAX
c61f5190 122#define ULLONG_MAX _ULL(18446744073709551615)
b50f1100
VK
123#endif
124
05f256fe 125#ifndef EVENTLOG_DEBUG_TYPE
ccc34207
VK
126#define EVENTLOG_DEBUG_TYPE 0x0080
127#endif
128
e647245b
VK
129#define INVALID_INDEX 0xFFFFFFFF
130#define MD5_DIGEST_SIZE 16
131#define SHA1_DIGEST_SIZE 20
1718cc2a 132#define SHA256_DIGEST_SIZE 32
e647245b 133
9fa031cd 134#define FILE_BUFFER_SIZE 32768
135
664b42a4
VK
136/**
137 * Compatibility defines for C sources
138 */
07a7e06b 139#if !defined(__cplusplus) && !defined(CORTEX) && !HAVE_BOOL
ccc34207 140typedef int bool;
05f256fe
VK
141#endif
142
bde67a1f
VK
143/**
144 * Oracle Pro*C compatibility
145 */
909c0624 146#ifdef ORA_PROC
bde67a1f 147#undef BYTE
50456b1f 148#undef DWORD
bde67a1f
VK
149#endif
150
1de39d9e
VK
151/**
152 * Java class path separator character
153 */
154#ifdef _WIN32
155#define JAVA_CLASSPATH_SEPARATOR _T(';')
156#else
157#define JAVA_CLASSPATH_SEPARATOR _T(':')
158#endif
159
fb52d37d 160
bde67a1f 161/***** Platform dependent includes and defines *****/
fb52d37d 162
018fda4d 163#if defined(_WIN32) || defined(UNDER_CE)
076a55c4
VK
164
165/********** WINDOWS ********************/
e9246d26 166
96772780
VK
167#ifdef _MSC_FULL_VER
168#define __BUILD_VERSION_STRING(s,v) s v
169#define __STR_NX(x) #x
170#define __STR(x) __STR_NX(x)
171#define CPP_COMPILER_VERSION __STR(__BUILD_VERSION_STRING(Microsoft C/C++ Optimizing Compiler Version,_MSC_FULL_VER))
172#endif
173
e17fe9ab 174#ifndef _WIN32_WINNT
e4590ef2 175#define _WIN32_WINNT 0x0501
e17fe9ab 176#endif
f33479c8 177
36e44abe
VK
178#define WITH_IPV6 1
179
807c0ccc 180#define USE_BUNDLED_LIBTRE 1
df9812a9 181#define USE_BUNDLED_GETOPT 1
807c0ccc 182
3bf0df9f
VK
183#define SAFE_FGETWS_WITH_POPEN 1
184
c6491611 185#define FS_PATH_SEPARATOR _T("\\")
b07c50cc
VK
186#define FS_PATH_SEPARATOR_A "\\"
187#define FS_PATH_SEPARATOR_W L"\\"
c6491611
VK
188#define FS_PATH_SEPARATOR_CHAR _T('\\')
189
b79e8fed
VK
190#define WEXITSTATUS(x) (x)
191
a9bad162 192#if _MSC_VER >= 1310
c6491611
VK
193#define HAVE_SCPRINTF 1
194#define HAVE_VSCPRINTF 1
195#define HAVE_SCWPRINTF 1
196#define HAVE_VSCWPRINTF 1
2385d5d0 197#endif
f70fc197 198
a9bad162
VK
199#if _MSC_VER >= 1800
200#define HAVE_STRTOLL 1
201#define HAVE_STRTOULL 1
202#define HAVE_WCSTOLL 1
203#define HAVE_WCSTOULL 1
204#endif
205
342a701d
VK
206#define HAVE_SNPRINTF 1
207#define HAVE_VSNPRINTF 1
208
ecdf8898
VK
209#define HAVE_GETADDRINFO 1
210
d63aad11
VK
211#define HAVE_STDARG_H 1
212
8d4bb054
VK
213#define HAVE_ALLOCA 1
214
7768852d
VK
215#define HAVE_WCSLEN 1
216#define HAVE_WCSNCPY 1
669fcb92 217#define HAVE_WCSDUP 1
7b45b90d 218#define HAVE_WUTIME 1
7768852d 219
74540dab
VK
220#define HAVE_LIBCURL 1
221
c7850580
VK
222#define HAVE_DIRENT_D_TYPE 1
223
9caddb3c 224#include <winsock2.h>
510dd9c4 225#include <windows.h>
36e44abe 226#include <ws2tcpip.h>
d454fb4c 227#include <stdlib.h>
1ddf3f0c 228#include <malloc.h>
1dd2715c 229
a9bad162
VK
230#include <stdarg.h>
231#ifndef va_copy
232#define va_copy(x,y) (x = y)
233#endif
234#define HAVE_DECL_VA_COPY 1
235
018fda4d 236#ifndef UNDER_CE
a8d4cdee 237#include <sys/stat.h>
7b45b90d 238#include <sys/utime.h>
a8d4cdee 239#include <process.h>
1dd2715c 240#include <io.h>
3d1cb7d6 241#include <fcntl.h>
a23d8e0d 242#include <direct.h>
018fda4d 243#endif
91ab8f0a 244
37d62364
AK
245#ifndef S_IRUSR
246# define S_IRUSR 0400
247#endif
248#ifndef S_IWUSR
249# define S_IWUSR 0200
250#endif
1dd2715c 251
34576b56
VK
252#define snprintf _snprintf
253#define vsnprintf _vsnprintf
f83a0c3a
VK
254#define snwprintf _snwprintf
255#define vsnwprintf _vsnwprintf
c6491611
VK
256#define scprintf _scprintf
257#define vscprintf _vscprintf
258#define scwprintf _scwprintf
259#define vscwprintf _vscwprintf
34576b56
VK
260#define popen _popen
261#define pclose _pclose
34576b56
VK
262#define stricmp _stricmp
263#define strnicmp _strnicmp
c90ea787
VK
264#define wcsicmp _wcsicmp
265#define wcsnicmp _wcsnicmp
3da622d4 266#define strlwr(s) _strlwr(s)
34576b56 267#define strupr(s) _strupr(s)
70af47c2 268#define putenv(s) _putenv(s)
34576b56
VK
269#define fileno(f) _fileno(f)
270#define chdir(p) _chdir(p)
271#define mkdir(p,m) _mkdir(p,m)
ccc34207 272#define lseek(f,o,w) _lseek(f,o,w)
34576b56 273#define unlink(x) _unlink(x)
d4c266b6 274
967893bb 275typedef UINT64 QWORD; // for compatibility
670c7f3d 276typedef int socklen_t;
1edb2dab 277typedef long pid_t;
734e79a8
VK
278typedef LONG ssize_t;
279
280typedef signed __int8 int8_t;
281typedef signed __int16 int16_t;
282typedef signed __int32 int32_t;
283typedef signed __int64 int64_t;
284typedef unsigned __int8 uint8_t;
285typedef unsigned __int16 uint16_t;
286typedef unsigned __int32 uint32_t;
08f16c05 287typedef unsigned __int64 uint64_t;
e9246d26 288
8b1fedb2 289#define INT64_FMT _T("%I64d")
dda7c270 290#define INT64_FMTA "%I64d"
511bea22 291#define INT64_FMTW L"%I64d"
8b1fedb2 292#define UINT64_FMT _T("%I64u")
dda7c270 293#define UINT64_FMTA "%I64u"
511bea22 294#define UINT64_FMTW L"%I64u"
8b1fedb2 295#define UINT64X_FMT(m) _T("%") m _T("I64X")
0b514e86 296#if defined(__64BIT__) || (_MSC_VER > 1300)
34576b56 297#define TIME_T_FMT _T("%I64u")
967893bb 298#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 299#else
34576b56 300#define TIME_T_FMT _T("%u")
967893bb 301#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 302#endif
cb53cb15 303
64a055a2
VK
304#ifndef __clang__
305
3c15eedb
VK
306#define HAVE_DECL_BSWAP_16 1
307#define HAVE_DECL_BSWAP_32 1
308#define HAVE_DECL_BSWAP_64 1
309
98a314d9
VK
310#define bswap_16(n) _byteswap_ushort(n)
311#define bswap_32(n) _byteswap_ulong(n)
312#define bswap_64(n) _byteswap_uint64(n)
3c15eedb 313
64a055a2
VK
314#endif
315
8f7e2482
VK
316// Socket compatibility
317#define SHUT_RD 0
318#define SHUT_WR 1
319#define SHUT_RDWR 2
320
1ddf3f0c
VK
321#define SetSocketReuseFlag(s) { \
322 BOOL val = TRUE; \
323 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(BOOL)); \
324}
325#define SetSocketExclusiveAddrUse(s) { \
326 BOOL val = TRUE; \
327 setsockopt(s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *)&val, sizeof(BOOL)); \
328}
a3c76aba 329#define SELECT_NFDS(x) ((int)(x))
19121a38
VK
330#define SetSocketNonBlocking(s) { \
331 u_long one = 1; \
332 ioctlsocket(s, FIONBIO, &one); \
333}
734e79a8
VK
334#define SetSocketBlocking(s) { \
335 u_long zero = 0; \
336 ioctlsocket(s, FIONBIO, &zero); \
337}
4a36d30c
VK
338#define SetSocketNoDelay(s) { \
339 BOOL val = TRUE; \
340 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(BOOL)); \
341}
08f16c05 342#define SetSocketBroadcast(s) { \
343 BOOL val = TRUE; \
344 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&val, sizeof(BOOL)); \
345}
be45f318 346
55b33d4c
VK
347#ifdef UNDER_CE
348#define O_RDONLY 0x0004
349#define O_WRONLY 0x0001
350#define O_RDWR 0x0002
351#define O_CREAT 0x0100
352#define O_EXCL 0x0200
353#define O_TRUNC 0x0800
354#endif
355
3973f74b 356#if !defined(UNDER_CE)
c1099678 357#define HAVE_LIBEXPAT 1
1bb6b449
VK
358#endif
359
058bf6fc
VK
360#define XMPP_SUPPORTED 1
361
c1099678
VK
362#define HAVE_LOCALE_H 1
363#define HAVE_SETLOCALE 1
364
8ff13508
VK
365// Use Win32 API instead of msvcrt for memory allocation
366#ifdef USE_WIN32_HEAP
367
368#define malloc(n) HeapAlloc(GetProcessHeap(), 0, n)
369#define realloc(p, n) (((p) == NULL) ? HeapAlloc(GetProcessHeap(), 0, n) : HeapReAlloc(GetProcessHeap(), 0, p, n))
370#define free(p) HeapFree(GetProcessHeap(), 0, p)
a65409fe 371#define _tcsdup(s) nx__tcsdup(s)
8ff13508
VK
372#define wcsdup(s) nx_wcsdup(s)
373
374#undef _tcsdup
375#ifdef UNICODE
376#define _tcsdup nx_wcsdup
377#else
378#define _tcsdup nx_strdup
379#endif
380
381#else
382
383#define strdup _strdup
384#define wcsdup _wcsdup
385
386#endif
387
82b4c558 388#else /* not _WIN32 */
076a55c4
VK
389
390/*********** UNIX *********************/
cbcaf8c8 391
28c329e2 392#ifndef PREFIX
124528cc
VK
393#ifdef UNICODE
394#define PREFIX L"/usr/local"
395#else
28c329e2 396#define PREFIX "/usr/local"
124528cc 397#endif
28c329e2
VK
398#warning Installation prefix not defined, defaulting to /usr/local
399#endif
400
5456cd6d
VK
401#if HAVE_STDBOOL_H
402#include <stdbool.h>
403#endif
404
ccfe2ba0
VK
405#if HAVE_ALLOCA_H
406#include <alloca.h>
407#endif
408
3e39fcde
VK
409#if HAVE_WCHAR_H
410#include <wchar.h>
411#endif
3e39fcde 412
8b86c5dc
VK
413#if HAVE_WCTYPE_H
414#include <wctype.h>
415#endif
416
e2e3ce85
VK
417// Fix for wcs* functions visibility in Solaris 11
418#if defined(__sun) && (__cplusplus >= 199711L)
419#if HAVE_WCSDUP
420using std::wcsdup;
421#endif
422#if HAVE_WCSCASECMP
423using std::wcscasecmp;
424#endif
425#if HAVE_WCSNCASECMP
426using std::wcsncasecmp;
427#endif
428#endif
429
5bdbe3df
VK
430#include <errno.h>
431
636da5f3 432#define FS_PATH_SEPARATOR _T("/")
b07c50cc
VK
433#define FS_PATH_SEPARATOR_A "/"
434#define FS_PATH_SEPARATOR_W L"/"
636da5f3 435#define FS_PATH_SEPARATOR_CHAR _T('/')
f70fc197 436
e31784c0 437#if HAVE_UNISTD_H
62d8cc27 438#include <unistd.h>
e31784c0
VK
439#endif
440
441#if HAVE_STDLIB_H
62d8cc27 442#include <stdlib.h>
e31784c0
VK
443#endif
444
445#if HAVE_SYS_TYPES_H
7e679c4b 446#include <sys/types.h>
e31784c0
VK
447#endif
448
7b45b90d 449#if HAVE_UTIME_H
450#include <utime.h>
451#endif
452
521d90e7
VK
453#if HAVE_SYS_INT_TYPES_H
454#include <sys/int_types.h>
455#endif
456
cc4c6659
VK
457#if HAVE_SYS_STAT_H
458#include <sys/stat.h>
459#endif
460
e31784c0 461#if HAVE_SYS_SOCKET_H
62d8cc27 462#include <sys/socket.h>
e31784c0
VK
463#endif
464
465#if HAVE_SYS_SELECT_H
62d8cc27 466#include <sys/select.h>
e31784c0
VK
467#endif
468
469#if HAVE_NETINET_IN_H
7e679c4b 470#include <netinet/in.h>
e31784c0
VK
471#endif
472
e9c8eb1d
VK
473#if HAVE_NETINET_TCP_H
474#include <netinet/tcp.h>
475#endif
476
ca6ad6bb
VK
477#if HAVE_NET_NH_H
478#include <net/nh.h>
479#endif
480
e31784c0 481#if HAVE_ARPA_INET_H
62d8cc27 482#include <arpa/inet.h>
e31784c0
VK
483#endif
484
485#if HAVE_NETDB_H
93e601e5 486#include <netdb.h>
e31784c0 487#endif
7e679c4b 488
cc4c6659 489#if HAVE_FCNTL_H
4507063f 490#include <fcntl.h>
cc4c6659
VK
491#endif
492
493#include <dirent.h>
d6a35a77 494
cd4c8ca3
VK
495#if _USE_GNU_PTH
496#include <pth.h>
0c78603d
VK
497#else
498#include <pthread.h>
cd4c8ca3
VK
499#endif
500
efdaffe4
VK
501#ifdef __IBMCPP__
502#include <builtins.h>
503#endif
504
ef8a3c32
VK
505#ifdef __minix
506#undef HAVE_ITOA /* Minix has non-compatible itoa() */
507#undef HAVE_GETHOSTBYNAME2_R
508#endif
509
0f8cd7ae
VK
510#include <sys/socket.h>
511#include <sys/un.h>
512
eefe7d68 513typedef int BOOL;
678de2bc 514#if (SIZEOF_LONG == 4)
efdaffe4
VK
515#if (SIZEOF_INT == 4)
516typedef int INT32;
517typedef unsigned int UINT32;
518#else
967893bb
VK
519typedef long INT32;
520typedef unsigned long UINT32;
efdaffe4 521#endif
3c3d2729 522#undef __64BIT__
678de2bc 523#else
967893bb
VK
524typedef int INT32;
525typedef unsigned int UINT32;
3c3d2729
VK
526#ifndef __64BIT__
527#define __64BIT__
528#endif
678de2bc 529#endif
967893bb
VK
530typedef unsigned short UINT16;
531typedef short INT16;
cbcaf8c8 532typedef unsigned char BYTE;
967893bb 533typedef INT32 LONG; // for compatibility
50456b1f 534typedef UINT32 DWORD; // for compatibility
967893bb 535typedef UINT16 WORD; // for compatibility
cbcaf8c8 536typedef void * HANDLE;
3cf35ea6 537typedef void * HMODULE;
521d90e7 538
8b86c5dc
VK
539#if !HAVE_MODE_T
540typedef int mode_t;
541#endif
542
628013e1
VK
543// We have to use long as INT64 on HP-UX - otherwise
544// there will be compilation errors because of type redefinition in
545// system includes
546#ifdef _HPUX
547
548#ifdef __LP64__
549typedef long INT64;
550typedef unsigned long UINT64;
551#else
552typedef long long INT64;
553typedef unsigned long long UINT64;
554#endif
555
556#else /* _HPUX */
557
6e383343 558#if HAVE_LONG_LONG && (SIZEOF_LONG_LONG == 8)
51128b42
VK
559typedef long long INT64;
560#elif HAVE_INT64_T
7e679c4b 561typedef int64_t INT64;
6e383343
VK
562#elif SIZEOF_LONG == 8
563typedef long INT64;
521d90e7
VK
564#else
565#error Target system does not have signed 64bit integer type
566#endif
567
6e383343 568#if HAVE_UNSIGNED_LONG_LONG && (SIZEOF_LONG_LONG == 8)
967893bb 569typedef unsigned long long UINT64;
51128b42 570#elif HAVE_UINT64_T
967893bb 571typedef uint64_t UINT64;
521d90e7 572#elif HAVE_U_INT64_T
967893bb 573typedef u_int64_t UINT64;
6e383343
VK
574#elif SIZEOF_LONG == 8
575typedef unsigned long UINT64;
521d90e7
VK
576#else
577#error Target system does not have unsigned 64bit integer type
578#endif
628013e1
VK
579
580#endif /* _HPUX */
581
967893bb 582typedef UINT64 QWORD; // for compatibility
7e679c4b 583
8b1fedb2 584#define INT64_FMT _T("%lld")
dda7c270
VK
585#define INT64_FMTW L"%lld"
586#define INT64_FMTA "%lld"
8b1fedb2 587#define UINT64_FMT _T("%llu")
dda7c270
VK
588#define UINT64_FMTW L"%llu"
589#define UINT64_FMTA "%llu"
8b1fedb2 590#define UINT64X_FMT(m) _T("%") m _T("llX")
1094818a 591#ifdef __64BIT__
8b1fedb2 592#define TIME_T_FMT _T("%llu")
967893bb 593#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 594#else
8b1fedb2 595#define TIME_T_FMT _T("%u")
967893bb 596#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 597#endif
cbcaf8c8 598
cd4c8ca3 599#ifndef TRUE
cbcaf8c8 600#define TRUE 1
cd4c8ca3
VK
601#endif
602#ifndef FALSE
cbcaf8c8 603#define FALSE 0
cd4c8ca3 604#endif
cbcaf8c8 605
efc49272
VK
606// Some systems may define true and false which may break overloaded functions
607#ifdef __cplusplus
608#undef true
609#undef false
610#endif
611
a5de3def 612#ifndef MAX_PATH
120bfcdf
VK
613#ifdef PATH_MAX
614#define MAX_PATH PATH_MAX
615#else
616#define MAX_PATH 1024
617#endif
a5de3def
VK
618#endif
619
c90ea787
VK
620// Windows compatibility layer for standard C I/O functions
621#ifdef __cplusplus
622
623inline int _access(const char *pathname, int mode) { return ::access(pathname, mode); }
624inline int _open(const char *pathname, int flags) { return ::open(pathname, flags); }
625inline int _open(const char *pathname, int flags, mode_t mode) { return ::open(pathname, flags, mode); }
626inline ssize_t _read(int fd, void *buf, size_t count) { return ::read(fd, buf, count); }
627inline ssize_t _write(int fd, const void *buf, size_t count) { return ::write(fd, buf, count); }
628inline int _close(int fd) { return ::close(fd); }
629
630#else
631
632#define _access(p, m) access((p), (m))
ee088bd0
VK
633#define _open open
634#define _close(f) close(f)
635#define _read(f, b, l) read((f), (b), (l))
c90ea787
VK
636#define _write(f, b, l) write((f), (b), (l))
637#define _close(f) close(f)
638
639#endif
ee088bd0 640
77312b6f 641// Socket compatibility
7e679c4b
AK
642typedef int SOCKET;
643
eae56922 644#define closesocket(x) _close(x)
77312b6f
VK
645#define WSAGetLastError() (errno)
646
f0ce9811 647#define WSAEINTR EINTR
a7a0c5cc 648#define WSAEWOULDBLOCK EWOULDBLOCK
1743a67a 649#define WSAEINPROGRESS EINPROGRESS
a2069340 650#define WSAESHUTDOWN ESHUTDOWN
f0ce9811 651#define INVALID_SOCKET (-1)
62d8cc27 652
be45f318
VK
653#define SetSocketReuseFlag(sd) { \
654 int nVal = 1; \
655 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&nVal, \
656 (socklen_t)sizeof(nVal)); \
657}
658
1ddf3f0c
VK
659#define SetSocketExclusiveAddrUse(s)
660
19121a38
VK
661#define SetSocketNonBlocking(s) { \
662 int f = fcntl(s, F_GETFL); \
663 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
664}
665
4a36d30c
VK
666#define SetSocketNoDelay(s) { \
667 int val = 1; \
668 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const void *)&val, sizeof(int)); \
669}
670
08f16c05 671#define SetSocketBroadcast(s) { \
672 int val = 1; \
673 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const void *)&val, sizeof(int)); \
674}
675
a3c76aba
VK
676#define SELECT_NFDS(x) (x)
677
cd4c8ca3 678#if !(HAVE_SOCKLEN_T) && !defined(_USE_GNU_PTH)
8ecf30ab 679typedef unsigned int socklen_t;
3c2bbe5f
VK
680#endif
681
0f8cd7ae
VK
682#ifndef SUN_LEN
683#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
684#endif
685
17d715ba 686// Shared library suffix
2b479c92 687#ifndef SHLIB_SUFFIX
17d715ba 688#if defined(_HPUX) && !defined(__64BIT__)
2b479c92 689#define SHLIB_SUFFIX _T(".sl")
17d715ba 690#else
2b479c92 691#define SHLIB_SUFFIX _T(".so")
17d715ba
VK
692#endif
693#endif
694
4383fcad
AK
695typedef struct hostent HOSTENT;
696
ce7565e7
VK
697#if HAVE_DECL___VA_COPY && !HAVE_DECL_VA_COPY
698#define HAVE_DECL_VA_COPY 1
699#define va_copy(d,s) __va_copy(d,s)
700#endif
701
8d9f0998
VK
702#endif /* _WIN32 */
703
90d8fac8
VK
704/**
705 * Value used to indicate invalid pointer where NULL is not appropriate
706 */
a731ec52
VK
707#ifdef __64BIT__
708#define INVALID_POINTER_VALUE ((void *)_ULL(0xFFFFFFFFFFFFFFFF))
709#else
710#define INVALID_POINTER_VALUE ((void *)0xFFFFFFFF)
711#endif
712
90d8fac8
VK
713/**
714 * Casting between pointer and 32-bit integer
715 */
c88a8bc1 716#ifdef __64BIT__
967893bb
VK
717#define CAST_FROM_POINTER(p, t) ((t)((UINT64)(p)))
718#define CAST_TO_POINTER(v, t) ((t)((UINT64)(v)))
c88a8bc1 719#else
a23d8e0d
VK
720#define CAST_FROM_POINTER(p, t) ((t)(p))
721#define CAST_TO_POINTER(v, t) ((t)(v))
c88a8bc1
VK
722#endif
723
bde67a1f
VK
724/**
725 * open() flags compatibility
726 */
8d9f0998
VK
727#ifndef O_BINARY
728#define O_BINARY 0
cbcaf8c8
VK
729#endif
730
bde67a1f
VK
731/**
732 * Windows-specific structures for non-Windows platforms
08f16c05 733 */
1d410d50
VK
734#ifndef _WIN32
735
736typedef struct tagPOINT
737{
738 int x;
739 int y;
740} POINT;
741
742#endif
743
bde67a1f
VK
744/**
745 * Event log severity codes
746 */
9c02b362 747#ifndef _WIN32
ccc34207
VK
748#define EVENTLOG_SUCCESS 0x0000
749#define EVENTLOG_ERROR_TYPE 0x0001
750#define EVENTLOG_WARNING_TYPE 0x0002
751#define EVENTLOG_INFORMATION_TYPE 0x0004
752#define EVENTLOG_AUDIT_SUCCESS 0x0008
753#define EVENTLOG_AUDIT_FAILURE 0x0010
9c02b362
VK
754#endif /* _WIN32 */
755
203e9d8a
VK
756#define NXLOG_DEBUG EVENTLOG_DEBUG_TYPE
757#define NXLOG_INFO EVENTLOG_INFORMATION_TYPE
758#define NXLOG_WARNING EVENTLOG_WARNING_TYPE
759#define NXLOG_ERROR EVENTLOG_ERROR_TYPE
760
bde67a1f
VK
761/**
762 * Interface types
763 */
020559de
VK
764#define IFTYPE_OTHER 1
765#define IFTYPE_REGULAR1822 2
766#define IFTYPE_HDH1822 3
767#define IFTYPE_DDN_X25 4
768#define IFTYPE_RFC877_X25 5
769#define IFTYPE_ETHERNET_CSMACD 6
770#define IFTYPE_ISO88023_CSMACD 7
771#define IFTYPE_ISO88024_TOKENBUS 8
772#define IFTYPE_ISO88025_TOKENRING 9
773#define IFTYPE_ISO88026_MAN 10
774#define IFTYPE_STARLAN 11
775#define IFTYPE_PROTEON_10MBIT 12
776#define IFTYPE_PROTEON_80MBIT 13
777#define IFTYPE_HYPERCHANNEL 14
778#define IFTYPE_FDDI 15
779#define IFTYPE_LAPB 16
780#define IFTYPE_SDLC 17
781#define IFTYPE_DS1 18
782#define IFTYPE_E1 19
783#define IFTYPE_BASIC_ISDN 20
784#define IFTYPE_PRIMARY_ISDN 21
785#define IFTYPE_PROP_PTP_SERIAL 22
786#define IFTYPE_PPP 23
787#define IFTYPE_SOFTWARE_LOOPBACK 24
788#define IFTYPE_EON 25
789#define IFTYPE_ETHERNET_3MBIT 26
790#define IFTYPE_NSIP 27
791#define IFTYPE_SLIP 28
792#define IFTYPE_ULTRA 29
793#define IFTYPE_DS3 30
794#define IFTYPE_SMDS 31
795#define IFTYPE_FRAME_RELAY 32
796#define IFTYPE_RS232 33
797#define IFTYPE_PARA 34
798#define IFTYPE_ARCNET 35
799#define IFTYPE_ARCNET_PLUS 36
800#define IFTYPE_ATM 37
801#define IFTYPE_MIOX25 38
802#define IFTYPE_SONET 39
803#define IFTYPE_X25PLE 40
804#define IFTYPE_ISO88022LLC 41
805#define IFTYPE_LOCALTALK 42
806#define IFTYPE_SMDS_DXI 43
807#define IFTYPE_FRAME_RELAY_SERVICE 44
808#define IFTYPE_V35 45
809#define IFTYPE_HSSI 46
810#define IFTYPE_HIPPI 47
811#define IFTYPE_MODEM 48
812#define IFTYPE_AAL5 49
813#define IFTYPE_SONET_PATH 50
814#define IFTYPE_SONET_VT 51
815#define IFTYPE_SMDS_ICIP 52
816#define IFTYPE_PROP_VIRTUAL 53
817#define IFTYPE_PROP_MULTIPLEXOR 54
818#define IFTYPE_IEEE80212 55
819#define IFTYPE_FIBRECHANNEL 56
820#define IFTYPE_HIPPIINTERFACE 57
821#define IFTYPE_FRAME_RELAY_INTERCONNECT 58
822#define IFTYPE_AFLANE8023 59
823#define IFTYPE_AFLANE8025 60
824#define IFTYPE_CCTEMUL 61
825#define IFTYPE_FAST_ETHERNET 62
826#define IFTYPE_ISDN 63
827#define IFTYPE_V11 64
828#define IFTYPE_V36 65
829#define IFTYPE_G703_AT64K 66
830#define IFTYPE_G703_AT2MB 67
831#define IFTYPE_QLLC 68
832#define IFTYPE_FASTETHERFX 69
833#define IFTYPE_CHANNEL 70
834#define IFTYPE_IEEE80211 71
835#define IFTYPE_IBM370_PARCHAN 72
836#define IFTYPE_ESCON 73
837#define IFTYPE_DLSW 74
838#define IFTYPE_ISDNS 75
839#define IFTYPE_ISDNU 76
840#define IFTYPE_LAPD 77
841#define IFTYPE_IPSWITCH 78
842#define IFTYPE_RSRB 79
843#define IFTYPE_ATMLOGICAL 80
844#define IFTYPE_DS0 81
845#define IFTYPE_DS0_BUNDLE 82
846#define IFTYPE_BSC 83
847#define IFTYPE_ASYNC 84
848#define IFTYPE_CNR 85
849#define IFTYPE_ISO88025DTR 86
850#define IFTYPE_EPLRS 87
851#define IFTYPE_ARAP 88
852#define IFTYPE_PROPCNLS 89
853#define IFTYPE_HOSTPAD 90
854#define IFTYPE_TERMPAD 91
855#define IFTYPE_FRAME_RELAY_MPI 92
856#define IFTYPE_X213 93
857#define IFTYPE_ADSL 94
858#define IFTYPE_RADSL 95
859#define IFTYPE_SDSL 96
860#define IFTYPE_VDSL 97
861#define IFTYPE_ISO88025CRFPINT 98
862#define IFTYPE_MYRINET 99
863#define IFTYPE_VOICEEM 100
864#define IFTYPE_VOICEFXO 101
865#define IFTYPE_VOICEFXS 102
866#define IFTYPE_VOICEENCAP 103
867#define IFTYPE_VOICEOVERIP 104
868#define IFTYPE_ATMDXI 105
869#define IFTYPE_ATMFUNI 106
870#define IFTYPE_ATMIMA 107
871#define IFTYPE_PPPMULTILINKBUNDLE 108
872#define IFTYPE_IPOVERCDLC 109
873#define IFTYPE_IPOVERCLAW 110
874#define IFTYPE_STACKTOSTACK 111
875#define IFTYPE_VIRTUAL_IP_ADDRESS 112
876#define IFTYPE_MPC 113
877#define IFTYPE_IPOVERATM 114
878#define IFTYPE_ISO88025FIBER 115
879#define IFTYPE_TDLC 116
880#define IFTYPE_GIGABIT_ETHERNET 117
881#define IFTYPE_HDLC 118
882#define IFTYPE_LAPF 119
883#define IFTYPE_V37 120
884#define IFTYPE_X25MLP 121
885#define IFTYPE_X25_HUNT_GROUP 122
886#define IFTYPE_TRANSPHDLC 123
887#define IFTYPE_INTERLEAVE 124
888#define IFTYPE_FAST 125
889#define IFTYPE_IP 126
890#define IFTYPE_DOCSCABLE_MACLAYER 127
891#define IFTYPE_DOCSCABLE_DOWNSTREAM 128
892#define IFTYPE_DOCSCABLE_UPSTREAM 129
893#define IFTYPE_A12MPPSWITCH 130
894#define IFTYPE_TUNNEL 131
895#define IFTYPE_COFFEE 132
896#define IFTYPE_CES 133
897#define IFTYPE_ATM_SUBINTERFACE 134
898#define IFTYPE_L2VLAN 135
899#define IFTYPE_L3IPVLAN 136
900#define IFTYPE_L3IPXVLAN 137
901#define IFTYPE_DIGITAL_POWERLINE 138
902#define IFTYPE_MEDIAMAIL_OVER_IP 139
903#define IFTYPE_DTM 140
904#define IFTYPE_DCN 141
905#define IFTYPE_IPFORWARD 142
906#define IFTYPE_MSDSL 143
907#define IFTYPE_IEEE1394 144
908#define IFTYPE_GSN 145
909#define IFTYPE_DVBRCC_MACLAYER 146
910#define IFTYPE_DVBRCC_DOWNSTREAM 147
911#define IFTYPE_DVBRCC_UPSTREAM 148
912#define IFTYPE_ATM_VIRTUAL 149
913#define IFTYPE_MPLS_TUNNEL 150
914#define IFTYPE_SRP 151
915#define IFTYPE_VOICE_OVER_ATM 152
916#define IFTYPE_VOICE_OVER_FRAME_RELAY 153
917#define IFTYPE_IDSL 154
918#define IFTYPE_COMPOSITE_LINK 155
919#define IFTYPE_SS7_SIGLINK 156
920#define IFTYPE_PROPWIRELESSP2P 157
921#define IFTYPE_FRFORWARD 158
922#define IFTYPE_RFC1483 159
923#define IFTYPE_USB 160
924#define IFTYPE_IEEE8023ADLAG 161
925#define IFTYPE_BGP_POLICY_ACCOUNTING 162
926#define IFTYPE_FRF16MFR_BUNDLE 163
927#define IFTYPE_H323_GATEKEEPER 164
928#define IFTYPE_H323_PROXY 165
929#define IFTYPE_MPLS 166
930#define IFTYPE_MFSIGLINK 167
931#define IFTYPE_HDSL2 168
932#define IFTYPE_SHDSL 169
933#define IFTYPE_DS1FDL 170
934#define IFTYPE_POS 171
935#define IFTYPE_DVBASI_IN 172
936#define IFTYPE_DVBASI_OUT 173
937#define IFTYPE_PLC 174
938#define IFTYPE_NFAS 175
939#define IFTYPE_TR008 176
940#define IFTYPE_GR303RDT 177
941#define IFTYPE_GR303IDT 178
942#define IFTYPE_ISUP 179
943#define IFTYPE_PROPDOCSWIRELESSMACLAYER 180
944#define IFTYPE_PROPDOCSWIRELESSDOWNSTREAM 181
945#define IFTYPE_PROPDOCSWIRELESSUPSTREAM 182
946#define IFTYPE_HIPERLAN2 183
947#define IFTYPE_PROPBWAP2MP 184
948#define IFTYPE_SONET_OVERHEAD_CHANNEL 185
949#define IFTYPE_DW_OVERHEAD_CHANNEL 186
950#define IFTYPE_AAL2 187
951#define IFTYPE_RADIOMAC 188
952#define IFTYPE_ATMRADIO 189
953#define IFTYPE_IMT 190
954#define IFTYPE_MVL 191
955#define IFTYPE_REACHDSL 192
956#define IFTYPE_FRDLCIENDPT 193
957#define IFTYPE_ATMVCIENDPT 194
958#define IFTYPE_OPTICAL_CHANNEL 195
959#define IFTYPE_OPTICAL_TRANSPORT 196
960#define IFTYPE_PROPATM 197
961#define IFTYPE_VOICE_OVER_CABLE 198
962#define IFTYPE_INFINIBAND 199
963#define IFTYPE_TELINK 200
964#define IFTYPE_Q2931 201
965#define IFTYPE_VIRTUALTG 202
966#define IFTYPE_SIPTG 203
967#define IFTYPE_SIPSIG 204
968#define IFTYPE_DOCSCABLEUPSTREAMCHANNEL 205
969#define IFTYPE_ECONET 206
970#define IFTYPE_PON155 207
971#define IFTYPE_PON622 208
972#define IFTYPE_BRIDGE 209
973#define IFTYPE_LINEGROUP 210
974#define IFTYPE_VOICEEMFGD 211
975#define IFTYPE_VOICEFGDEANA 212
976#define IFTYPE_VOICEDID 213
977#define IFTYPE_MPEG_TRANSPORT 214
978#define IFTYPE_SIXTOFOUR 215
979#define IFTYPE_GTP 216
980#define IFTYPE_PDNETHERLOOP1 217
981#define IFTYPE_PDNETHERLOOP2 218
982#define IFTYPE_OPTICAL_CHANNEL_GROUP 219
983#define IFTYPE_HOMEPNA 220
984#define IFTYPE_GFP 221
985#define IFTYPE_CISCO_ISL_VLAN 222
986#define IFTYPE_ACTELIS_METALOOP 223
987#define IFTYPE_FCIPLINK 224
988#define IFTYPE_RPR 225
989#define IFTYPE_QAM 226
990#define IFTYPE_LMP 227
991#define IFTYPE_CBLVECTASTAR 228
992#define IFTYPE_DOCSCABLEMCMTSDOWNSTREAM 229
993#define IFTYPE_ADSL2 230
994#define IFTYPE_MACSECCONTROLLEDIF 231
995#define IFTYPE_MACSECUNCONTROLLEDIF 232
996#define IFTYPE_AVICIOPTICALETHER 233
997#define IFTYPE_ATM_BOND 234
998#define IFTYPE_VOICEFGDOS 235
999#define IFTYPE_MOCA_VERSION1 236
1000#define IFTYPE_IEEE80216WMAN 237
1001#define IFTYPE_ADSL2PLUS 238
1002#define IFTYPE_DVBRCSMACLAYER 239
1003#define IFTYPE_DVBTDM 240
1004#define IFTYPE_DVBRCSTDMA 241
1005#define IFTYPE_X86LAPS 242
1006#define IFTYPE_WWANPP 243
1007#define IFTYPE_WWANPP2 244
1008#define IFTYPE_VOICEEBS 245
1009#define IFTYPE_IFPWTYPE 246
1010#define IFTYPE_ILAN 247
1011#define IFTYPE_PIP 248
1012#define IFTYPE_ALUELP 249
1013#define IFTYPE_GPON 250
1014#define IFTYPE_VDSL2 251
1015#define IFTYPE_CAPWAP_DOT11_PROFILE 252
1016#define IFTYPE_CAPWAP_DOT11_BSS 253
1017#define IFTYPE_CAPWAP_WTP_VIRTUAL_RADIO 254
1018#define IFTYPE_BITS 255
1019#define IFTYPE_DOCSCABLEUPSTREAMRFPORT 256
1020#define IFTYPE_CABLEDOWNSTREAMRFPORT 257
1021#define IFTYPE_VMWARE_VIRTUAL_NIC 258
1022#define IFTYPE_IEEE802154 259
1023#define IFTYPE_OTNODU 260
1024#define IFTYPE_OTNOTU 261
1025#define IFTYPE_IFVFITYPE 262
1026#define IFTYPE_G9981 263
1027#define IFTYPE_G9982 264
1028#define IFTYPE_G9983 265
1029#define IFTYPE_ALUEPON 266
1030#define IFTYPE_ALUEPONONU 267
1031#define IFTYPE_ALUEPONPHYSICALUNI 268
1032#define IFTYPE_ALUEPONLOGICALLINK 269
1033#define IFTYPE_ALUGPONONU 270
1034#define IFTYPE_ALUGPONPHYSICALUNI 271
1035#define IFTYPE_VMWARE_NIC_TEAM 272
840a1a6a 1036
674164eb
VK
1037/**
1038 * IP Header -- RFC 791
1039 */
798f373a
VK
1040typedef struct tagIPHDR
1041{
1042 BYTE m_cVIHL; // Version and IHL
1043 BYTE m_cTOS; // Type Of Service
1044 WORD m_wLen; // Total Length
1045 WORD m_wId; // Identification
1046 WORD m_wFlagOff; // Flags and Fragment Offset
1047 BYTE m_cTTL; // Time To Live
1048 BYTE m_cProtocol; // Protocol
1049 WORD m_wChecksum; // Checksum
1050 struct in_addr m_iaSrc; // Internet Address - Source
1051 struct in_addr m_iaDst; // Internet Address - Destination
1052} IPHDR;
1053
674164eb
VK
1054/**
1055 * ICMP Header - RFC 792
1056 */
798f373a
VK
1057typedef struct tagICMPHDR
1058{
1059 BYTE m_cType; // Type
1060 BYTE m_cCode; // Code
1061 WORD m_wChecksum; // Checksum
1062 WORD m_wId; // Identification
1063 WORD m_wSeq; // Sequence
798f373a
VK
1064} ICMPHDR;
1065
674164eb
VK
1066/**
1067 * INADDR_NONE can be undefined on some systems
1068 */
696fc54f
VK
1069#ifndef INADDR_NONE
1070#define INADDR_NONE (0xFFFFFFFF)
1071#endif
1072
674164eb
VK
1073/**
1074 * Check if given string is NULL and always return valid pointer
1075 */
7da71731
VK
1076#define CHECK_NULL(x) ((x) == NULL ? _T("(null)") : (x))
1077#define CHECK_NULL_A(x) ((x) == NULL ? "(null)" : (x))
1078#define CHECK_NULL_EX(x) ((x) == NULL ? _T("") : (x))
1079#define CHECK_NULL_EX_A(x) ((x) == NULL ? "" : (x))
ef44d5ea 1080
674164eb
VK
1081/**
1082 * Free memory block if it isn't NULL
1083 */
2f64a076
VK
1084#if FREE_IS_NULL_SAFE
1085#define safe_free(x) free(x);
1086#define safe_free_and_null(x) { free(x); x = NULL; }
1087#else
b6a77d6d 1088#define safe_free(x) { if ((x) != NULL) free(x); }
de2c1214 1089#define safe_free_and_null(x) { if ((x) != NULL) { free(x); x = NULL; } }
2f64a076
VK
1090#endif
1091
1092/**
1093 * free() wrapper if it isn't NULL safe
1094 */
1095#if defined(__cplusplus) && !FREE_IS_NULL_SAFE
1096inline void nx_free(void *p)
1097{
1098 if (p != NULL)
1099 free(p);
1100}
1101#define free nx_free
1102#endif
b6a77d6d 1103
674164eb
VK
1104/**
1105 * delete object and nullify pointer
1106 */
cd890184
VK
1107#define delete_and_null(x) { delete x; x = NULL; }
1108
674164eb
VK
1109/**
1110 * Convert half-byte's value to hex digit and vice versa
1111 */
4075c782
VK
1112#define bin2hex(x) ((x) < 10 ? ((x) + _T('0')) : ((x) + (_T('A') - 10)))
1113#ifdef UNICODE
1114#define hex2bin(x) ((((x) >= _T('0')) && ((x) <= _T('9'))) ? ((x) - _T('0')) : \
1115 (((towupper(x) >= _T('A')) && (towupper(x) <= _T('F'))) ? (towupper(x) - _T('A') + 10) : 0))
1116#else
93b18807
VK
1117#define hex2bin(x) ((((x) >= '0') && ((x) <= '9')) ? ((x) - '0') : \
1118 (((toupper(x) >= 'A') && (toupper(x) <= 'F')) ? (toupper(x) - 'A' + 10) : 0))
4075c782 1119#endif
fe49ce0b 1120
674164eb
VK
1121/**
1122 * Define min() and max() if needed
1123 */
7e679c4b 1124#ifndef min
8ec5c2c1 1125#define min(a, b) ((a) < (b) ? (a) : (b))
7e679c4b 1126#endif
53c17a96 1127#ifndef max
8ec5c2c1 1128#define max(a, b) ((a) > (b) ? (a) : (b))
53c17a96 1129#endif
b9792835
VK
1130#ifndef MIN
1131#define MIN(a, b) ((a) < (b) ? (a) : (b))
1132#endif
1133#ifndef MAX
1134#define MAX(a, b) ((a) > (b) ? (a) : (b))
1135#endif
7e679c4b 1136
674164eb
VK
1137/**
1138 * Define _tcsicmp() for non-windows
1139 */
daf35c51 1140#ifndef _WIN32
90ce1516
VK
1141#define stricmp strcasecmp
1142#define strnicmp strncasecmp
8b86c5dc
VK
1143#define wcsicmp wcscasecmp
1144#define wcsnicmp wcsncasecmp
daf35c51
VK
1145#endif
1146
674164eb
VK
1147/**
1148 * Compare two numbers and return -1, 0, or 1
1149 */
4c7a83e5
VK
1150#define COMPARE_NUMBERS(n1,n2) (((n1) < (n2)) ? -1 : (((n1) > (n2)) ? 1 : 0))
1151
674164eb
VK
1152/**
1153 * Increment pointer for given number of bytes
1154 */
9f20696e
VK
1155#define inc_ptr(ptr, step, ptype) ptr = (ptype *)(((char *)ptr) + step)
1156
674164eb
VK
1157/**
1158 * Validate numerical value
1159 */
52996299
VK
1160#define VALIDATE_VALUE(var,x,y,z) { if ((var < x) || (var > y)) var = z; }
1161
674164eb
VK
1162/**
1163 * DCI (data collection item) data types
1164 */
a72a1fb1
VK
1165#define DCI_DT_INT 0
1166#define DCI_DT_UINT 1
1167#define DCI_DT_INT64 2
1168#define DCI_DT_UINT64 3
1169#define DCI_DT_STRING 4
1170#define DCI_DT_FLOAT 5
20aaa307 1171#define DCI_DT_NULL 6
8f9299d1 1172#define DCI_DT_DEPRECATED 255 /* used internally by agent */
a72a1fb1 1173
674164eb
VK
1174/**
1175 * Insert parameter as string
1176 */
9493e563
VK
1177#ifdef UNICODE
1178#define STRING(x) L#x
1179#else
1180#define STRING(x) #x
1181#endif
1182
6be0a20b
VK
1183/**
1184 * Pipe handle
1185 */
1186#ifdef _WIN32
1187#define HPIPE HANDLE
1188#define INVALID_PIPE_HANDLE INVALID_HANDLE_VALUE
1189#else
1190#define HPIPE int
1191#define INVALID_PIPE_HANDLE (-1)
1192#endif
1193
34b9a3e7
VK
1194#ifdef __cplusplus
1195
b9792835
VK
1196#include <algorithm>
1197
34b9a3e7
VK
1198/**
1199 * Session enumeration callback return codes
1200 */
1201enum EnumerationCallbackResult
1202{
1203 _STOP = 0,
1204 _CONTINUE = 1
1205};
1206
1207#endif
1208
cbcaf8c8 1209#endif /* _nms_common_h_ */