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.

55 lines
1.8 KiB

  1. /*******************************************************************/
  2. /* Copyright(c) 1993 Microsoft Corporation */
  3. /*******************************************************************/
  4. //***
  5. //
  6. // Filename: utils.h
  7. //
  8. // Description: Contains miscellaneous utilities
  9. //
  10. // Author: Stefan Solomon (stefans) October 4, 1993.
  11. //
  12. // Revision History:
  13. //
  14. //***
  15. #ifndef _UTILS_
  16. #define _UTILS_
  17. /*
  18. * The following macros deal with on-the-wire short and long values
  19. *
  20. * On the wire format is big-endian i.e. a long value of 0x01020304 is
  21. * represented as 01 02 03 04.
  22. * Similarly a short value of 0x0102 is represented as 01 02.
  23. *
  24. * The host format is not assumed since it will vary from processor to
  25. * processor.
  26. */
  27. // Get a short from on-the-wire format to a USHORT in the host format
  28. #define GETSHORT2USHORT(DstPtr, SrcPtr) \
  29. *(PUSHORT)(DstPtr) = ((*((PUCHAR)(SrcPtr)+0) << 8) + \
  30. (*((PUCHAR)(SrcPtr)+1) ))
  31. // Get a long from on-the-wire format to a ULONG in the host format
  32. #define GETLONG2ULONG(DstPtr, SrcPtr) \
  33. *(PULONG)(DstPtr) = ((*((PUCHAR)(SrcPtr)+0) << 24) + \
  34. (*((PUCHAR)(SrcPtr)+1) << 16) + \
  35. (*((PUCHAR)(SrcPtr)+2) << 8) + \
  36. (*((PUCHAR)(SrcPtr)+3) ))
  37. // Put a USHORT from the host format to a short to on-the-wire format
  38. #define PUTUSHORT2SHORT(DstPtr, Src) \
  39. *((PUCHAR)(DstPtr)+0) = (UCHAR) ((USHORT)(Src) >> 8), \
  40. *((PUCHAR)(DstPtr)+1) = (UCHAR)(Src)
  41. // Put a ULONG from the host format to an array of 4 UCHARs on-the-wire format
  42. #define PUTULONG2LONG(DstPtr, Src) \
  43. *((PUCHAR)(DstPtr)+0) = (UCHAR) ((ULONG)(Src) >> 24), \
  44. *((PUCHAR)(DstPtr)+1) = (UCHAR) ((ULONG)(Src) >> 16), \
  45. *((PUCHAR)(DstPtr)+2) = (UCHAR) ((ULONG)(Src) >> 8), \
  46. *((PUCHAR)(DstPtr)+3) = (UCHAR) (Src)
  47. #endif // _UTILS_