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.

117 lines
2.7 KiB

  1. #include "stdafx.h"
  2. #include "common.h"
  3. #include "util.h"
  4. #include "iisdebug.h"
  5. #include <winsock.h>
  6. #include <lm.h>
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char BASED_CODE THIS_FILE[] = __FILE__;
  10. #endif
  11. #define new DEBUG_NEW
  12. BOOL DoesUNCShareExist(CString& strServerShare)
  13. {
  14. // try to connect to the unc path.
  15. CString server, share;
  16. int idx = strServerShare.ReverseFind(_T('\\'));
  17. server = strServerShare.Left(idx);
  18. share = strServerShare.Mid(++idx);
  19. LPBYTE pbuf = NULL;
  20. NET_API_STATUS rc = NetShareGetInfo((LPTSTR)(LPCTSTR)server, (LPTSTR)(LPCTSTR)share, 0, &pbuf);
  21. if (NERR_Success == rc)
  22. {
  23. NetApiBufferFree(pbuf);
  24. return TRUE;
  25. }
  26. return FALSE;
  27. }
  28. BOOL // WinSE 25807
  29. LooksLikeIPAddress(
  30. IN LPCTSTR lpszServer)
  31. {
  32. BOOL bSomeDigits = FALSE;
  33. // Skip leading blanks
  34. while(*lpszServer == ' ')
  35. {
  36. lpszServer ++;
  37. }
  38. // Check all characters until first blank
  39. while(*lpszServer && *lpszServer != ' ')
  40. {
  41. if(*lpszServer != '.')
  42. {
  43. // If it's non-digit and not a dot, it's not IP address
  44. if (!_istdigit(*lpszServer))
  45. {
  46. return FALSE; // not digit, not dot --> not IP addr
  47. }
  48. bSomeDigits = TRUE;
  49. }
  50. lpszServer ++;
  51. }
  52. // Skip remaining blanks
  53. while(*lpszServer == ' ')
  54. {
  55. lpszServer ++;
  56. }
  57. // Looks like IP if we're at NULL & saw some digits
  58. return (*lpszServer == 0) && bSomeDigits;
  59. }
  60. //Use WinSock to the host name based on the ip address
  61. DWORD
  62. MyGetHostName
  63. (
  64. DWORD dwIpAddr,
  65. CString & strHostName
  66. )
  67. {
  68. CString strName;
  69. //
  70. // Call the Winsock API to get host name information.
  71. //
  72. strHostName.Empty();
  73. ULONG ulAddrInNetOrder = ::htonl( (ULONG) dwIpAddr ) ;
  74. HOSTENT * pHostInfo = ::gethostbyaddr( (CHAR *) & ulAddrInNetOrder,
  75. sizeof ulAddrInNetOrder,
  76. PF_INET ) ;
  77. if ( pHostInfo == NULL )
  78. {
  79. return ::WSAGetLastError();
  80. }
  81. // copy the name
  82. LPTSTR pBuf = strName.GetBuffer(256);
  83. ZeroMemory(pBuf, 256);
  84. ::MultiByteToWideChar(CP_ACP,
  85. MB_PRECOMPOSED,
  86. pHostInfo->h_name,
  87. -1,
  88. pBuf,
  89. 256);
  90. strName.ReleaseBuffer();
  91. strName.MakeUpper();
  92. int nDot = strName.Find(_T("."));
  93. if (nDot != -1)
  94. strHostName = strName.Left(nDot);
  95. else
  96. strHostName = strName;
  97. return NOERROR;
  98. }