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.

197 lines
4.9 KiB

  1. //++
  2. //
  3. // Copyright (C) Microsoft Corporation, 1987 - 1999
  4. //
  5. // Module Name:
  6. //
  7. // winsock.c
  8. //
  9. // Abstract:
  10. //
  11. // Queries into network drivers
  12. //
  13. // Author:
  14. //
  15. // Anilth - 4-20-1998
  16. //
  17. // Environment:
  18. //
  19. // User mode only.
  20. // Contains NT-specific code.
  21. //
  22. // Revision History:
  23. //
  24. //--
  25. #include "precomp.h"
  26. HRESULT WinsockTest( NETDIAG_PARAMS* pParams, NETDIAG_RESULT* pResults)
  27. {
  28. int err,i;
  29. LPWSAPROTOCOL_INFO lpProtocolBuffer = NULL;
  30. DWORD reqd_length;
  31. SOCKET sock;
  32. UINT optval;
  33. int optlen;
  34. WSADATA WSAData;
  35. HRESULT hr = S_OK;
  36. PrintStatusMessage(pParams,0, IDS_WINSOCK_STATUS_MSG);
  37. err = WSAStartup(MAKEWORD( 2, 0 ), &WSAData);
  38. if(err != 0) // error
  39. {
  40. CHK_HR_CONTEXT(pResults->Winsock, hr = HRESULT_FROM_WIN32(err), IDS_WINSOCK_FAILED_START);
  41. };
  42. // determine the length of the buffer needed
  43. reqd_length = 0;
  44. err = WSAEnumProtocols(NULL, NULL, &reqd_length);
  45. if(reqd_length == 0 || reqd_length == -1)
  46. {
  47. err = WSAGetLastError();
  48. CHK_HR_CONTEXT(pResults->Winsock, hr = HRESULT_FROM_WIN32(err), IDS_WINSOCK_FAILED_ENUM);
  49. };
  50. lpProtocolBuffer = (LPWSAPROTOCOL_INFO)Malloc(reqd_length);
  51. if (lpProtocolBuffer == NULL) {
  52. CHK_HR_CONTEXT(pResults->Winsock, hr = E_OUTOFMEMORY, IDS_WINSOCK_FAILED_ENUM);
  53. }
  54. ZeroMemory( lpProtocolBuffer, reqd_length );
  55. // get the information of the protocols
  56. err = WSAEnumProtocols(
  57. NULL,
  58. (LPWSAPROTOCOL_INFO)lpProtocolBuffer,
  59. (LPDWORD)&reqd_length
  60. );
  61. if(err == SOCKET_ERROR)
  62. {
  63. err = WSAGetLastError();
  64. CHK_HR_CONTEXT(pResults->Winsock, hr = HRESULT_FROM_WIN32(err), IDS_WINSOCK_FAILED_ENUM);
  65. }
  66. pResults->Winsock.dwProts = err; // number of protocols
  67. pResults->Winsock.pProtInfo = lpProtocolBuffer; // protocol information array
  68. //
  69. // Other TCP/IP information
  70. //
  71. sock = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
  72. if ( sock == INVALID_SOCKET)
  73. {
  74. err = WSAGetLastError();
  75. CHK_HR_CONTEXT(pResults->Winsock, hr = HRESULT_FROM_WIN32(err), IDS_WINSOCK_FAILED_UDPSOCKET);
  76. }
  77. optlen = sizeof(optval);
  78. err = getsockopt(sock, SOL_SOCKET, SO_MAX_MSG_SIZE, (char FAR*)&optval, (int FAR*)&optlen);
  79. if (err == SOCKET_ERROR)
  80. {
  81. err = WSAGetLastError();
  82. CHK_HR_CONTEXT(pResults->Winsock, hr = HRESULT_FROM_WIN32(err), IDS_WINSOCK_FAILED_UDPSOCKET);
  83. }
  84. pResults->Winsock.dwMaxUDP = optval;
  85. L_ERR:
  86. WSACleanup();
  87. //$REVIEW (nsun) we should return S_FALSE so that we can go on with
  88. //other tests
  89. if (!FHrOK(hr))
  90. hr = S_FALSE;
  91. return hr;
  92. } /* END OF WINSTest() */
  93. void WinsockGlobalPrint(IN NETDIAG_PARAMS *pParams, IN OUT NETDIAG_RESULT *pResults)
  94. {
  95. DWORD i = 0;
  96. LPWSAPROTOCOL_INFO pProtInfo = pResults->Winsock.pProtInfo;
  97. // print out the test result
  98. if (pParams->fVerbose || !FHrOK(pResults->Winsock.hr))
  99. {
  100. PrintNewLine(pParams, 2);
  101. PrintTestTitleResult(pParams,
  102. IDS_WINSOCK_LONG,
  103. IDS_WINSOCK_SHORT,
  104. TRUE,
  105. pResults->Winsock.hr, 0);
  106. }
  107. if (pParams->fReallyVerbose || !FHrOK(pResults->Winsock.hr))
  108. {
  109. if (!FHrOK(pResults->Winsock.hr))
  110. {
  111. PrintError(pParams, pResults->Winsock.idsContext, pResults->Winsock.hr);
  112. }
  113. }
  114. if (pParams->fReallyVerbose)
  115. {
  116. if(pProtInfo)
  117. {
  118. // if there is any information about the providers
  119. // " The number of protocols which have been reported : %d\n"
  120. PrintMessage(pParams, IDS_WINSOCK_12605, pResults->Winsock.dwProts);
  121. for (i = 0; i < pResults->Winsock.dwProts ; i++)
  122. {
  123. // " Description: %s\n"
  124. PrintMessage(pParams, IDS_WINSOCK_12606,pProtInfo->szProtocol);
  125. // " Provider Version :%d\n"
  126. PrintMessage(pParams, IDS_WINSOCK_12607,pProtInfo->iVersion);
  127. switch(pProtInfo++->dwMessageSize){
  128. case 0:
  129. // " Max message size : Stream Oriented\n"
  130. PrintMessage(pParams, IDS_WINSOCK_12608);
  131. break;
  132. case 1:
  133. // " Max message size : Message Oriented\n"
  134. PrintMessage(pParams, IDS_WINSOCK_12609);
  135. break;
  136. case 0xffffffff:
  137. // " Max message size : depends on MTU\n"
  138. PrintMessage(pParams, IDS_WINSOCK_12610);
  139. break;
  140. }
  141. }
  142. }
  143. // if there is any information about the UDP size
  144. if(pResults->Winsock.dwMaxUDP)
  145. // "\n Max UDP size : %d bytes\n"
  146. PrintMessage(pParams, IDS_WINSOCK_12611,pResults->Winsock.dwMaxUDP);
  147. }
  148. }
  149. void WinsockPerInterfacePrint(IN NETDIAG_PARAMS *pParams,
  150. IN OUT NETDIAG_RESULT *pResults,
  151. IN INTERFACE_RESULT *pIfResult)
  152. {
  153. // no perinterface information
  154. }
  155. void WinsockCleanup(IN NETDIAG_PARAMS *pParams,
  156. IN OUT NETDIAG_RESULT *pResults)
  157. {
  158. if(pResults->Winsock.pProtInfo)
  159. {
  160. free(pResults->Winsock.pProtInfo);
  161. }
  162. ZeroMemory(&(pResults->Winsock), sizeof(GLOBAL_WINSOCK));
  163. }