Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.2 KiB

  1. //=============================================================================
  2. // Copyright (c) 1998 Microsoft Corporation
  3. // Module Name: defines.h
  4. // Abstract:
  5. //
  6. // Author: K.S.Lokesh (lokeshs@) 1-1-98
  7. //=============================================================================
  8. //
  9. // IPADDR typedef
  10. //
  11. #ifndef IPADDR
  12. typedef DWORD IPADDR;
  13. #endif
  14. //
  15. // instead of using goto:end to go to the end of the block, use the following
  16. //
  17. #define BEGIN_BREAKOUT_BLOCK1 do
  18. #define GOTO_END_BLOCK1 goto END_BREAKOUT_BLOCK_1
  19. #define END_BREAKOUT_BLOCK1 while(FALSE); END_BREAKOUT_BLOCK_1:
  20. #define BEGIN_BREAKOUT_BLOCK2 do
  21. #define GOTO_END_BLOCK2 goto END_BREAKOUT_BLOCK_2
  22. #define END_BREAKOUT_BLOCK2 while(FALSE); END_BREAKOUT_BLOCK_2:
  23. //-----------------------------------------------------------------------------
  24. // memory allocation/deallocation macros, error macros
  25. //-----------------------------------------------------------------------------
  26. #define DVMRP_ALLOC(sz) HeapAlloc(Globals1.Heap,0,(sz))
  27. #define DVMRP_ALLOC_AND_ZERO(sz) \
  28. HeapAlloc(Globals1.Heap,HEAP_ZERO_MEMORY,(sz))
  29. #define DVMRP_FREE(p) HeapFree(Globals1.Heap, 0, (p))
  30. #define DVMRP_FREE_AND_NULL(p) {\
  31. if (p) HeapFree(Globals1.Heap, 0, (p));\
  32. (p) = NULL; \
  33. }
  34. #define DVMRP_FREE_NOT_NULL(p) ((p) ? DVMRP_FREE(p) : TRUE)
  35. #define PROCESS_ALLOC_FAILURE1(ptr, Error,arg2, GotoStmt) \
  36. if (ptr==NULL) {\
  37. Error = GetLastError();\
  38. Trace3(ERR, "Error %d allocating %d bytes",Error,arg2);\
  39. Logerr0(HEAP_ALLOC_FAILED, Error);\
  40. GotoStmt;\
  41. }
  42. #define PROCESS_ALLOC_FAILURE2(ptr, Name, Error,arg2,GotoStmt) \
  43. if (ptr==NULL) {\
  44. Error = GetLastError();\
  45. Trace3(ERR, "Error %d allocating %d bytes for %s", \
  46. Error, arg2, Name); \
  47. Logerr0(HEAP_ALLOC_FAILED, Error);\
  48. GotoStmt;\
  49. }
  50. #define PROCESS_ALLOC_FAILURE3(ptr, Format, Error,arg2,arg3, GotoStmt) \
  51. if (ptr==NULL) {\
  52. Error = GetLastError();\
  53. Trace3(ERR, "Error %d allocating %d bytes for " ## Format, \
  54. Error, arg2, arg3); \
  55. Logerr0(HEAP_ALLOC_FAILED, Error);\
  56. GotoStmt;\
  57. }
  58. #define HANDLE_CRITICAL_SECTION_EXCEPTION(Error, GotoStmt) \
  59. except (EXCEPTION_EXECUTE_HANDLER) { \
  60. \
  61. Error = GetExceptionCode(); \
  62. Trace1(ERR, "Error initializing critical section", Error); \
  63. \
  64. Logerr0(INIT_CRITSEC_FAILED, Error); \
  65. GotoStmt; \
  66. }
  67. //-----------------------------------------------------------------------------
  68. // general ip address macros
  69. //-----------------------------------------------------------------------------
  70. #define ALL_DVMRP_ROUTERS_MCAST_GROUP 0x040000E0
  71. //
  72. // This macro compares two IP addresses in network order by
  73. // masking off each pair of octets and doing a subtraction;
  74. // the result of the final subtraction is stored in the third argument.
  75. //
  76. #define INET_CMP(a,b,c) \
  77. (((c) = (((a) & 0x000000ff) - ((b) & 0x000000ff))) ? (c) : \
  78. (((c) = (((a) & 0x0000ff00) - ((b) & 0x0000ff00))) ? (c) : \
  79. (((c) = (((a) & 0x00ff0000) - ((b) & 0x00ff0000))) ? (c) : \
  80. (((c) = ((((a)>>8) & 0x00ff0000) - (((b)>>8) & 0x00ff0000)))))))
  81. #define PRINT_IPADDR(x) \
  82. ((x)&0x000000ff),(((x)&0x0000ff00)>>8),\
  83. (((x)&0x00ff0000)>>16),(((x)&0xff000000)>>24)
  84. //
  85. // assert macros
  86. //
  87. #if DBG
  88. #define IgmpAssert(exp){ \
  89. if(!(exp)) \
  90. { \
  91. TracePrintf(TRACEID, \
  92. "Assertion failed in %s : %d \n",__FILE__,__LINE__);\
  93. RouterAssert(#exp,__FILE__,__LINE__,NULL); \
  94. } \
  95. }
  96. #else
  97. #define IgmpAssert(exp)
  98. #endif