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.

204 lines
5.1 KiB

  1. //============================================================================
  2. // Copyright(c) 1996, Microsoft Corporation
  3. //
  4. // File: datafmt.cpp
  5. //
  6. // History:
  7. // 08/30/96 Ram Cherala Created
  8. //
  9. // Implementation of IPX data formatting routines
  10. //============================================================================
  11. // helper routines for data formatting - copied from ..\ipxadmin\datafmt.cpp
  12. #include "stdafx.h"
  13. #include "resource.h"
  14. #include "datafmt.h"
  15. CString&
  16. operator << (
  17. CString& str,
  18. CIPX_NETWORK& net
  19. ) {
  20. str.Format (TEXT ("%.2x%.2x%.2x%.2x"),
  21. net.m_pNet[0],net.m_pNet[1],net.m_pNet[2],net.m_pNet[3]);
  22. return str;
  23. }
  24. LPTSTR&
  25. operator << (
  26. LPTSTR& str,
  27. CIPX_NETWORK& net
  28. ) {
  29. _stprintf (str, TEXT ("%.2x%.2x%.2x%.2x"),
  30. net.m_pNet[0],net.m_pNet[1],net.m_pNet[2],net.m_pNet[3]);
  31. return str;
  32. }
  33. CString&
  34. operator >> (
  35. CString& str,
  36. CIPX_NETWORK &net
  37. ) {
  38. ULONG val; INT n;
  39. if ((_stscanf (str, TEXT("%lx%n"), &val, &n)==1) && (n==str.GetLength())) {
  40. net.m_pNet[0] = (UCHAR)(val>>24);
  41. net.m_pNet[1] = (UCHAR)(val>>16);
  42. net.m_pNet[2] = (UCHAR)(val>>8);
  43. net.m_pNet[3] = (UCHAR)(val);
  44. return str;
  45. }
  46. AfxMessageBox (IDS_INVALID_NETWORK_NUMBER);
  47. // throw (DWORD)ERROR_INVALID_DATA;
  48. return str;
  49. }
  50. CString&
  51. operator << (
  52. CString& str,
  53. CIPX_NODE& node
  54. ) {
  55. str.Format (TEXT ("%.2x%.2x%.2x%.2x%.2x%.2x"),
  56. node.m_pNode[0],node.m_pNode[1],node.m_pNode[2],
  57. node.m_pNode[3],node.m_pNode[4],node.m_pNode[5]);
  58. return str;
  59. }
  60. LPTSTR&
  61. operator << (
  62. LPTSTR& str,
  63. CIPX_NODE& node
  64. ) {
  65. _stprintf (str, TEXT ("%.2x%.2x%.2x%.2x%.2x%.2x"),
  66. node.m_pNode[0],node.m_pNode[1],node.m_pNode[2],
  67. node.m_pNode[3],node.m_pNode[4],node.m_pNode[5]);
  68. return str;
  69. }
  70. CString&
  71. operator >> (
  72. CString& str,
  73. CIPX_NODE &node
  74. ) {
  75. ULONGLONG val; INT n;
  76. if ((_stscanf (str, TEXT("%I64x%n"), &val, &n)==1)
  77. && (val<=0xFFFFFFFFFFFFI64)
  78. && (n==str.GetLength())) {
  79. node.m_pNode[0] = (UCHAR)(val>>40);
  80. node.m_pNode[1] = (UCHAR)(val>>32);
  81. node.m_pNode[2] = (UCHAR)(val>>24);
  82. node.m_pNode[3] = (UCHAR)(val>>16);
  83. node.m_pNode[4] = (UCHAR)(val>>8);
  84. node.m_pNode[5] = (UCHAR)(val);
  85. return str;
  86. }
  87. AfxMessageBox (IDS_INVALID_NODE_NUMBER);
  88. // throw (DWORD)ERROR_INVALID_DATA;
  89. return str;
  90. }
  91. CString&
  92. operator << (
  93. CString& str,
  94. CIPX_SOCKET &sock
  95. ) {
  96. str.Format (TEXT ("%.2x%.2x"),
  97. sock.m_pSock[0],sock.m_pSock[1]);
  98. return str;
  99. }
  100. LPTSTR&
  101. operator << (
  102. LPTSTR& str,
  103. CIPX_SOCKET &sock
  104. ) {
  105. _stprintf (str, TEXT ("%.2x%.2x"),
  106. sock.m_pSock[0],sock.m_pSock[1]);
  107. return str;
  108. }
  109. CString&
  110. operator >> (
  111. CString& str,
  112. CIPX_SOCKET &sock
  113. ) {
  114. USHORT val; INT n;
  115. if ((_stscanf (str, TEXT("%hx%n"), &val, &n)==1) && (n==str.GetLength())) {
  116. sock.m_pSock[0] = (UCHAR)(val>>8);
  117. sock.m_pSock[1] = (UCHAR)(val);
  118. return str;
  119. }
  120. AfxMessageBox (IDS_INVALID_SOCKET_NUMBER);
  121. // throw (DWORD)ERROR_INVALID_DATA;
  122. return str;
  123. }
  124. CString&
  125. operator << (
  126. CString& str,
  127. CIPX_PACKET_TYPE& type
  128. ) {
  129. str.Format (TEXT ("%.1x"), *type.m_pType);
  130. return str;
  131. }
  132. LPTSTR&
  133. operator << (
  134. LPTSTR& str,
  135. CIPX_PACKET_TYPE& type
  136. ) {
  137. _stprintf (str, TEXT ("%.1x"), *type.m_pType);
  138. return str;
  139. }
  140. CString&
  141. operator >> (
  142. CString& str,
  143. CIPX_PACKET_TYPE& type
  144. ) {
  145. INT n;
  146. CString cStr;
  147. if ((_stscanf (str, TEXT("%hx%n"), type.m_pType, &n)==1)
  148. && (n==str.GetLength())) {
  149. return str;
  150. }
  151. AfxMessageBox (IDS_INVALID_SERVICE_TYPE);
  152. // throw (DWORD)ERROR_INVALID_DATA;
  153. return str;
  154. }
  155. CString&
  156. operator << (
  157. CString& str,
  158. CIPX_ADDRESS &addr
  159. ) {
  160. str.Format (TEXT ("%.2x%.2x%.2x%.2x.%.2x%.2x%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x.%.2x%.2x"),
  161. addr.m_pNet[0],addr.m_pNet[1],addr.m_pNet[2],addr.m_pNet[3],
  162. addr.m_pMask[0],addr.m_pMask[1],addr.m_pMask[2],addr.m_pMask[3],
  163. addr.m_pNode[0],addr.m_pNode[1],addr.m_pNode[2],
  164. addr.m_pNode[3],addr.m_pNode[4],addr.m_pNode[5],
  165. addr.m_pSock[0],addr.m_pSock[1]);
  166. return str;
  167. }
  168. LPTSTR&
  169. operator << (
  170. LPTSTR& str,
  171. CIPX_ADDRESS &addr
  172. ) {
  173. _stprintf (str, TEXT ("%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x.%.2x%.2x"),
  174. addr.m_pNet[0],addr.m_pNet[1],addr.m_pNet[2],addr.m_pNet[3],
  175. addr.m_pMask[0],addr.m_pMask[1],addr.m_pMask[2],addr.m_pMask[3],
  176. addr.m_pNode[0],addr.m_pNode[1],addr.m_pNode[2],
  177. addr.m_pNode[3],addr.m_pNode[4],addr.m_pNode[5],
  178. addr.m_pSock[0],addr.m_pSock[1]);
  179. return str;
  180. }