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.

116 lines
3.2 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <winsock2.h>
  6. #include <wsipx.h>
  7. #include <svcguid.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <rpc.h>
  11. #include <rpcdce.h>
  12. #define BUFFSIZE 3000
  13. _cdecl
  14. main(int argc, char **argv)
  15. {
  16. HANDLE hLib;
  17. WCHAR Buffer[BUFFSIZE];
  18. PWSAQUERYSETA Query = (PWSAQUERYSETA)Buffer;
  19. HANDLE hRnr;
  20. DWORD dwIp;
  21. DWORD dwQuerySize = BUFFSIZE;
  22. WSADATA wsaData;
  23. ANSI_STRING asServiceInstanceName;
  24. UNICODE_STRING usServiceInstanceName;
  25. WCHAR UnicodeStringBuf[1024];
  26. AFPROTOCOLS lpAfpProtocols[3];
  27. GUID ServiceGuid = SVCID_INET_HOSTADDRBYNAME;
  28. DWORD uLoop;
  29. usServiceInstanceName.Length = 0;
  30. usServiceInstanceName.MaximumLength = 1024;
  31. usServiceInstanceName.Buffer = UnicodeStringBuf;
  32. if ( argc != 2 )
  33. {
  34. printf( "\nUsage: lookup <Name>\n" );
  35. return( -1 );
  36. }
  37. RtlInitAnsiString( &asServiceInstanceName, argv[1] );
  38. RtlAnsiStringToUnicodeString( &usServiceInstanceName,
  39. &asServiceInstanceName,
  40. FALSE );
  41. WSAStartup(MAKEWORD(2, 0), &wsaData);
  42. memset(Query, 0, sizeof(*Query));
  43. if ( usServiceInstanceName.Buffer[0] != L'*' )
  44. {
  45. Query->lpszServiceInstanceName = argv[1];
  46. }
  47. Query->dwSize = sizeof(*Query);
  48. Query->dwNameSpace = NS_DNS;
  49. Query->lpServiceClassId = &ServiceGuid;
  50. if( WSALookupServiceBeginA( Query,
  51. LUP_RETURN_ALL,
  52. &hRnr ) == SOCKET_ERROR )
  53. {
  54. printf( "LookupBegin failed %d\n", GetLastError() );
  55. }
  56. while ( WSALookupServiceNextA( hRnr,
  57. 0,
  58. &dwQuerySize,
  59. Query ) == NO_ERROR )
  60. {
  61. printf( "Next got: \n" );
  62. printf( " dwSize = %d\n",
  63. Query->dwSize );
  64. printf( " dwOutputFlags = %d\n",
  65. Query->dwOutputFlags );
  66. printf( " lpszServiceInstanceName = %ws\n",
  67. Query->lpszServiceInstanceName );
  68. if ( Query->lpVersion )
  69. {
  70. printf( " lpVersion->dwVersion = %d\n",
  71. Query->lpVersion->dwVersion );
  72. printf( " lpVersion->ecHow = %d\n",
  73. Query->lpVersion->ecHow );
  74. }
  75. if ( Query->lpszComment )
  76. {
  77. printf( " lpszComment = %ws\n",
  78. Query->lpszComment );
  79. }
  80. printf( " dwNameSpace = %d\n",
  81. Query->dwNameSpace );
  82. if ( Query->lpszContext )
  83. {
  84. printf( " lpszContext = %ws\n",
  85. Query->lpszContext );
  86. }
  87. printf( " dwNumberOfCsAddrs = %d\n",
  88. Query->dwNumberOfCsAddrs );
  89. }
  90. printf( "Next finished with %d\n", GetLastError() );
  91. if( WSALookupServiceEnd( hRnr ) )
  92. {
  93. printf( "ServiceEnd failed %d\n", GetLastError() );
  94. }
  95. WSACleanup();
  96. return(0);
  97. }