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.

178 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. spxutils.h
  5. Abstract:
  6. Author:
  7. Nikhil Kamkolkar (nikhilk) 11-November-1993
  8. Environment:
  9. Kernel mode
  10. Revision History:
  11. --*/
  12. // For PROTO_SPX, i'd return a device name from the dll of the form
  13. // \Device\NwlnkSpx\SpxStream (for SOCK_STREAM) or
  14. // \Device\NwlnkSpx\Spx (for SOCK_SEQPKT)
  15. //
  16. // and for PROTO_SPXII (the more common case we hope, even if
  17. // internally we degrade to SPX1 cause of the remote client's
  18. // limitations)
  19. // \Device\NwlnkSpx\Stream (for SOCK_STREAM) or
  20. // \Device\NwlnkSpx (for SOCK_SEQPKT)
  21. #define SOCKET1STREAM_SUFFIX L"\\SpxStream"
  22. #define SOCKET1_SUFFIX L"\\Spx"
  23. #define SOCKET2STREAM_SUFFIX L"\\Stream"
  24. #define SOCKET1_TYPE_SEQPKT 0
  25. #define SOCKET2_TYPE_SEQPKT 1
  26. #define SOCKET1_TYPE_STREAM 2
  27. #define SOCKET2_TYPE_STREAM 3
  28. #define IN_RANGE(_S, _RangeStart, _RangeEnd) \
  29. ((_S >= _RangeStart) && (_S <= _RangeEnd))
  30. //
  31. // The following macros deal with on-the-wire integer and long values
  32. //
  33. // On the wire format is big-endian i.e. a long value of 0x01020304 is
  34. // represented as 01 02 03 04. Similarly an int value of 0x0102 is
  35. // represented as 01 02.
  36. //
  37. // The host format is not assumed since it will vary from processor to
  38. // processor.
  39. //
  40. // Get a byte from on-the-wire format to a short in the host format
  41. #define GETBYTE2SHORT(DstPtr, SrcPtr) \
  42. *(PUSHORT)(DstPtr) = (USHORT) (*(PBYTE)(SrcPtr))
  43. // Get a byte from on-the-wire format to a short in the host format
  44. #define GETBYTE2ULONG(DstPtr, SrcPtr) \
  45. *(PULONG)(DstPtr) = (ULONG) (*(PBYTE)(SrcPtr))
  46. // Get a short from on-the-wire format to a dword in the host format
  47. #define GETSHORT2ULONG(DstPtr, SrcPtr) \
  48. *(PULONG)(DstPtr) = ((*((PBYTE)(SrcPtr)+0) << 8) + \
  49. (*((PBYTE)(SrcPtr)+1) ))
  50. // Get a short from on-the-wire format to a dword in the host format
  51. #define GETSHORT2SHORT(DstPtr, SrcPtr) \
  52. *(PUSHORT)(DstPtr) = ((*((PBYTE)(SrcPtr)+0) << 8) + \
  53. (*((PBYTE)(SrcPtr)+1) ))
  54. // Get a dword from on-the-wire format to a dword in the host format
  55. #define GETULONG2ULONG(DstPtr, SrcPtr) \
  56. *(PULONG)(DstPtr) = ((*((PBYTE)(SrcPtr)+0) << 24) + \
  57. (*((PBYTE)(SrcPtr)+1) << 16) + \
  58. (*((PBYTE)(SrcPtr)+2) << 8) + \
  59. (*((PBYTE)(SrcPtr)+3) ))
  60. // Get a dword from on-the-wire format to a dword in the same format but
  61. // also watch out for alignment
  62. #define GETULONG2ULONG_NOCONV(DstPtr, SrcPtr) \
  63. *((PBYTE)(DstPtr)+0) = *((PBYTE)(SrcPtr)+0); \
  64. *((PBYTE)(DstPtr)+1) = *((PBYTE)(SrcPtr)+1); \
  65. *((PBYTE)(DstPtr)+2) = *((PBYTE)(SrcPtr)+2); \
  66. *((PBYTE)(DstPtr)+3) = *((PBYTE)(SrcPtr)+3);
  67. // Put a dword from the host format to a short to on-the-wire format
  68. #define PUTBYTE2BYTE(DstPtr, Src) \
  69. *((PBYTE)(DstPtr)) = (BYTE)(Src)
  70. // Put a dword from the host format to a short to on-the-wire format
  71. #define PUTSHORT2BYTE(DstPtr, Src) \
  72. *((PBYTE)(DstPtr)) = ((USHORT)(Src) % 256)
  73. // Put a dword from the host format to a short to on-the-wire format
  74. #define PUTSHORT2SHORT(DstPtr, Src) \
  75. *((PBYTE)(DstPtr)+0) = (BYTE) ((USHORT)(Src) >> 8), \
  76. *((PBYTE)(DstPtr)+1) = (BYTE)(Src)
  77. // Put a dword from the host format to a byte to on-the-wire format
  78. #define PUTULONG2BYTE(DstPtr, Src) \
  79. *(PBYTE)(DstPtr) = (BYTE)(Src)
  80. // Put a dword from the host format to a short to on-the-wire format
  81. #define PUTULONG2SHORT(DstPtr, Src) \
  82. *((PBYTE)(DstPtr)+0) = (BYTE) ((ULONG)(Src) >> 8), \
  83. *((PBYTE)(DstPtr)+1) = (BYTE) (Src)
  84. // Put a dword from the host format to a dword to on-the-wire format
  85. #define PUTULONG2ULONG(DstPtr, Src) \
  86. *((PBYTE)(DstPtr)+0) = (BYTE) ((ULONG)(Src) >> 24), \
  87. *((PBYTE)(DstPtr)+1) = (BYTE) ((ULONG)(Src) >> 16), \
  88. *((PBYTE)(DstPtr)+2) = (BYTE) ((ULONG)(Src) >> 8), \
  89. *((PBYTE)(DstPtr)+3) = (BYTE) (Src)
  90. // Put a BYTE[4] array into another BYTE4 array.
  91. #define PUTBYTE42BYTE4(DstPtr, SrcPtr) \
  92. *((PBYTE)(DstPtr)+0) = *((PBYTE)(SrcPtr)+0), \
  93. *((PBYTE)(DstPtr)+1) = *((PBYTE)(SrcPtr)+1), \
  94. *((PBYTE)(DstPtr)+2) = *((PBYTE)(SrcPtr)+2), \
  95. *((PBYTE)(DstPtr)+3) = *((PBYTE)(SrcPtr)+3)
  96. // MIN/MAX macros
  97. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  98. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  99. // Exported prototypes
  100. UINT
  101. SpxUtilWstrLength(
  102. IN PWSTR Wstr);
  103. LONG
  104. SpxRandomNumber(
  105. VOID);
  106. NTSTATUS
  107. SpxUtilGetSocketType(
  108. PUNICODE_STRING RemainingFileName,
  109. PBYTE SocketType);
  110. VOID
  111. SpxSleep(
  112. IN ULONG TimeInMs);
  113. ULONG
  114. SpxBuildTdiAddress(
  115. IN PVOID AddressBuffer,
  116. IN ULONG AddressBufferLength,
  117. IN UCHAR Network[4],
  118. IN UCHAR Node[6],
  119. IN USHORT Socket);
  120. VOID
  121. SpxBuildTdiAddressFromIpxAddr(
  122. IN PVOID AddressBuffer,
  123. IN PBYTE pIpxAddr);
  124. TDI_ADDRESS_IPX UNALIGNED *
  125. SpxParseTdiAddress(
  126. IN TRANSPORT_ADDRESS UNALIGNED * TransportAddress);
  127. BOOLEAN
  128. SpxValidateTdiAddress(
  129. IN TRANSPORT_ADDRESS UNALIGNED * TransportAddress,
  130. IN ULONG TransportAddressLength);
  131. VOID
  132. SpxCalculateNewT1(
  133. IN struct _SPX_CONN_FILE * pSpxConnFile,
  134. IN int NewT1);