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.

299 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. File:
  4. prot.h
  5. Abstract:
  6. This module contains Internet protocol-related declarations.
  7. Author:
  8. Abolade Gbadegesin (t-abolag) 21-July-1997
  9. Revision History:
  10. --*/
  11. #ifndef _NAT_PROT_H_
  12. #define _NAT_PROT_H_
  13. //
  14. // NBT constants
  15. //
  16. #define NBT_DATAGRAM_PORT 138
  17. #define NBT_NAME_LENGTH 34
  18. #define NBT_MESSAGE_DIRECT_UNIQUE 0x10
  19. #define NBT_MESSAGE_DIRECT_GROUP 0x11
  20. #define NBT_FLAG_FIRST_FRAGMENT 0x02
  21. //
  22. // PPTP constants
  23. //
  24. #define PPTP_CONTROL_PORT 1723
  25. #define PPTP_GRE_PROTOCOL 0x880B
  26. //
  27. // IPSec constants
  28. //
  29. #define IPSEC_ISAKMP_PORT 500
  30. //
  31. // DHCP constants
  32. //
  33. #define DHCP_SERVER_PORT 67
  34. #define DHCP_CLIENT_PORT 68
  35. //
  36. // ICMP message-type constants
  37. //
  38. #define ICMP_ECHO_REPLY 0
  39. #define ICMP_DEST_UNREACH 3
  40. #define ICMP_SOURCE_QUENCH 4
  41. #define ICMP_REDIRECT 5
  42. #define ICMP_ECHO_REQUEST 8
  43. #define ICMP_ROUTER_REPLY 9
  44. #define ICMP_ROUTER_REQUEST 10
  45. #define ICMP_TIME_EXCEED 11
  46. #define ICMP_PARAM_PROBLEM 12
  47. #define ICMP_TIMESTAMP_REQUEST 13
  48. #define ICMP_TIMESTAMP_REPLY 14
  49. #define ICMP_MASK_REQUEST 17
  50. #define ICMP_MASK_REPLY 18
  51. //
  52. // ICMP message-code constants
  53. //
  54. #define ICMP_CODE_NET_UNREACH 0
  55. #define ICMP_CODE_HOST_UNREACH 1
  56. #define ICMP_CODE_PROTOCOL_UNREACH 2
  57. #define ICMP_CODE_PORT_UNREACH 3
  58. #define ICMP_CODE_FRAG_NEEDED 4
  59. #define ICMP_SOURCE_ROUTE_FAILED 5
  60. //
  61. // Macro for extracting the data-offset from the field IPHeader.verlen
  62. //
  63. #define IP_DATA_OFFSET(h) \
  64. ((ULONG)((((PIP_HEADER)(h))->VersionAndHeaderLength & 0x0F) << 2))
  65. //
  66. // Mask for extracting the fragment-offset from the IPHeader structure's
  67. // combined flags/fragment-offset field
  68. //
  69. #define IP_FRAGMENT_OFFSET_MASK ~0x00E0
  70. //
  71. // Value of the Don't Fragment bit w/in the IPHeader structure's combined
  72. // flags/fragment-offset field.
  73. //
  74. #define IP_DF_FLAG 0x0040
  75. //
  76. // Macro for extracting the data-offset from the field TCP_HEADER.OffsetAndFlags
  77. // The offset is in 32-bit words, so shifting by 2 gives the value in bytes.
  78. //
  79. #define TCP_DATA_OFFSET(h) (((h)->OffsetAndFlags & 0x00F0) >> 2)
  80. //
  81. // Masks for extracting flags from the field TCP_HEADER.OffsetAndFlags
  82. //
  83. #define TCP_FLAG_FIN 0x0100
  84. #define TCP_FLAG_SYN 0x0200
  85. #define TCP_FLAG_RST 0x0400
  86. #define TCP_FLAG_PSH 0x0800
  87. #define TCP_FLAG_ACK 0x1000
  88. #define TCP_FLAG_URG 0x2000
  89. #define TCP_FLAG(h,f) ((h)->OffsetAndFlags & TCP_FLAG_ ## f)
  90. #define TCP_ALL_FLAGS(h) ((h)->OffsetAndFlags & 0x3f00)
  91. #define TCP_RESERVED_BITS(h) ((h)->OffsetAndFlags & 0xc00f)
  92. //
  93. // TCP Option Opcodes
  94. //
  95. #define TCP_OPTION_ENDOFOPTIONS ( 0 )
  96. #define TCP_OPTION_NOP ( 1 )
  97. #define TCP_OPTION_MSS ( 2 )
  98. #define TCP_OPTION_WSCALE ( 3 )
  99. #define TCP_OPTION_SACK_PERMITTED ( 4 )
  100. #define TCP_OPTION_SACK ( 5 )
  101. #define TCP_OPTION_TIMESTAMPS ( 8 )
  102. //
  103. // Length Definitions for TCP Options
  104. //
  105. #define MSS_OPTION_SIZE ( 4 )
  106. #define WS_OPTION_SIZE ( 3 )
  107. #define TS_OPTION_SIZE ( 10 )
  108. #define SP_OPTION_SIZE ( 2 )
  109. //
  110. // Maximum MSS value based on the MTU of the sending interface
  111. //
  112. #define MAX_MSSOPTION(m) ((m)>0 ? (m) - sizeof(TCP_HEADER) - sizeof(IP_HEADER):0)
  113. #include <packon.h>
  114. typedef struct _IP_HEADER {
  115. UCHAR VersionAndHeaderLength;
  116. UCHAR TypeOfService;
  117. USHORT TotalLength;
  118. USHORT Identification;
  119. USHORT OffsetAndFlags;
  120. UCHAR TimeToLive;
  121. UCHAR Protocol;
  122. USHORT Checksum;
  123. ULONG SourceAddress;
  124. ULONG DestinationAddress;
  125. } IP_HEADER, *PIP_HEADER;
  126. typedef struct _TCP_HEADER {
  127. USHORT SourcePort;
  128. USHORT DestinationPort;
  129. ULONG SequenceNumber;
  130. ULONG AckNumber;
  131. USHORT OffsetAndFlags;
  132. USHORT WindowSize;
  133. USHORT Checksum;
  134. USHORT UrgentPointer;
  135. } TCP_HEADER, *PTCP_HEADER;
  136. typedef struct _TCP_MSS_OPTION {
  137. BYTE OptionType;
  138. BYTE OptionLen;
  139. USHORT MSSValue;
  140. } MSSOption, *PMSSOption;
  141. typedef struct _UDP_HEADER {
  142. USHORT SourcePort;
  143. USHORT DestinationPort;
  144. USHORT Length;
  145. USHORT Checksum;
  146. } UDP_HEADER, *PUDP_HEADER;
  147. typedef struct _ICMP_HEADER {
  148. UCHAR Type;
  149. UCHAR Code;
  150. USHORT Checksum;
  151. USHORT Identifier; // valid only for ICMP request/reply
  152. USHORT SequenceNumber; // valid only for ICMP request/reply
  153. IP_HEADER EncapsulatedIpHeader; // valid only for ICMP errors
  154. union {
  155. struct _ENCAPSULATED_TCP_HEADER {
  156. USHORT SourcePort;
  157. USHORT DestinationPort;
  158. ULONG SequenceNumber;
  159. } EncapsulatedTcpHeader;
  160. struct _ENCAPSULATED_UDP_HEADER {
  161. USHORT SourcePort;
  162. USHORT DestinationPort;
  163. USHORT Length;
  164. USHORT Checksum;
  165. } EncapsulatedUdpHeader;
  166. struct _ENCAPSULATED_ICMP_HEADER {
  167. UCHAR Type;
  168. UCHAR Code;
  169. USHORT Checksum;
  170. USHORT Identifier;
  171. USHORT SequenceNumber;
  172. } EncapsulatedIcmpHeader;
  173. };
  174. } ICMP_HEADER, *PICMP_HEADER;
  175. typedef struct _PPTP_HEADER {
  176. USHORT PacketLength;
  177. USHORT PacketType;
  178. ULONG MagicCookie;
  179. USHORT MessageType;
  180. USHORT Reserved;
  181. USHORT CallId; // may be sender ID or peer ID
  182. USHORT PeerCallId;
  183. } PPTP_HEADER, *PPPTP_HEADER;
  184. #define PPTP_MAGIC_COOKIE 0x4D3C2B1A // network byte order
  185. #define PPTP_OUTGOING_CALL_REQUEST 7
  186. #define PPTP_OUTGOING_CALL_REPLY 8
  187. #define PPTP_INCOMING_CALL_REQUEST 9
  188. #define PPTP_INCOMING_CALL_REPLY 10
  189. #define PPTP_INCOMING_CALL_CONNECTED 11
  190. #define PPTP_CALL_CLEAR_REQUEST 12
  191. #define PPTP_CALL_DISCONNECT_NOTIFY 13
  192. #define PPTP_WAN_ERROR_NOTIFY 14
  193. #define PPTP_SET_LINK_INFO 15
  194. typedef struct _GRE_HEADER {
  195. USHORT FlagsAndVersion;
  196. USHORT ProtocolType;
  197. USHORT PayloadLength;
  198. USHORT CallId;
  199. ULONG SequenceNumber;
  200. ULONG AckNumber;
  201. } GRE_HEADER, *PGRE_HEADER;
  202. typedef struct _NBT_HEADER {
  203. UCHAR MessageType;
  204. UCHAR Flags;
  205. USHORT DatagramId;
  206. ULONG SourceAddress;
  207. USHORT SourcePort;
  208. USHORT DatagramLength;
  209. USHORT PacketOffset;
  210. UCHAR SourceName[NBT_NAME_LENGTH];
  211. UCHAR DestinationName[NBT_NAME_LENGTH];
  212. } NBT_HEADER, *PNBT_HEADER;
  213. #include <packoff.h>
  214. //
  215. // IP address class-mask definitions
  216. //
  217. #define CLASS_MASK_A 0x000000ff
  218. #define CLASS_MASK_B 0x0000ffff
  219. #define CLASS_MASK_C 0x00ffffff
  220. #define CLASS_MASK_D 0x000000e0
  221. #define CLASS_MASK_E 0xffffffff
  222. #define ADDRESS_CLASS_A(a) (((*((PBYTE)&(a))) & 0x80) == 0)
  223. #define ADDRESS_CLASS_B(a) (((*((PBYTE)&(a))) & 0xc0) == 0x80)
  224. #define ADDRESS_CLASS_C(a) (((*((PBYTE)&(a))) & 0xe0) == 0xc0)
  225. #define ADDRESS_CLASS_D(a) (((*((PBYTE)&(a))) & 0xf0) == 0xe0)
  226. #define ADDRESS_CLASS_E(a) ((((*((PBYTE)&(a)))& 0xf0) == 0xf0) && \
  227. ((a) != 0xffffffff))
  228. #define GET_CLASS_MASK(a) \
  229. (ADDRESS_CLASS_A(a) ? CLASS_MASK_A: \
  230. (ADDRESS_CLASS_B(a) ? CLASS_MASK_B: \
  231. (ADDRESS_CLASS_C(a) ? CLASS_MASK_C : \
  232. (ADDRESS_CLASS_D(a) ? CLASS_MASK_D : CLASS_MASK_E))))
  233. #endif // _NAT_PROT_H_