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.

504 lines
20 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. wlbsip.h
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. IP/TCP/UDP support
  8. Author:
  9. kyrilf
  10. Environment:
  11. Revision History:
  12. --*/
  13. #ifndef _Tcpip_h_
  14. #define _Tcpip_h_
  15. #ifdef KERNEL_MODE
  16. #include <ndis.h>
  17. #endif
  18. #pragma pack(1)
  19. /* type structures for basic protocols */
  20. typedef struct
  21. {
  22. UCHAR byte [20];
  23. }
  24. IP_HDR, * PIP_HDR;
  25. typedef struct
  26. {
  27. UCHAR byte [20];
  28. }
  29. TCP_HDR, * PTCP_HDR;
  30. typedef struct
  31. {
  32. UCHAR byte [8];
  33. }
  34. UDP_HDR, * PUDP_HDR;
  35. typedef struct
  36. {
  37. UCHAR byte [28];
  38. }
  39. ARP_HDR, * PARP_HDR;
  40. #define TCPIP_BCAST_ADDR 0xffffffff /* IP broadcast address */
  41. #define TCPIP_CLASSC_MASK 0x00ffffff /* IP address Class C mask */
  42. /* protocol type signatures carried in the length field of Ethernet frame */
  43. #define TCPIP_IP_SIG 0x0800 /* IP protocol */
  44. #define TCPIP_ARP_SIG 0x0806 /* ARP/RARP protocol */
  45. /* supported IP version */
  46. #define TCPIP_VERSION 4 /* current IP version */
  47. /* protocol types as encoded in IP header */
  48. #define TCPIP_PROTOCOL_IP 0 /* Internet protocol id */
  49. #define TCPIP_PROTOCOL_ICMP 1 /* Internet control message protocol id */
  50. #define TCPIP_PROTOCOL_IGMP 2 /* Internet gateway message protocol id */
  51. #define TCPIP_PROTOCOL_GGP 3 /* Gateway-gateway protocol id */
  52. #define TCPIP_PROTOCOL_TCP 6 /* Transmission control protocol id */
  53. #define TCPIP_PROTOCOL_EGP 8 /* Exterior gateway protocol id */
  54. #define TCPIP_PROTOCOL_PUP 12 /* PARC universal packet protocol id */
  55. #define TCPIP_PROTOCOL_UDP 17 /* user datagram protocol id */
  56. #define TCPIP_PROTOCOL_HMP 20 /* Host monitoring protocol id */
  57. #define TCPIP_PROTOCOL_XNS_IDP 22 /* Xerox NS IDP protocol id */
  58. #define TCPIP_PROTOCOL_RDP 27 /* Reliable datagram protocol id */
  59. #define TCPIP_PROTOCOL_RVD 66 /* MIT remote virtual disk protocol id */
  60. #define TCPIP_PROTOCOL_RAW_IP 255 /* raw IP protocol id */
  61. #define TCPIP_PROTOCOL_GRE 47 /* PPTP's GRE stream */
  62. #define TCPIP_PROTOCOL_IPSEC1 50 /* IPSEC's data stream */
  63. #define TCPIP_PROTOCOL_IPSEC2 51 /* IPSEC's data stream */
  64. #define TCPIP_PROTOCOL_PPTP 99 /* This is a bogus protocol ID used by descriptor tracking in the load module. */
  65. #define TCPIP_PROTOCOL_IPSEC_UDP 217 /* Bogus protocol ID used to track UDP subsequent
  66. fragments within the IPSEC protocol in load.c */
  67. #define IP_ADDR_LEN 4 /* in bytes */
  68. /* Stolen from net\ipsec\oakley\ikedef.h and net\ipsec\oakley\isakmp.h for reference. */
  69. #if 0
  70. #define COOKIE_LEN 8
  71. typedef struct isakmp_hdr_ {
  72. unsigned char init_cookie[COOKIE_LEN];
  73. unsigned char resp_cookie[COOKIE_LEN];
  74. unsigned char next_payload;
  75. #ifdef ISAKMP_i386
  76. unsigned char minver:4,
  77. majver:4;
  78. #else
  79. unsigned char majver:4,
  80. minver:4;
  81. #endif
  82. unsigned char exch;
  83. unsigned char flags;
  84. unsigned long mess_id;
  85. unsigned long len;
  86. } isakmp_hdr;
  87. typedef struct generic_payload_ {
  88. unsigned char next_payload;
  89. unsigned char reserved;
  90. unsigned short payload_len;
  91. } generic_payload;
  92. typedef struct vendor_payload_ {
  93. unsigned char next_payload;
  94. unsigned char reserved;
  95. unsigned short payload_len;
  96. unsigned char vendor_id[1];
  97. } generic_payload;
  98. typedef struct notify_payload_ {
  99. unsigned char next_payload;
  100. unsigned char reserved;
  101. unsigned short payload_len;
  102. unsigned long doi;
  103. unsigned char protocol_id;
  104. unsigned char spi_size;
  105. unsigned short notify_message;
  106. }
  107. #endif
  108. /* IPSec/IKE header macros. */
  109. typedef enum {
  110. NLB_IPSEC_OTHER = 1,
  111. NLB_IPSEC_INITIAL_CONTACT,
  112. NLB_IPSEC_IDENTIFICATION
  113. } NLB_IPSEC_PACKET_TYPE;
  114. #define IPSEC_ISAKMP_SA 1
  115. #define IPSEC_ISAKMP_ID 5
  116. #define IPSEC_ISAKMP_VENDOR_ID 13
  117. #define IPSEC_ISAKMP_NOTIFY 11
  118. #define IPSEC_ISAKMP_NAT_DELIMITER_LENGTH 4
  119. #define IPSEC_ISAKMP_NAT_DELIMITER {0x00, 0x00, 0x00, 0x00}
  120. #define IPSEC_ISAKMP_MAIN_MODE_RCOOKIE {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  121. #define IPSEC_ISAKMP_HEADER_LENGTH 28
  122. #define IPSEC_ISAKMP_HEADER_RCOOKIE_OFFSET 8
  123. #define IPSEC_ISAKMP_HEADER_RCOOKIE_LENGTH 8
  124. #define IPSEC_ISAKMP_HEADER_NEXT_PAYLOAD_OFFSET 16
  125. #define IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET 24
  126. typedef struct {
  127. UCHAR byte[IPSEC_ISAKMP_HEADER_LENGTH];
  128. } IPSEC_ISAKMP_HDR, * PIPSEC_ISAKMP_HDR;
  129. #define IPSEC_ISAKMP_GET_RCOOKIE_POINTER(isakmp_hdrp) ((PUCHAR)isakmp_hdrp + IPSEC_ISAKMP_HEADER_RCOOKIE_OFFSET)
  130. #define IPSEC_ISAKMP_GET_NEXT_PAYLOAD(isakmp_hdrp) ((UCHAR)((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_NEXT_PAYLOAD_OFFSET]))
  131. #define IPSEC_ISAKMP_GET_PACKET_LENGTH(isakmp_hdrp) ((ULONG)(((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET] << 24) | \
  132. ((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET + 1] << 16) | \
  133. ((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET + 2] << 8) | \
  134. ((isakmp_hdrp)->byte[IPSEC_ISAKMP_HEADER_PACKET_LENGTH_OFFSET + 3] << 0)))
  135. #define IPSEC_GENERIC_HEADER_LENGTH 4
  136. #define IPSEC_GENERIC_HEADER_NEXT_PAYLOAD_OFFSET 0
  137. #define IPSEC_GENERIC_HEADER_PAYLOAD_LENGTH_OFFSET 2
  138. typedef struct {
  139. UCHAR byte[IPSEC_GENERIC_HEADER_LENGTH];
  140. } IPSEC_GENERIC_HDR, * PIPSEC_GENERIC_HDR;
  141. #define IPSEC_GENERIC_GET_NEXT_PAYLOAD(generic_hdrp) ((UCHAR)((generic_hdrp)->byte[IPSEC_GENERIC_HEADER_NEXT_PAYLOAD_OFFSET]))
  142. #define IPSEC_GENERIC_GET_PAYLOAD_LENGTH(generic_hdrp) ((USHORT)(((generic_hdrp)->byte[IPSEC_GENERIC_HEADER_PAYLOAD_LENGTH_OFFSET] << 8) | \
  143. ((generic_hdrp)->byte[IPSEC_GENERIC_HEADER_PAYLOAD_LENGTH_OFFSET + 1] << 0)))
  144. #define IPSEC_VENDOR_ID_INITIAL_CONTACT {0x26, 0x24, 0x4D, 0x38, 0xED, 0xDB, 0x61, 0xB3, 0x17, 0x2A, 0x36, 0xE3, 0xD0, 0xCF, 0xB8, 0x19}
  145. #define IPSEC_VENDOR_ID_INITIAL_CONTACT_SUPPORT {0xA7, 0x72, 0xD1, 0x78, 0x08, 0x40, 0x9E, 0xDC, 0xCD, 0xAB, 0x92, 0x9A, 0x0F, 0x96, 0x91, 0xD0}
  146. #define IPSEC_VENDOR_ID_MICROSOFT {0x1E, 0x2B, 0x51, 0x69, 0x05, 0x99, 0x1C, 0x7D, 0x7C, 0x96, 0xFC, 0xBF, 0xB5, 0x87, 0xE4, 0x61}
  147. #define IPSEC_VENDOR_ID_MICROSOFT_MIN_VERSION 0x00000004
  148. #define IPSEC_VENDOR_ID_PAYLOAD_LENGTH 20
  149. #define IPSEC_VENDOR_HEADER_VENDOR_ID_OFFSET 4
  150. #define IPSEC_VENDOR_HEADER_VENDOR_ID_LENGTH 16
  151. #define IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET 20
  152. #define IPSEC_VENDOR_HEADER_VENDOR_VERSION_LENGTH 4
  153. typedef struct {
  154. UCHAR byte[IPSEC_GENERIC_HEADER_LENGTH + IPSEC_VENDOR_ID_PAYLOAD_LENGTH];
  155. } IPSEC_VENDOR_HDR, * PIPSEC_VENDOR_HDR;
  156. #define IPSEC_VENDOR_ID_GET_ID_POINTER(vendor_hdrp) ((PUCHAR)vendor_hdrp + IPSEC_VENDOR_HEADER_VENDOR_ID_OFFSET)
  157. #define IPSEC_VENDOR_ID_GET_VERSION(vendor_hdrp) ((ULONG)(((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET] << 24) | \
  158. ((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET + 1] << 16) | \
  159. ((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET + 2] << 8) | \
  160. ((vendor_hdrp)->byte[IPSEC_VENDOR_HEADER_VENDOR_VERSION_OFFSET + 3] << 0)))
  161. #define IPSEC_NOTIFY_INITIAL_CONTACT 24578
  162. #define IPSEC_NOTIFY_PAYLOAD_LENGTH 8
  163. #define IPSEC_NOTIFY_HEADER_NOTIFY_MESSAGE_OFFSET 10
  164. typedef struct {
  165. UCHAR byte[IPSEC_GENERIC_HEADER_LENGTH + IPSEC_NOTIFY_PAYLOAD_LENGTH];
  166. } IPSEC_NOTIFY_HDR, * PIPSEC_NOTIFY_HDR;
  167. #define IPSEC_NOTIFY_GET_NOTIFY_MESSAGE(notify_hdrp) ((USHORT)(((notify_hdrp)->byte[IPSEC_NOTIFY_HEADER_NOTIFY_MESSAGE_OFFSET] << 8) | \
  168. ((notify_hdrp)->byte[IPSEC_NOTIFY_HEADER_NOTIFY_MESSAGE_OFFSET + 1] << 0)))
  169. /* ARP header macros - note address locations assume 6 byte MAC (Ethernet)
  170. and 4 byte protocol (IP) sizes */
  171. /* type of hardware address */
  172. #define ARP_GET_MAC_TYPE(p) (((ULONG) ((p) -> byte[0]) << 8) | (ULONG) ((p) -> byte[1]))
  173. /* higher layer addressing protocol */
  174. #define ARP_GET_PROT_TYPE(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  175. /* length of hardware address */
  176. #define ARP_GET_MAC_LEN(p) ((ULONG) ((p) -> byte[4]))
  177. /* length of higher layer address */
  178. #define ARP_GET_PROT_LEN(p) ((ULONG) ((p) -> byte[5]))
  179. /* type of message */
  180. #define ARP_GET_MSG_TYPE(p) (((ULONG) ((p) -> byte[6]) << 8) | (ULONG) ((p) -> byte[7]))
  181. /* source hardware address */
  182. #define ARP_GET_SRC_MAC_PTR(p) (&((p) -> byte[8]))
  183. #define ARP_GET_SRC_MAC(p,n) ((ULONG) ((p) -> byte[8 + (n)]))
  184. /* source higher layer address */
  185. #define ARP_GET_SRC_PROT(p,n) ((ULONG) ((p) -> byte[14 + (n)]))
  186. #define ARP_GET_SRC_FPROT(p) (* ((PULONG) &((p) -> byte[14])))
  187. /* 64-bit -- ramkrish */
  188. #define ARP_GET_SRC_PROT_64(p) ((ULONG) (((p) -> byte[14] << 0) | ((p) -> byte[15] << 8) | \
  189. ((p) -> byte[16] << 16) | ((p) -> byte[17] << 24)))
  190. /* destination hardware address */
  191. #define ARP_GET_DST_MAC_PTR(p) (&((p) -> byte[18]))
  192. #define ARP_GET_DST_MAC(p,n) ((ULONG) ((p) -> byte[18 + (n)]))
  193. /* destination higher layer address */
  194. #define ARP_GET_DST_PROT(p,n) ((ULONG) ((p) -> byte[24 + (n)]))
  195. #define ARP_GET_DST_FPROT(p) (* ((PULONG) &((p) -> byte[24])))
  196. /* 64-bit -- ramkrish */
  197. #define ARP_GET_DST_PROT_64(p) ((ULONG) (((p) -> byte[18] << 0) | ((p) -> byte[19] << 8) | \
  198. ((p) -> byte[20] << 16) | ((p) -> byte[21] << 24)))
  199. #define ARP_MAC_TYPE_ETH 0x0001
  200. #define ARP_PROT_TYPE_IP 0x0800
  201. #define ARP_MAC_LEN_ETH 6
  202. #define ARP_PROT_LEN_IP 4
  203. #define ARP_MSG_TYPE_REQ 0x1
  204. #define ARP_MSG_TYPE_RSP 0x2
  205. /* IP datagram header macros */
  206. /* IP version number */
  207. #define IP_GET_VERS(p) ((ULONG) ((((p) -> byte[0]) >> 4) & 0xf))
  208. /* header length in 32-bit words */
  209. #define IP_GET_HLEN(p) ((ULONG) (((p) -> byte[0]) & 0xf))
  210. /* service type */
  211. #define IP_GET_SRVC(p) ((ULONG) ((p) -> byte[1]))
  212. /* total datagram packet length in bytes */
  213. #define IP_GET_PLEN(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  214. /* fragmentation identification - this one seems to have bytes swaped within
  215. the short word ??? */
  216. #define IP_GET_FRAG_ID(p) (((ULONG) ((p) -> byte[5]) << 8) | (ULONG) ((p) -> byte[4]))
  217. /* fragmentation flags */
  218. #define IP_GET_FRAG_FLGS(p) ((ULONG) ((((p) -> byte[6]) >> 5) & 0x7))
  219. /* fragmentation offset */
  220. #define IP_GET_FRAG_OFF(p) (((ULONG) ((p) -> byte[6] & 0x1f) << 8) | (ULONG) ((p) -> byte[7]))
  221. /* Time To Live in seconds */
  222. #define IP_GET_TTL(p) ((ULONG) ((p) -> byte[8]))
  223. /* higher level protocol id */
  224. #define IP_GET_PROT(p) ((ULONG) ((p) -> byte[9]))
  225. /* header checksum - this one seems to have bytes swaped within
  226. the short word ??? */
  227. #define IP_GET_CHKSUM(p) (((USHORT) ((p) -> byte[10]) << 8) | (USHORT) ((p) -> byte[11]))
  228. #define IP_SET_CHKSUM(p,c) (((p) -> byte[10] = (c) >> 8), ((p) -> byte[11] = (c) & 0xff))
  229. /* source IP address */
  230. #define IP_GET_SRC_ADDR(p,n) ((ULONG) ((p) -> byte[12 + (n)]))
  231. #define IP_GET_SRC_ADDR_PTR(p) (&((p) -> byte[12]))
  232. #define IP_GET_SRC_FADDR(p) (* ((PULONG) &((p) -> byte[12]))) /* 64-bit -- ramkrish */
  233. #ifdef _WIN64
  234. #define IP_GET_SRC_ADDR_64(p) ((ULONG) (((p) -> byte[12] << 0) | ((p) -> byte[13] << 8) | \
  235. ((p) -> byte[14] << 16) | ((p) -> byte[15] << 24)))
  236. #else
  237. // This is faster than the one above. This function is called in critical receiving path
  238. #define IP_GET_SRC_ADDR_64(p) (* ((PULONG) &((p) -> byte[12])))
  239. #endif
  240. /* destination IP address */
  241. #define IP_GET_DST_ADDR(p,n) ((ULONG) ((p) -> byte[16 + (n)]))
  242. #ifdef _WIN64
  243. #define IP_GET_DST_ADDR_64(p) ((ULONG) (((p) -> byte[16] << 0) | ((p) -> byte[17] << 8) | \
  244. ((p) -> byte[18] << 16) | ((p) -> byte[19] << 24)))
  245. #else
  246. // This is faster than the one above. This function is called in critical receiving path
  247. #define IP_GET_DST_ADDR_64(p) (* ((PULONG) &((p) -> byte[16])))
  248. #endif
  249. /* 64-bit -- ramkrish */
  250. #define IP_SET_SRC_ADDR_64(p,c) { \
  251. PUCHAR tmp = (PUCHAR) (&(c)); \
  252. (p) -> byte[12] = tmp[0]; (p) -> byte[13] = tmp[1]; \
  253. (p) -> byte[14] = tmp[2]; (p) -> byte[15] = tmp[3]; \
  254. }
  255. #define IP_SET_DST_ADDR_64(p,c) { \
  256. PUCHAR tmp = (PUCHAR) (&(c)); \
  257. (p) -> byte[16] = tmp[0]; (p) -> byte[17] = tmp[1]; \
  258. (p) -> byte[18] = tmp[2]; (p) -> byte[19] = tmp[3]; \
  259. }
  260. /* get IP address octets. */
  261. #define IP_GET_ADDR(p,b0,b1,b2,b3) { \
  262. *(b3) = ((p) & 0xff000000) >> 24; \
  263. *(b2) = ((p) & 0x00ff0000) >> 16; \
  264. *(b1) = ((p) & 0x0000ff00) >> 8; \
  265. *(b0) = ((p) & 0x000000ff) >> 0; \
  266. }
  267. /* Get the Nth octect of an IP address DWORD. The zeroeth octect is the least significant byte of the DWORD. */
  268. #define IP_GET_OCTET(p,n) (((p) & (0x000000ff << (8*(n)))) >> (8*(n)))
  269. /* create IP address from 4 bytes */
  270. #define IP_SET_ADDR(p,b0,b1,b2,b3) (* (p) = (((b0) << 0) | ((b1) << 8) | ((b2) << 16) | ((b3) << 24)))
  271. /* compute broadcast address from IP address and netmask */
  272. #define IP_SET_BCAST(p,a,m) (* (p) = ((a) & (m)) | (~(m)))
  273. /* TCP header macros */
  274. /* pointer to TCP header from IP header pointer */
  275. #define TCP_PTR(p) ((PTCP_HDR)(((ULONG *)(p)) + ((ULONG)IP_GET_HLEN(p))))
  276. /* source port */
  277. #define TCP_GET_SRC_PORT(p) (((ULONG) ((p) -> byte[0]) << 8) | (ULONG) ((p) -> byte[1]))
  278. #define TCP_GET_SRC_PORT_PTR(p) (& ((p) -> byte[0])) /* 64-bit -- ramkrish */
  279. /* destination port */
  280. #define TCP_GET_DST_PORT(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  281. #define TCP_GET_DST_PORT_PTR(p) (& ((p) -> byte[2])) /* 64-bit -- ramkrish */
  282. /* sequence number */
  283. #define TCP_GET_SEQ_NO(p) (((ULONG) ((p) -> byte[4]) << 24) | ((ULONG) ((p) -> byte[5]) << 16) | \
  284. ((ULONG) ((p) -> byte[6]) << 8) | (ULONG) ((p) -> byte[7]))
  285. /* acknowledgement number */
  286. #define TCP_GET_ACK_NO(p) (((ULONG) ((p) -> byte[8]) << 24) | ((ULONG) ((p) -> byte[9]) << 16) | \
  287. ((ULONG) ((p) -> byte[10]) << 8) | (ULONG) ((p) -> byte[11]))
  288. /* flags */
  289. #define TCP_GET_FLAGS(p) (((ULONG) ((p) -> byte[13])) & 0x3f)
  290. /* header length in 32-bit words */
  291. #define TCP_GET_HLEN(p) ((ULONG) (((p) -> byte[12]) >> 4))
  292. /* datagram length */
  293. #define TCP_GET_DGRAM_LEN(i,t) (IP_GET_PLEN (i) - ((IP_GET_HLEN (i) + TCP_GET_HLEN (t)) * sizeof (ULONG)))
  294. /* pointer to datagram */
  295. #define TCP_GET_DGRAM_PTR(p) ((PUCHAR)(((ULONG *)(p)) + ((ULONG) TCP_GET_HLEN(p))))
  296. /* checksum field */
  297. #define TCP_GET_CHKSUM(p) ((((USHORT)((p) -> byte[16])) << 8) | (USHORT)((p) -> byte[17]))
  298. #define TCP_SET_CHKSUM(p,c) (((p) -> byte[16] = (c) >> 8), ((p) -> byte[17] = (c) & 0xff))
  299. #define TCP_FLAG_URG 0x20
  300. #define TCP_FLAG_ACK 0x10
  301. #define TCP_FLAG_PSH 0x8
  302. #define TCP_FLAG_RST 0x4
  303. #define TCP_FLAG_SYN 0x2
  304. #define TCP_FLAG_FIN 0x1
  305. /* UDP header macros */
  306. /* pointer to TCP header from IP header pointer */
  307. #define UDP_PTR(p) ((PUDP_HDR)(((ULONG *)(p)) + ((ULONG)IP_GET_HLEN(p))))
  308. /* source port */
  309. #define UDP_GET_SRC_PORT(p) (((ULONG) ((p) -> byte[0]) << 8) | (ULONG) ((p) -> byte[1]))
  310. #define UDP_GET_SRC_PORT_PTR(p) (& ((p) -> byte[0]))
  311. #define UDP_GET_SRC_FPORT(p) (* ((PUSHORT) &((p) -> byte[0])))
  312. /* 64-bit -- ramkrish */
  313. #define UDP_SET_SRC_PORT_64(p,v) (((p) -> byte[0] = v >> 8), ((p) -> byte[1] = v & 0xff))
  314. /* destination port */
  315. #define UDP_GET_DST_PORT(p) (((ULONG) ((p) -> byte[2]) << 8) | (ULONG) ((p) -> byte[3]))
  316. #define UDP_GET_DST_PORT_PTR(p) (& ((p) -> byte[2]))
  317. #define UDP_GET_DST_FPORT(p) (* ((PUSHORT) &((p) -> byte[2])))
  318. /* 64-bit -- ramkrish */
  319. #define UDP_SET_DST_PORT_64(p,v) (((p) -> byte[2] = v >> 8), ((p) -> byte[3] = v & 0xff))
  320. /* packet length */
  321. #define UDP_GET_LEN(p) (((ULONG) ((p) -> byte[4]) << 8) | (ULONG) ((p) -> byte[5]))
  322. /* packet length */
  323. #define UDP_GET_CHKSUM(p) (((USHORT) ((p) -> byte[6]) << 8) | (USHORT) ((p) -> byte[7]))
  324. #define UDP_SET_CHKSUM(p,c) (((p) -> byte[6] = (c) >> 8), ((p) -> byte[7] = (c) & 0xff))
  325. /* pointer to datagram */
  326. #define UDP_GET_DGRAM_PTR(p) ((PUCHAR)(p) + sizeof (UDP_HDR))
  327. /* V1.11 NetBIOS name cluster name support */
  328. #define NBT_NAME_LEN 16
  329. #define NBT_ENCODED_NAME_LEN (2 * NBT_NAME_LEN) /* multiplier HAS to be 2 */
  330. #define NBT_ENCODED_NAME_BASE 'A'
  331. #define NBT_NAME_SHADOW "*SMBSERVER "
  332. #define NBT_ENCODED_NAME_SHADOW \
  333. { \
  334. 'C', 'K', 'F', 'D', 'E', 'N', 'E', 'C', 'F', 'D', 'E', 'F', 'F', 'C', 'F', 'G', \
  335. 'E', 'F', 'F', 'C', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A' \
  336. }
  337. #define NBT_ENCODE_FIRST(c) (((c) >> 4) + NBT_ENCODED_NAME_BASE)
  338. #define NBT_ENCODE_SECOND(c) (((c) & 0xf) + NBT_ENCODED_NAME_BASE)
  339. #define NBT_SESSION_PORT 139
  340. #define NBT_SESSION_REQUEST 0x81 /* packet type */
  341. typedef struct
  342. {
  343. UCHAR byte[72]; /* only the session request packet */
  344. }
  345. NBT_HDR, * PNBT_HDR;
  346. /* pointer to NBT header from TCP header */
  347. #define NBT_PTR(p) ((PNBT_HDR)(((ULONG *)(p)) + ((ULONG) TCP_GET_HLEN(p))))
  348. /* packet type */
  349. #define NBT_GET_PKT_TYPE(p) ((ULONG) ((p) -> byte[0]))
  350. /* packet length */
  351. #define NBT_GET_PKT_LEN(p) ((ULONG) ((p) -> byte[3]))
  352. /* called name */
  353. #define NBT_GET_CALLED_NAME(p) ((PUCHAR) & ((p) -> byte[4])) /* server's name */
  354. /* calling name */
  355. #define NBT_GET_CALLING_NAME(p) ((PUCHAR) & ((p) -> byte[36])) /* client's name */
  356. /* PPTP/IPSEC support */
  357. #define PPTP_CTRL_PORT 1723
  358. #define IPSEC_NAT_PORT 4500
  359. #define IPSEC_CTRL_PORT 500
  360. #define TCP_HTTP_PORT 80
  361. /* TCPIP module context */
  362. typedef struct
  363. {
  364. UCHAR nbt_encoded_cluster_name [NBT_ENCODED_NAME_LEN]; /* V1.2 */
  365. }
  366. TCPIP_CTXT, * PTCPIP_CTXT;
  367. #pragma pack()
  368. #endif /* _Tcpip_h_ */