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