Leaked source code of windows server 2003
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.

219 lines
6.5 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: defs.h
  5. //
  6. // History:
  7. // Abolade Gbadegesin Aug-7-1995 Created.
  8. //
  9. // Contains miscellaneous definitions and declarations
  10. //============================================================================
  11. #ifndef _DEFS_H_
  12. #define _DEFS_H_
  13. //
  14. // type definitions for IPRIP network packet templates
  15. //
  16. #pragma pack(1)
  17. typedef struct _IPRIP_HEADER {
  18. BYTE IH_Command;
  19. BYTE IH_Version;
  20. WORD IH_Reserved;
  21. } IPRIP_HEADER, *PIPRIP_HEADER;
  22. typedef struct _IPRIP_ENTRY {
  23. WORD IE_AddrFamily;
  24. WORD IE_RouteTag;
  25. DWORD IE_Destination;
  26. DWORD IE_SubnetMask;
  27. DWORD IE_Nexthop;
  28. DWORD IE_Metric;
  29. } IPRIP_ENTRY, *PIPRIP_ENTRY;
  30. typedef struct _IPRIP_AUTHENT_ENTRY {
  31. WORD IAE_AddrFamily;
  32. WORD IAE_AuthType;
  33. BYTE IAE_AuthKey[IPRIP_MAX_AUTHKEY_SIZE];
  34. } IPRIP_AUTHENT_ENTRY, *PIPRIP_AUTHENT_ENTRY;
  35. #pragma pack()
  36. #define ADDRFAMILY_REQUEST 0
  37. #define ADDRFAMILY_INET ntohs(AF_INET)
  38. #define ADDRFAMILY_AUTHENT 0xFFFF
  39. #define MIN_PACKET_SIZE (sizeof(IPRIP_HEADER) + sizeof(IPRIP_ENTRY))
  40. #define MAX_PACKET_SIZE 512
  41. #define MAX_PACKET_ENTRIES \
  42. ((MAX_PACKET_SIZE - sizeof(IPRIP_HEADER)) / sizeof(IPRIP_ENTRY))
  43. #define MAX_UPDATE_REQUESTS 3
  44. //
  45. // this structure exists so that a RIP packet can be copied
  46. // via structure-assignment rather than having to call CopyMemory
  47. //
  48. typedef struct _IPRIP_PACKET {
  49. BYTE IP_Packet[MAX_PACKET_SIZE];
  50. } IPRIP_PACKET, *PIPRIP_PACKET;
  51. //
  52. // definitions for IPRIP packet fields
  53. //
  54. #define IPRIP_PORT 520
  55. #define IPRIP_REQUEST 1
  56. #define IPRIP_RESPONSE 2
  57. #define IPRIP_INFINITE 16
  58. #define IPRIP_MULTIADDR ((DWORD)0x090000E0)
  59. //
  60. // Constant for recv buffer size of sockets bound to RIP port
  61. //
  62. #define RIPRECVBUFFERSIZE 65536
  63. //
  64. // Maximum number of work items that will be enqueued
  65. //
  66. #define MAXPROCESSINPUTWORKITEMS 8
  67. //
  68. // Time conversion constants and macros
  69. //
  70. #define SYSTIME_UNITS_PER_MSEC (1000 * 10)
  71. #define SYSTIME_UNITS_PER_SEC (1000 * SYSTIME_UNITS_PER_MSEC)
  72. //
  73. // macro to get system time in 100-nanosecond units
  74. //
  75. #define RipQuerySystemTime(p) NtQuerySystemTime((p))
  76. //
  77. // macros to convert time between 100-nanosecond, 1millsec, and 1 sec units
  78. //
  79. #define RipSystemTimeToMillisecs(p) { \
  80. DWORD _r; \
  81. *(p) = RtlExtendedLargeIntegerDivide(*(p), SYSTIME_UNITS_PER_MSEC, &_r);\
  82. }
  83. #define RipMillisecsToSystemTime(p) \
  84. *(p) = RtlExtendedIntegerMultiply(*(p), SYSTIME_UNITS_PER_MSEC)
  85. #define RipSecsToSystemTime(p) \
  86. *(p) = RtlExtendedIntegerMultiply(*(p), SYSTIME_UNITS_PER_SEC)
  87. #define RipSecsToMilliSecs(p) \
  88. (p) * 1000
  89. //
  90. // Network classification constants and macros
  91. //
  92. #define CLASSA_MASK ((DWORD)0x000000ff)
  93. #define CLASSB_MASK ((DWORD)0x0000ffff)
  94. #define CLASSC_MASK ((DWORD)0x00ffffff)
  95. #define CLASSD_MASK ((DWORD)0x000000e0)
  96. #define CLASSE_MASK ((DWORD)0xffffffff)
  97. #define CLASSA_ADDR(a) (((*((PBYTE)&(a))) & 0x80) == 0)
  98. #define CLASSB_ADDR(a) (((*((PBYTE)&(a))) & 0xc0) == 0x80)
  99. #define CLASSC_ADDR(a) (((*((PBYTE)&(a))) & 0xe0) == 0xc0)
  100. #define CLASSD_ADDR(a) (((*((PBYTE)&(a))) & 0xf0) == 0xe0)
  101. //
  102. // NOTE:
  103. // This check for class E addresses doesn't weed out the address range from
  104. // 248.0.0.0 to 255.255.255.254
  105. //
  106. #define CLASSE_ADDR(a) ((((*((PBYTE)&(a)))& 0xf0) == 0xf0) && \
  107. ((a) != 0xffffffff))
  108. #define IS_LOOPBACK_ADDR(a) (((a) & 0xff) == 0x7f)
  109. //
  110. // Checks if the address is a broadcast
  111. // Determines the class of the address passed in, and then uses the net mask
  112. // corresponding to that class to determine if it is a broadcast address.
  113. // Also identifies an all 1's address as a broadcast address.
  114. // This macro can't be used for identifying subnet directed broadcasts
  115. //
  116. #define IS_BROADCAST_ADDR(a) \
  117. ((a) == INADDR_BROADCAST || \
  118. (CLASSA_ADDR(a) && (((a) & ~CLASSA_MASK) == ~CLASSA_MASK)) || \
  119. (CLASSB_ADDR(a) && (((a) & ~CLASSB_MASK) == ~CLASSB_MASK)) || \
  120. (CLASSC_ADDR(a) && (((a) & ~CLASSC_MASK) == ~CLASSC_MASK)))
  121. //
  122. // Checks if the address is a directed broadcast
  123. // The ~mask == TRUE check makes sure that host addresses with a mask
  124. // of all ones, don't get classified as directed broadcasts
  125. // But this also means that anytime the mask is all 1's (which is what
  126. // NETCLASS_MASK macro returns, if the address passed in is not an A, B, C or
  127. // D class address) the IS_DIRECTED_BROADCAST macro will return 0
  128. //
  129. #define IS_DIRECTED_BROADCAST_ADDR(a, mask) \
  130. ( (~(mask)) && (((a) & ~(mask)) == ~(mask)) )
  131. //
  132. // checks if an address is 255.255.255.255
  133. //
  134. #define IS_LOCAL_BROADCAST_ADDR(a) \
  135. ( (a) == INADDR_BROADCAST )
  136. #define HOSTADDR_MASK 0xffffffff
  137. #define NETCLASS_MASK(a) \
  138. (CLASSA_ADDR(a) ? CLASSA_MASK : \
  139. (CLASSB_ADDR(a) ? CLASSB_MASK : \
  140. (CLASSC_ADDR(a) ? CLASSC_MASK : \
  141. (CLASSD_ADDR(a) ? CLASSD_MASK : CLASSE_MASK))))
  142. //
  143. // This macro compares two IP addresses in network order by
  144. // masking off each pair of octets and doing a subtraction;
  145. // the result of the final subtraction is stored in the third argument.
  146. //
  147. #define INET_CMP(a,b,c) \
  148. (((c) = (((a) & 0x000000ff) - ((b) & 0x000000ff))) ? (c) : \
  149. (((c) = (((a) & 0x0000ff00) - ((b) & 0x0000ff00))) ? (c) : \
  150. (((c) = (((a) & 0x00ff0000) - ((b) & 0x00ff0000))) ? (c) : \
  151. (((c) = ((((a)>>8) & 0x00ff0000) - (((b)>>8) & 0x00ff0000)))))))
  152. #define IPV4_ADDR_LEN 32
  153. #define IPV4_SOURCE_MASK 0xFFFFFFFF
  154. #endif // _DEFS_H_