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.

208 lines
6.1 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. // Time conversion constants and macros
  61. //
  62. #define SYSTIME_UNITS_PER_MSEC (1000 * 10)
  63. #define SYSTIME_UNITS_PER_SEC (1000 * SYSTIME_UNITS_PER_MSEC)
  64. //
  65. // macro to get system time in 100-nanosecond units
  66. //
  67. #define RipQuerySystemTime(p) NtQuerySystemTime((p))
  68. //
  69. // macros to convert time between 100-nanosecond, 1millsec, and 1 sec units
  70. //
  71. #define RipSystemTimeToMillisecs(p) { \
  72. DWORD _r; \
  73. *(p) = RtlExtendedLargeIntegerDivide(*(p), SYSTIME_UNITS_PER_MSEC, &_r);\
  74. }
  75. #define RipMillisecsToSystemTime(p) \
  76. *(p) = RtlExtendedIntegerMultiply(*(p), SYSTIME_UNITS_PER_MSEC)
  77. #define RipSecsToSystemTime(p) \
  78. *(p) = RtlExtendedIntegerMultiply(*(p), SYSTIME_UNITS_PER_SEC)
  79. #define RipSecsToMilliSecs(p) \
  80. (p) * 1000
  81. //
  82. // Network classification constants and macros
  83. //
  84. #define CLASSA_MASK ((DWORD)0x000000ff)
  85. #define CLASSB_MASK ((DWORD)0x0000ffff)
  86. #define CLASSC_MASK ((DWORD)0x00ffffff)
  87. #define CLASSD_MASK ((DWORD)0x000000e0)
  88. #define CLASSE_MASK ((DWORD)0xffffffff)
  89. #define CLASSA_ADDR(a) (((*((PBYTE)&(a))) & 0x80) == 0)
  90. #define CLASSB_ADDR(a) (((*((PBYTE)&(a))) & 0xc0) == 0x80)
  91. #define CLASSC_ADDR(a) (((*((PBYTE)&(a))) & 0xe0) == 0xc0)
  92. #define CLASSD_ADDR(a) (((*((PBYTE)&(a))) & 0xf0) == 0xe0)
  93. //
  94. // NOTE:
  95. // This check for class E addresses doesn't weed out the address range from
  96. // 248.0.0.0 to 255.255.255.254
  97. //
  98. #define CLASSE_ADDR(a) ((((*((PBYTE)&(a)))& 0xf0) == 0xf0) && \
  99. ((a) != 0xffffffff))
  100. #define IS_LOOPBACK_ADDR(a) (((a) & 0xff) == 0x7f)
  101. //
  102. // Checks if the address is a broadcast
  103. // Determines the class of the address passed in, and then uses the net mask
  104. // corresponding to that class to determine if it is a broadcast address.
  105. // Also identifies an all 1's address as a broadcast address.
  106. // This macro can't be used for identifying subnet directed broadcasts
  107. //
  108. #define IS_BROADCAST_ADDR(a) \
  109. ((a) == INADDR_BROADCAST || \
  110. (CLASSA_ADDR(a) && (((a) & ~CLASSA_MASK) == ~CLASSA_MASK)) || \
  111. (CLASSB_ADDR(a) && (((a) & ~CLASSB_MASK) == ~CLASSB_MASK)) || \
  112. (CLASSC_ADDR(a) && (((a) & ~CLASSC_MASK) == ~CLASSC_MASK)))
  113. //
  114. // Checks if the address is a directed broadcast
  115. // The ~mask == TRUE check makes sure that host addresses with a mask
  116. // of all ones, don't get classified as directed broadcasts
  117. // But this also means that anytime the mask is all 1's (which is what
  118. // NETCLASS_MASK macro returns, if the address passed in is not an A, B, C or
  119. // D class address) the IS_DIRECTED_BROADCAST macro will return 0
  120. //
  121. #define IS_DIRECTED_BROADCAST_ADDR(a, mask) \
  122. ( (~(mask)) && (((a) & ~(mask)) == ~(mask)) )
  123. //
  124. // checks if an address is 255.255.255.255
  125. //
  126. #define IS_LOCAL_BROADCAST_ADDR(a) \
  127. ( (a) == INADDR_BROADCAST )
  128. #define HOSTADDR_MASK 0xffffffff
  129. #define NETCLASS_MASK(a) \
  130. (CLASSA_ADDR(a) ? CLASSA_MASK : \
  131. (CLASSB_ADDR(a) ? CLASSB_MASK : \
  132. (CLASSC_ADDR(a) ? CLASSC_MASK : \
  133. (CLASSD_ADDR(a) ? CLASSD_MASK : CLASSE_MASK))))
  134. //
  135. // This macro compares two IP addresses in network order by
  136. // masking off each pair of octets and doing a subtraction;
  137. // the result of the final subtraction is stored in the third argument.
  138. //
  139. #define INET_CMP(a,b,c) \
  140. (((c) = (((a) & 0x000000ff) - ((b) & 0x000000ff))) ? (c) : \
  141. (((c) = (((a) & 0x0000ff00) - ((b) & 0x0000ff00))) ? (c) : \
  142. (((c) = (((a) & 0x00ff0000) - ((b) & 0x00ff0000))) ? (c) : \
  143. (((c) = ((((a)>>8) & 0x00ff0000) - (((b)>>8) & 0x00ff0000)))))))
  144. #define IPV4_ADDR_LEN 32
  145. #define IPV4_SOURCE_MASK 0xFFFFFFFF
  146. #endif // _DEFS_H_