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.

181 lines
4.8 KiB

  1. //////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // connect.cpp
  7. //
  8. // Abstract:
  9. // This module contains code which implements connection-related
  10. // commands from the exe
  11. //
  12. //////////////////////////////////////////////////////////
  13. #include "stdafx.h"
  14. // --------------------------------------------------------------------
  15. //
  16. // Function: DoConnect
  17. //
  18. // Arguments: ulTdiEndpointHandle -- handle of endpoint
  19. // pTransportAddress -- address to connect to
  20. // ulTimeout -- how long to wait for connection
  21. //
  22. // Returns: Final status of connect
  23. //
  24. // Descript: This function causes the driver to try and connect to
  25. // a remote address
  26. //
  27. //---------------------------------------------------------------------
  28. NTSTATUS
  29. DoConnect(ULONG ulTdiEndpointHandle,
  30. PTRANSPORT_ADDRESS pTransportAddress,
  31. ULONG ulTimeout)
  32. {
  33. RECEIVE_BUFFER ReceiveBuffer; // return info from command
  34. SEND_BUFFER SendBuffer; // arguments for command
  35. //
  36. // set up arguments
  37. //
  38. SendBuffer.TdiHandle = ulTdiEndpointHandle;
  39. SendBuffer.COMMAND_ARGS.ConnectArgs.ulTimeout = ulTimeout;
  40. memcpy(&SendBuffer.COMMAND_ARGS.ConnectArgs.TransAddr,
  41. pTransportAddress,
  42. (FIELD_OFFSET(TRANSPORT_ADDRESS, Address)
  43. + FIELD_OFFSET(TA_ADDRESS, Address)
  44. + pTransportAddress->Address[0].AddressLength));
  45. //
  46. // call the driver
  47. //
  48. return TdiLibDeviceIO(ulCONNECT,
  49. &SendBuffer,
  50. &ReceiveBuffer);
  51. }
  52. // --------------------------------------------------------------------
  53. //
  54. // Function: DoDisconnect
  55. //
  56. // Arguments: TdiEndpointHandle -- handle of endpoint object
  57. // ulFlags -- how to perform disconnect
  58. //
  59. // Returns: none
  60. //
  61. // Descript: This function causes the driver to disconnect the local
  62. // endpoint from its connection with a remote endpoint
  63. //
  64. //---------------------------------------------------------------------
  65. VOID
  66. DoDisconnect(ULONG ulTdiEndpointHandle,
  67. ULONG ulFlags)
  68. {
  69. RECEIVE_BUFFER ReceiveBuffer; // return info from command
  70. SEND_BUFFER SendBuffer; // arguments for command
  71. //
  72. // set up arguments
  73. //
  74. SendBuffer.TdiHandle = ulTdiEndpointHandle;
  75. SendBuffer.COMMAND_ARGS.ulFlags = ulFlags;
  76. //
  77. // call the driver
  78. //
  79. NTSTATUS lStatus = TdiLibDeviceIO(ulDISCONNECT,
  80. &SendBuffer,
  81. &ReceiveBuffer);
  82. if (lStatus != STATUS_SUCCESS)
  83. {
  84. _tprintf(TEXT("DoDisconnect: failure, status = %s\n"), TdiLibStatusMessage(lStatus));
  85. }
  86. }
  87. // --------------------------------------------------------------------
  88. //
  89. // Function: DoListen
  90. //
  91. // Arguments: TdiEndpointHandle -- handle of endpoint object
  92. //
  93. // Returns: final status of command
  94. //
  95. // Descript: This function causes the driver to listen for a connection
  96. // request from a remote endpoint
  97. //
  98. //---------------------------------------------------------------------
  99. NTSTATUS
  100. DoListen(ULONG ulTdiEndpointHandle)
  101. {
  102. RECEIVE_BUFFER ReceiveBuffer; // return info from command
  103. SEND_BUFFER SendBuffer; // arguments for command
  104. //
  105. // set up arguments
  106. //
  107. SendBuffer.TdiHandle = ulTdiEndpointHandle;
  108. //
  109. // call the driver
  110. //
  111. return TdiLibDeviceIO(ulLISTEN,
  112. &SendBuffer,
  113. &ReceiveBuffer);
  114. }
  115. // --------------------------------------------------------------------
  116. //
  117. // Function: DoIsConnected
  118. //
  119. // Arguments: TdiEndpointHandle -- handle of endpoint object
  120. //
  121. // Returns: TRUE if connected, FALSE if not
  122. //
  123. // Descript: This function causes the driver to check on the connect
  124. // status of an endpoint
  125. //
  126. //---------------------------------------------------------------------
  127. BOOLEAN
  128. DoIsConnected(ULONG ulTdiEndpointHandle)
  129. {
  130. RECEIVE_BUFFER ReceiveBuffer; // return info from command
  131. SEND_BUFFER SendBuffer; // arguments for command
  132. //
  133. // set up arguments
  134. //
  135. SendBuffer.TdiHandle = ulTdiEndpointHandle;
  136. //
  137. // call the driver
  138. //
  139. if (TdiLibDeviceIO(ulISCONNECTED,
  140. &SendBuffer,
  141. &ReceiveBuffer) == STATUS_SUCCESS)
  142. {
  143. return (BOOLEAN)ReceiveBuffer.RESULTS.ulReturnValue;
  144. }
  145. return FALSE;
  146. }
  147. ////////////////////////////////////////////////////////////////////
  148. // end of file connect.cpp
  149. ////////////////////////////////////////////////////////////////////