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.

149 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. socket.c
  5. Abstract:
  6. This module implements the user mode DAV miniredir routines pertaining to
  7. initialization and closing of the socket data structures.
  8. Author:
  9. Rohan Kumar [RohanK] 27-May-1999
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #pragma hdrstop
  14. #include "ntumrefl.h"
  15. #include "usrmddav.h"
  16. #include "global.h"
  17. //
  18. // Implementation of functions begins here.
  19. //
  20. //
  21. // Data structure that is to receive details of the WinSock implementation.
  22. //
  23. WSADATA g_wsaData;
  24. BOOLEAN g_socketinit = FALSE;
  25. ULONG
  26. InitializeTheSocketInterface(
  27. VOID
  28. )
  29. /*++
  30. Routine Description:
  31. This routine initializes the socket interface. This has to be done before
  32. any WinSock calls can be made.
  33. Arguments:
  34. none.
  35. Return Value:
  36. The return status for the operation
  37. --*/
  38. {
  39. ULONG WStatus = ERROR_SUCCESS;
  40. int err;
  41. WORD VersionRequested;
  42. //
  43. // Request version 2.0.
  44. //
  45. VersionRequested = MAKEWORD(2, 0);
  46. //
  47. // The WSAStartup function must be the first Windows Sockets function
  48. // called.
  49. //
  50. err = WSAStartup(VersionRequested, &g_wsaData);
  51. if (err != 0) {
  52. //
  53. // We could not find a suitable Winsock lib.
  54. //
  55. DavPrint((DEBUG_ERRORS,
  56. "InitializeTheSocketInterface/WSAStartup: Error Val = %d.\n",
  57. err));
  58. WStatus = (ULONG)err;
  59. goto EXIT_THE_FUNCTION;
  60. }
  61. //
  62. // Confirm that the lib supports version 2.0. Only Winsock versions 1.1 or
  63. // higher support the GetHostByName call.
  64. //
  65. if (LOBYTE(g_wsaData.wVersion) != 2 || HIBYTE(g_wsaData.wVersion) != 0) {
  66. DavPrint((DEBUG_ERRORS,
  67. "InitializeTheSocketInterface/WSAStartup: Ver not supported.\n"));
  68. //
  69. // Cleanup and return error.
  70. //
  71. err = WSACleanup();
  72. if (err == SOCKET_ERROR) {
  73. WStatus = (ULONG)WSAGetLastError();
  74. DavPrint((DEBUG_ERRORS,
  75. "InitializeTheSocketInterface/WSACleanup: Error Val = "
  76. "%08lx.\n", WStatus));
  77. }
  78. WStatus = ERROR_NOT_SUPPORTED;
  79. goto EXIT_THE_FUNCTION;
  80. }
  81. EXIT_THE_FUNCTION:
  82. if (WStatus == ERROR_SUCCESS) {
  83. g_socketinit = TRUE;
  84. }
  85. return WStatus;
  86. }
  87. NTSTATUS
  88. CleanupTheSocketInterface(
  89. VOID
  90. )
  91. /*++
  92. Routine Description:
  93. This routine cleansup the data structures created during the initialization
  94. of the socket interface.
  95. Arguments:
  96. none.
  97. Return Value:
  98. The return status for the operation
  99. --*/
  100. {
  101. ULONG WStatus = ERROR_SUCCESS;
  102. int err;
  103. err = WSACleanup();
  104. if (err == SOCKET_ERROR) {
  105. WStatus = (ULONG)WSAGetLastError();
  106. DavPrint((DEBUG_ERRORS,
  107. "CleanupTheSocketInterface/WSACleanup: Error Val = "
  108. "%08lx.\n", WStatus));
  109. }
  110. return WStatus;
  111. }