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.

131 lines
2.7 KiB

  1. /* Copyright (c) 1993, Microsoft Corporation, all rights reserved
  2. **
  3. ** hostwire.c
  4. ** Gidwanian Host<-->Wire format conversions.
  5. */
  6. #include <windows.h>
  7. #define INCL_HOSTWIRE
  8. #include "ppputil.h"
  9. //**
  10. //
  11. // Call: HostToWireFormat16
  12. //
  13. // Returns: None
  14. //
  15. // Description: Will convert a 16 bit integer from host format to wire format
  16. //
  17. VOID
  18. HostToWireFormat16(
  19. IN WORD wHostFormat,
  20. IN OUT PBYTE pWireFormat
  21. )
  22. {
  23. *((PBYTE)(pWireFormat)+0) = (BYTE) ((DWORD)(wHostFormat) >> 8);
  24. *((PBYTE)(pWireFormat)+1) = (BYTE) (wHostFormat);
  25. }
  26. //**
  27. //
  28. // Call: HostToWireFormat16U
  29. //
  30. // Returns: None
  31. //
  32. // Description: Will convert a 16 bit integer from host format to wire format
  33. // (accepts unaligned wire data).
  34. //
  35. VOID
  36. HostToWireFormat16U(
  37. IN WORD wHostFormat,
  38. IN OUT PBYTE pWireFormat
  39. )
  40. {
  41. *((PBYTE )(pWireFormat)+0) = (BYTE) ((DWORD)(wHostFormat) >> 8);
  42. *((PBYTE )(pWireFormat)+1) = (BYTE) (wHostFormat);
  43. }
  44. //**
  45. //
  46. // Call: WireToHostFormat16
  47. //
  48. // Returns: WORD - Representing the integer in host format.
  49. //
  50. // Description: Will convert a 16 bit integer from wire format to host format
  51. //
  52. WORD
  53. WireToHostFormat16(
  54. IN PBYTE pWireFormat
  55. )
  56. {
  57. WORD wHostFormat = ((*((PBYTE)(pWireFormat)+0) << 8) +
  58. (*((PBYTE)(pWireFormat)+1)));
  59. return( wHostFormat );
  60. }
  61. //**
  62. //
  63. // Call: WireToHostFormat16
  64. //
  65. // Returns: WORD - Representing the integer in host format.
  66. //
  67. // Description: Will convert a 16 bit integer from wire format to host format
  68. // (accepts unaligned wire data)
  69. //
  70. WORD
  71. WireToHostFormat16U(
  72. IN PBYTE pWireFormat
  73. )
  74. {
  75. WORD wHostFormat = ((*((PBYTE )(pWireFormat)+0) << 8) +
  76. (*((PBYTE )(pWireFormat)+1)));
  77. return( wHostFormat );
  78. }
  79. //**
  80. //
  81. // Call: HostToWireFormat32
  82. //
  83. // Returns: nonr
  84. //
  85. // Description: Will convert a 32 bit integer from host format to wire format
  86. //
  87. VOID
  88. HostToWireFormat32(
  89. IN DWORD dwHostFormat,
  90. IN OUT PBYTE pWireFormat
  91. )
  92. {
  93. *((PBYTE)(pWireFormat)+0) = (BYTE) ((DWORD)(dwHostFormat) >> 24);
  94. *((PBYTE)(pWireFormat)+1) = (BYTE) ((DWORD)(dwHostFormat) >> 16);
  95. *((PBYTE)(pWireFormat)+2) = (BYTE) ((DWORD)(dwHostFormat) >> 8);
  96. *((PBYTE)(pWireFormat)+3) = (BYTE) (dwHostFormat);
  97. }
  98. //**
  99. //
  100. // Call: WireToHostFormat32
  101. //
  102. // Returns: DWORD - Representing the integer in host format.
  103. //
  104. // Description: Will convert a 32 bit integer from wire format to host format
  105. //
  106. DWORD
  107. WireToHostFormat32(
  108. IN PBYTE pWireFormat
  109. )
  110. {
  111. DWORD dwHostFormat = ((*((PBYTE)(pWireFormat)+0) << 24) +
  112. (*((PBYTE)(pWireFormat)+1) << 16) +
  113. (*((PBYTE)(pWireFormat)+2) << 8) +
  114. (*((PBYTE)(pWireFormat)+3) ));
  115. return( dwHostFormat );
  116. }